@dxos/eslint-plugin-rules 0.8.4-main.1068cf700f → 0.8.4-main.2244d791bb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -0
- package/package.json +1 -1
- package/rules/no-bare-dot-imports.js +55 -0
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import comment from './rules/comment.js';
|
|
6
6
|
import effectSubpathImports from './rules/effect-subpath-imports.js';
|
|
7
7
|
import header from './rules/header.js';
|
|
8
|
+
import noBareDotImports from './rules/no-bare-dot-imports.js';
|
|
8
9
|
import noEffectRunPromise from './rules/no-effect-run-promise.js';
|
|
9
10
|
import noEmptyPromiseCatch from './rules/no-empty-promise-catch.js';
|
|
10
11
|
import fs from 'node:fs';
|
|
@@ -21,6 +22,7 @@ const plugin = {
|
|
|
21
22
|
comment,
|
|
22
23
|
'effect-subpath-imports': effectSubpathImports,
|
|
23
24
|
header,
|
|
25
|
+
'no-bare-dot-imports': noBareDotImports,
|
|
24
26
|
'no-effect-run-promise': noEffectRunPromise,
|
|
25
27
|
'no-empty-promise-catch': noEmptyPromiseCatch,
|
|
26
28
|
},
|
|
@@ -32,6 +34,7 @@ const plugin = {
|
|
|
32
34
|
rules: {
|
|
33
35
|
'dxos-plugin/effect-subpath-imports': 'error',
|
|
34
36
|
'dxos-plugin/header': 'error',
|
|
37
|
+
'dxos-plugin/no-bare-dot-imports': 'error',
|
|
35
38
|
'dxos-plugin/no-effect-run-promise': 'error',
|
|
36
39
|
'dxos-plugin/no-empty-promise-catch': 'error',
|
|
37
40
|
// TODO(dmaretskyi): Turned off due to large number of errors and no auto-fix.
|
package/package.json
CHANGED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2026 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ESLint rule to prevent bare "." or ".." imports.
|
|
7
|
+
* These imports are ambiguous as they don't explicitly show which file is being imported.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* // ❌ Bad
|
|
11
|
+
* import { foo } from '.';
|
|
12
|
+
* import { bar } from '..';
|
|
13
|
+
*
|
|
14
|
+
* // ✅ Good
|
|
15
|
+
* import { foo } from './index';
|
|
16
|
+
* import { bar } from '../index';
|
|
17
|
+
*/
|
|
18
|
+
export default {
|
|
19
|
+
meta: {
|
|
20
|
+
type: 'problem',
|
|
21
|
+
docs: {
|
|
22
|
+
description: 'disallow bare "." or ".." in import paths',
|
|
23
|
+
category: 'Best Practices',
|
|
24
|
+
recommended: true,
|
|
25
|
+
},
|
|
26
|
+
fixable: 'code',
|
|
27
|
+
schema: [],
|
|
28
|
+
messages: {
|
|
29
|
+
bareDotImport: 'Use explicit path instead of bare "{{source}}". Consider "{{suggestion}}" instead.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
create: (context) => {
|
|
33
|
+
return {
|
|
34
|
+
ImportDeclaration: (node) => {
|
|
35
|
+
const source = node.source.value;
|
|
36
|
+
|
|
37
|
+
// Check if the import is exactly "." or ".."
|
|
38
|
+
if (source === '.' || source === '..') {
|
|
39
|
+
context.report({
|
|
40
|
+
node: node.source,
|
|
41
|
+
messageId: 'bareDotImport',
|
|
42
|
+
data: {
|
|
43
|
+
source,
|
|
44
|
+
suggestion: source === '.' ? './index' : '../index',
|
|
45
|
+
},
|
|
46
|
+
fix: (fixer) => {
|
|
47
|
+
const newSource = source === '.' ? './index' : '../index';
|
|
48
|
+
return fixer.replaceText(node.source, `'${newSource}'`);
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
};
|