@dxos/eslint-plugin-rules 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced

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.
@@ -0,0 +1,317 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { createRequire } from 'node:module';
6
+
7
+ const EXCLUDED_EFFECT_PACKAGES = ['@effect/vitest'];
8
+
9
+ /**
10
+ * Map of Effect base-package exports that come from a subpath (not a direct segment).
11
+ * Used when resolving imports like `import { pipe } from 'effect'` → effect/Function.
12
+ */
13
+ const EFFECT_EXPORT_TO_SUBPATH = {
14
+ pipe: 'Function',
15
+ flow: 'Function',
16
+ };
17
+
18
+ /**
19
+ * Subpaths that allow named imports (e.g. `import { pipe, flow } from 'effect/Function'`).
20
+ * Other subpaths still require namespace imports.
21
+ */
22
+ const NAMED_IMPORT_ALLOWED_SUBPATHS = new Set(['Function']);
23
+
24
+ /**
25
+ * ESLint rule to transform combined imports from 'effect' and '@effect/*'
26
+ * into subpath imports except for the EXCLUDED_EFFECT_PACKAGES.
27
+ * @example
28
+ * // before
29
+ * import { type Schema, SchemaAST } from 'effect';
30
+ *
31
+ * // after
32
+ * import type * as Schema from 'effect/Schema'
33
+ * import * as SchemaAST from 'effect/SchemaAST'
34
+ */
35
+ export default {
36
+ meta: {
37
+ type: 'suggestion',
38
+ docs: {
39
+ description: 'enforce subpath imports for Effect packages',
40
+ },
41
+ fixable: 'code',
42
+ schema: [],
43
+ },
44
+ create: (context) => {
45
+ // Resolver and caches are scoped to this lint run.
46
+ const requireForFile = createRequire(context.getFilename());
47
+ const exportsCache = new Map(); // packageName -> Set<segment>
48
+
49
+ const loadExportsForPackage = (pkgName) => {
50
+ if (exportsCache.has(pkgName)) {
51
+ return exportsCache.get(pkgName);
52
+ }
53
+ try {
54
+ const pkgJson = requireForFile(`${pkgName}/package.json`);
55
+ const ex = pkgJson && pkgJson.exports;
56
+ const segments = new Set();
57
+ if (ex && typeof ex === 'object') {
58
+ for (const key of Object.keys(ex)) {
59
+ // Keys like './Schema', './SchemaAST', './Function' (skip '.' and './package.json').
60
+ if (key === '.' || key === './package.json') {
61
+ continue;
62
+ }
63
+ if (key.startsWith('./')) {
64
+ segments.add(key.slice(2));
65
+ }
66
+ }
67
+ }
68
+ exportsCache.set(pkgName, segments);
69
+ return segments;
70
+ } catch {
71
+ const empty = new Set();
72
+ exportsCache.set(pkgName, empty);
73
+ return empty;
74
+ }
75
+ };
76
+
77
+ const isValidSubpath = (pkgName, segment) => {
78
+ const exported = loadExportsForPackage(pkgName);
79
+ return exported.has(segment);
80
+ };
81
+
82
+ const resolveExportToSegment = (pkgName, exportName) => {
83
+ if (isValidSubpath(pkgName, exportName)) {
84
+ return exportName;
85
+ }
86
+ if (pkgName === 'effect' && EFFECT_EXPORT_TO_SUBPATH[exportName]) {
87
+ const segment = EFFECT_EXPORT_TO_SUBPATH[exportName];
88
+ return isValidSubpath(pkgName, segment) ? segment : null;
89
+ }
90
+ return null;
91
+ };
92
+
93
+ const isEffectPackage = (source) => {
94
+ return source === 'effect' || source.startsWith('effect/') || source.startsWith('@effect/');
95
+ };
96
+
97
+ const shouldSkipEffectPackage = (basePackage) => {
98
+ return EXCLUDED_EFFECT_PACKAGES.includes(basePackage);
99
+ };
100
+
101
+ /**
102
+ * Get the base package name from a source string.
103
+ * @param {string} source - The source string to get the base package name from.
104
+ * @returns {string} The base package name.
105
+ * @example
106
+ * getBasePackage('effect/Schema') // 'effect'
107
+ * getBasePackage('@effect/ai/openai') // '@effect/ai'
108
+ */
109
+ const getBasePackage = (source) => {
110
+ if (source.startsWith('@')) {
111
+ const parts = source.split('/');
112
+ return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : source;
113
+ } else {
114
+ return source.split('/')[0];
115
+ }
116
+ };
117
+
118
+ return {
119
+ ImportDeclaration: (node) => {
120
+ const source = String(node.source.value);
121
+ if (!isEffectPackage(source)) {
122
+ return;
123
+ }
124
+ const basePackage = getBasePackage(source);
125
+ if (shouldSkipEffectPackage(basePackage)) {
126
+ return;
127
+ }
128
+
129
+ // If it's a subpath import (e.g., 'effect/Schema'), enforce namespace import except for allowed subpaths.
130
+ if (source.startsWith(basePackage + '/')) {
131
+ const segment = source.slice(basePackage.length + 1);
132
+ const allowsNamed = NAMED_IMPORT_ALLOWED_SUBPATHS.has(segment);
133
+ const isNamespaceOnly =
134
+ node.specifiers.length === 1 && node.specifiers[0].type === 'ImportNamespaceSpecifier';
135
+ if (!allowsNamed && !isNamespaceOnly) {
136
+ context.report({
137
+ node,
138
+ message: 'Use namespace import for Effect subpaths',
139
+ });
140
+ }
141
+ return;
142
+ }
143
+
144
+ // From here on, we only handle root package imports like 'effect'.
145
+ const packageName = basePackage;
146
+
147
+ // Only process imports with specifiers.
148
+ if (!node.specifiers || node.specifiers.length === 0) {
149
+ return;
150
+ }
151
+
152
+ // Only process named imports.
153
+ const hasNamedImports = node.specifiers.some((spec) => spec.type === 'ImportSpecifier');
154
+
155
+ if (!hasNamedImports) {
156
+ return;
157
+ }
158
+
159
+ // Group specifiers by type.
160
+ const typeImports = [];
161
+ const regularImports = [];
162
+ for (const specifier of node.specifiers) {
163
+ if (specifier.type !== 'ImportSpecifier') {
164
+ continue;
165
+ }
166
+ const entry = { imported: specifier.imported.name, local: specifier.local.name };
167
+ if (specifier.importKind === 'type') {
168
+ typeImports.push(entry);
169
+ } else {
170
+ regularImports.push(entry);
171
+ }
172
+ }
173
+
174
+ // Partition into resolvable vs unresolved specifiers (resolved entries include segment for fix).
175
+ const resolvedType = [];
176
+ const unresolvedType = [];
177
+ const resolvedRegular = [];
178
+ const unresolvedRegular = [];
179
+
180
+ typeImports.forEach((spec) => {
181
+ const segment = resolveExportToSegment(packageName, spec.imported);
182
+ if (segment) {
183
+ resolvedType.push({ ...spec, segment });
184
+ } else {
185
+ unresolvedType.push(spec);
186
+ }
187
+ });
188
+ regularImports.forEach((spec) => {
189
+ const segment = resolveExportToSegment(packageName, spec.imported);
190
+ if (segment) {
191
+ resolvedRegular.push({ ...spec, segment });
192
+ } else {
193
+ unresolvedRegular.push(spec);
194
+ }
195
+ });
196
+
197
+ const unresolved = [...unresolvedType, ...unresolvedRegular].map(({ imported }) => imported);
198
+
199
+ // Report and autofix: fix resolvable ones; keep unresolved in a remaining combined import.
200
+ context.report({
201
+ node,
202
+ message:
203
+ unresolved.length > 0
204
+ ? `Use subpath imports for Effect packages; unresolved kept in base import: ${unresolved.join(', ')}`
205
+ : 'Use subpath imports for Effect packages',
206
+ fix: (fixer) => {
207
+ const sourceCode = context.getSourceCode();
208
+ const imports = [];
209
+
210
+ // Idempotency guard: if nothing is resolvable, do not rewrite.
211
+ if (resolvedType.length === 0 && resolvedRegular.length === 0) {
212
+ return null;
213
+ }
214
+
215
+ // Group resolved imports by segment.
216
+ const bySegment = new Map(); // segment -> { regular: [...], type: [...] }
217
+ resolvedRegular.forEach((entry) => {
218
+ const seg = entry.segment;
219
+ let group = bySegment.get(seg);
220
+ if (!group) {
221
+ group = { regular: [], type: [] };
222
+ bySegment.set(seg, group);
223
+ }
224
+ group.regular.push(entry);
225
+ });
226
+ resolvedType.forEach((entry) => {
227
+ const seg = entry.segment;
228
+ let group = bySegment.get(seg);
229
+ if (!group) {
230
+ group = { regular: [], type: [] };
231
+ bySegment.set(seg, group);
232
+ }
233
+ group.type.push(entry);
234
+ });
235
+
236
+ for (const [segment, group] of bySegment) {
237
+ const useNamed = NAMED_IMPORT_ALLOWED_SUBPATHS.has(segment);
238
+ const merged = [...group.regular];
239
+ for (const t of group.type) {
240
+ if (!group.regular.some((r) => r.local === t.local)) {
241
+ merged.push(t);
242
+ }
243
+ }
244
+ if (useNamed && merged.length > 0) {
245
+ const specParts = merged.map(({ imported, local }) =>
246
+ imported !== local ? `${imported} as ${local}` : imported,
247
+ );
248
+ imports.push(`import { ${specParts.join(', ')} } from '${packageName}/${segment}';`);
249
+ } else {
250
+ const seen = new Set();
251
+ for (const { imported, local } of merged) {
252
+ const alias = imported !== local ? local : imported;
253
+ if (seen.has(alias)) {
254
+ continue;
255
+ }
256
+ seen.add(alias);
257
+ const isTypeOnly =
258
+ group.type.some((t) => t.imported === imported) &&
259
+ !group.regular.some((r) => r.imported === imported);
260
+ const importStr = isTypeOnly
261
+ ? `import type * as ${alias} from '${packageName}/${segment}';`
262
+ : `import * as ${alias} from '${packageName}/${segment}';`;
263
+ imports.push(importStr);
264
+ }
265
+ }
266
+ }
267
+
268
+ // If there are unresolved, keep them in a single base import.
269
+ if (unresolvedType.length || unresolvedRegular.length) {
270
+ // Prefer value over type for the same local alias when both are present.
271
+ const byLocal = new Map(); // local -> { value?: {imported,local}, type?: {imported,local} }
272
+ unresolvedRegular.forEach((s) => {
273
+ const entry = byLocal.get(s.local) ?? {};
274
+ entry.value = s;
275
+ byLocal.set(s.local, entry);
276
+ });
277
+ unresolvedType.forEach((s) => {
278
+ const entry = byLocal.get(s.local) ?? {};
279
+ if (!entry.value) {
280
+ entry.type = s;
281
+ } // only keep type if no value for same local
282
+ byLocal.set(s.local, entry);
283
+ });
284
+
285
+ const specParts = [];
286
+ for (const entry of byLocal.values()) {
287
+ if (entry.value) {
288
+ const { imported, local } = entry.value;
289
+ const part = imported !== local ? `${imported} as ${local}` : `${imported}`;
290
+ specParts.push(part);
291
+ } else if (entry.type) {
292
+ const { imported, local } = entry.type;
293
+ const part = imported !== local ? `type ${imported} as ${local}` : `type ${imported}`;
294
+ specParts.push(part);
295
+ }
296
+ }
297
+ if (specParts.length) {
298
+ imports.push(`import { ${specParts.join(', ')} } from '${packageName}';`);
299
+ }
300
+ }
301
+
302
+ // Get the original import's indentation.
303
+ const importIndent = sourceCode.text.slice(node.range[0] - node.loc.start.column, node.range[0]);
304
+
305
+ // Join imports with newline and proper indentation.
306
+ if (imports.length === 0) {
307
+ return null;
308
+ } // nothing to change
309
+ const newImports = imports.join('\n' + importIndent);
310
+
311
+ return fixer.replaceText(node, newImports);
312
+ },
313
+ });
314
+ },
315
+ };
316
+ },
317
+ };
package/rules/header.js CHANGED
@@ -5,7 +5,7 @@
5
5
  const REGEX = /Copyright [0-9]+ DXOS.org/;
6
6
  const TEMPLATE = ['//', `// Copyright ${new Date().getFullYear()} DXOS.org`, '//', ''].join('\n') + '\n';
7
7
 
8
- module.exports = {
8
+ export default {
9
9
  pattern: REGEX,
10
10
  meta: {
11
11
  type: 'layout',
@@ -19,7 +19,7 @@ module.exports = {
19
19
  create: (context) => {
20
20
  return {
21
21
  Program: (node) => {
22
- if (!context.getSource().match(REGEX)) {
22
+ if (!context.sourceCode.getText().match(REGEX)) {
23
23
  context.report({
24
24
  node,
25
25
  message: 'Missing copyright header',
@@ -0,0 +1,271 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+
8
+ const DIRECTIVE_TEXT = '@import-as-namespace';
9
+ const DIRECTIVE_LINE_REGEX = /^\s*\/\/\s*@import-as-namespace\s*$/m;
10
+ const PASCAL_CASE_REGEX = /^[A-Z][a-zA-Z0-9]*$/;
11
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx'];
12
+
13
+ /**
14
+ * ESLint rule to enforce namespace imports for modules annotated with `// @import-as-namespace`.
15
+ *
16
+ * When a module contains the `// @import-as-namespace` directive comment, this rule enforces:
17
+ * - The module filename is PascalCase (e.g. `LanguageModel.ts`).
18
+ * - All imports of the module use namespace form: `import * as LanguageModel from './LanguageModel'`.
19
+ * - The namespace name matches the filename (without extension), or has a `Module` suffix.
20
+ * - Re-exports use namespace form: `export * as LanguageModel from './LanguageModel'`.
21
+ *
22
+ * The `Module` suffix is allowed as an escape hatch when the expected namespace name conflicts
23
+ * with a local declaration in the importing file (e.g., `import * as ObjModule from './Obj'`
24
+ * when the file also exports its own `Obj` interface).
25
+ *
26
+ * @example
27
+ * // In LanguageModel.ts:
28
+ * // @import-as-namespace
29
+ * export const foo = 1;
30
+ *
31
+ * // ❌ Bad (in another file):
32
+ * import { foo } from './LanguageModel';
33
+ * export { foo } from './LanguageModel';
34
+ * export * from './LanguageModel';
35
+ *
36
+ * // ✅ Good:
37
+ * import * as LanguageModel from './LanguageModel';
38
+ * import * as LanguageModelModule from './LanguageModel'; // Also allowed when needed
39
+ * export * as LanguageModel from './LanguageModel';
40
+ */
41
+ export default {
42
+ meta: {
43
+ type: 'problem',
44
+ docs: {
45
+ description: 'enforce namespace imports for modules marked with @import-as-namespace',
46
+ },
47
+ fixable: 'code',
48
+ schema: [],
49
+ messages: {
50
+ filenameMustBePascalCase:
51
+ 'Module marked with @import-as-namespace must have a PascalCase filename. Got: "{{filename}}".',
52
+ mustUseNamespaceImport:
53
+ 'Module "{{source}}" is marked @import-as-namespace. Use: `import * as {{namespace}} from \'{{source}}\'`.',
54
+ namespaceMustMatchFilename: 'Namespace import name "{{actual}}" must match filename "{{expected}}".',
55
+ mustUseNamespaceReexport:
56
+ 'Module "{{source}}" is marked @import-as-namespace. Use: `export * as {{namespace}} from \'{{source}}\'`.',
57
+ },
58
+ },
59
+ create: (context) => {
60
+ const directiveCache = new Map();
61
+
62
+ const fileHasDirective = (filePath) => {
63
+ if (directiveCache.has(filePath)) {
64
+ return directiveCache.get(filePath);
65
+ }
66
+ try {
67
+ const content = fs.readFileSync(filePath, 'utf8');
68
+ const result = DIRECTIVE_LINE_REGEX.test(content);
69
+ directiveCache.set(filePath, result);
70
+ return result;
71
+ } catch {
72
+ directiveCache.set(filePath, false);
73
+ return false;
74
+ }
75
+ };
76
+
77
+ const resolveRelativeImport = (source, currentFile) => {
78
+ if (!source.startsWith('.')) {
79
+ return null;
80
+ }
81
+ const dir = path.dirname(currentFile);
82
+ const resolved = path.resolve(dir, source);
83
+ for (const ext of TS_EXTENSIONS) {
84
+ const filePath = resolved + ext;
85
+ if (fs.existsSync(filePath)) {
86
+ return filePath;
87
+ }
88
+ }
89
+ for (const ext of TS_EXTENSIONS) {
90
+ const filePath = path.join(resolved, 'index' + ext);
91
+ if (fs.existsSync(filePath)) {
92
+ return filePath;
93
+ }
94
+ }
95
+ return null;
96
+ };
97
+
98
+ const namespaceFromSource = (source) => {
99
+ const parts = source.split('/');
100
+ const last = parts[parts.length - 1];
101
+ return last.replace(/\.\w+$/, '');
102
+ };
103
+
104
+ const buildImportFix = (fixer, node, source, expectedNamespace, context) => {
105
+ const fixes = [];
106
+ const importKeyword = node.importKind === 'type' ? 'import type' : 'import';
107
+ fixes.push(fixer.replaceText(node, `${importKeyword} * as ${expectedNamespace} from '${source}';`));
108
+
109
+ try {
110
+ const declaredVars = context.sourceCode.getDeclaredVariables(node);
111
+ for (const variable of declaredVars) {
112
+ for (const ref of variable.references) {
113
+ if (ref.identifier.range[0] >= node.range[0] && ref.identifier.range[1] <= node.range[1]) {
114
+ continue;
115
+ }
116
+ fixes.push(fixer.replaceText(ref.identifier, `${expectedNamespace}.${variable.name}`));
117
+ }
118
+ }
119
+ } catch {
120
+ // Scope analysis unavailable; fix import declaration only.
121
+ }
122
+
123
+ return fixes;
124
+ };
125
+
126
+ return {
127
+ Program: (node) => {
128
+ const comments = context.sourceCode.getAllComments();
129
+ const hasDirective = comments.some(
130
+ (comment) => comment.type === 'Line' && comment.value.trim() === DIRECTIVE_TEXT,
131
+ );
132
+ if (!hasDirective) {
133
+ return;
134
+ }
135
+ const filename = path.basename(context.getFilename());
136
+ const stem = filename.replace(/\.\w+$/, '');
137
+ if (!PASCAL_CASE_REGEX.test(stem)) {
138
+ context.report({
139
+ node,
140
+ messageId: 'filenameMustBePascalCase',
141
+ data: { filename },
142
+ });
143
+ }
144
+ },
145
+
146
+ ImportDeclaration: (node) => {
147
+ const source = String(node.source.value);
148
+ if (!source.startsWith('.')) {
149
+ return;
150
+ }
151
+ if (!node.specifiers || node.specifiers.length === 0) {
152
+ return;
153
+ }
154
+
155
+ const currentFile = context.getFilename();
156
+ const resolved = resolveRelativeImport(source, currentFile);
157
+ if (!resolved) {
158
+ return;
159
+ }
160
+ if (!fileHasDirective(resolved)) {
161
+ return;
162
+ }
163
+
164
+ const expectedNamespace = namespaceFromSource(source);
165
+
166
+ const isNamespaceImport =
167
+ node.specifiers.length === 1 && node.specifiers[0].type === 'ImportNamespaceSpecifier';
168
+
169
+ if (!isNamespaceImport) {
170
+ context.report({
171
+ node,
172
+ messageId: 'mustUseNamespaceImport',
173
+ data: { source, namespace: expectedNamespace },
174
+ fix: (fixer) => buildImportFix(fixer, node, source, expectedNamespace, context),
175
+ });
176
+ return;
177
+ }
178
+
179
+ const actual = node.specifiers[0].local.name;
180
+ const allowedNames = [expectedNamespace, expectedNamespace + 'Module'];
181
+ if (!allowedNames.includes(actual)) {
182
+ context.report({
183
+ node,
184
+ messageId: 'namespaceMustMatchFilename',
185
+ data: { actual, expected: expectedNamespace },
186
+ fix: (fixer) => {
187
+ const importKeyword = node.importKind === 'type' ? 'import type' : 'import';
188
+ return fixer.replaceText(node, `${importKeyword} * as ${expectedNamespace} from '${source}';`);
189
+ },
190
+ });
191
+ }
192
+ },
193
+
194
+ ExportNamedDeclaration: (node) => {
195
+ if (!node.source) {
196
+ return;
197
+ }
198
+ const source = String(node.source.value);
199
+ if (!source.startsWith('.')) {
200
+ return;
201
+ }
202
+
203
+ const currentFile = context.getFilename();
204
+ const resolved = resolveRelativeImport(source, currentFile);
205
+ if (!resolved) {
206
+ return;
207
+ }
208
+ if (!fileHasDirective(resolved)) {
209
+ return;
210
+ }
211
+
212
+ const expectedNamespace = namespaceFromSource(source);
213
+ const exportKeyword = node.exportKind === 'type' ? 'export type' : 'export';
214
+ context.report({
215
+ node,
216
+ messageId: 'mustUseNamespaceReexport',
217
+ data: { source, namespace: expectedNamespace },
218
+ fix: (fixer) => {
219
+ return fixer.replaceText(node, `${exportKeyword} * as ${expectedNamespace} from '${source}';`);
220
+ },
221
+ });
222
+ },
223
+
224
+ ExportAllDeclaration: (node) => {
225
+ if (!node.source) {
226
+ return;
227
+ }
228
+ const source = String(node.source.value);
229
+ if (!source.startsWith('.')) {
230
+ return;
231
+ }
232
+
233
+ const currentFile = context.getFilename();
234
+ const resolved = resolveRelativeImport(source, currentFile);
235
+ if (!resolved) {
236
+ return;
237
+ }
238
+ if (!fileHasDirective(resolved)) {
239
+ return;
240
+ }
241
+
242
+ const expectedNamespace = namespaceFromSource(source);
243
+
244
+ if (node.exported) {
245
+ const actual = node.exported.name;
246
+ const allowedNames = [expectedNamespace, expectedNamespace + 'Module'];
247
+ if (!allowedNames.includes(actual)) {
248
+ context.report({
249
+ node,
250
+ messageId: 'namespaceMustMatchFilename',
251
+ data: { actual, expected: expectedNamespace },
252
+ fix: (fixer) => {
253
+ return fixer.replaceText(node, `export * as ${expectedNamespace} from '${source}';`);
254
+ },
255
+ });
256
+ }
257
+ return;
258
+ }
259
+
260
+ context.report({
261
+ node,
262
+ messageId: 'mustUseNamespaceReexport',
263
+ data: { source, namespace: expectedNamespace },
264
+ fix: (fixer) => {
265
+ return fixer.replaceText(node, `export * as ${expectedNamespace} from '${source}';`);
266
+ },
267
+ });
268
+ },
269
+ };
270
+ },
271
+ };
@@ -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
+ };