@futdevpro/dynamo-eslint 1.12.1 → 1.14.2

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.
Files changed (106) hide show
  1. package/.github/workflows/main.yml +1 -2
  2. package/README.md +34 -0
  3. package/build/configs/base.d.ts +7 -3
  4. package/build/configs/base.d.ts.map +1 -1
  5. package/build/configs/base.js +9 -4
  6. package/build/configs/base.js.map +1 -1
  7. package/build/configs/fsm.d.ts +13 -9
  8. package/build/configs/fsm.d.ts.map +1 -1
  9. package/build/configs/fsm.js +6 -2
  10. package/build/configs/fsm.js.map +1 -1
  11. package/build/configs/ngx-package.d.ts +8 -3
  12. package/build/configs/ngx-package.d.ts.map +1 -1
  13. package/build/configs/ngx-package.js +4 -0
  14. package/build/configs/ngx-package.js.map +1 -1
  15. package/build/configs/ngx.d.ts +8 -3
  16. package/build/configs/ngx.d.ts.map +1 -1
  17. package/build/configs/ngx.js +4 -0
  18. package/build/configs/ngx.js.map +1 -1
  19. package/build/configs/nts-package.d.ts +8 -3
  20. package/build/configs/nts-package.d.ts.map +1 -1
  21. package/build/configs/nts-package.js +4 -0
  22. package/build/configs/nts-package.js.map +1 -1
  23. package/build/configs/nts.d.ts +8 -3
  24. package/build/configs/nts.d.ts.map +1 -1
  25. package/build/configs/nts.js +4 -0
  26. package/build/configs/nts.js.map +1 -1
  27. package/build/plugin/index.d.ts +4 -0
  28. package/build/plugin/index.d.ts.map +1 -1
  29. package/build/plugin/index.js +7 -1
  30. package/build/plugin/index.js.map +1 -1
  31. package/build/plugin/rules/import/import-order.d.ts +4 -0
  32. package/build/plugin/rules/import/import-order.d.ts.map +1 -0
  33. package/build/plugin/rules/{import-order.js → import/import-order.js} +16 -17
  34. package/build/plugin/rules/import/import-order.js.map +1 -0
  35. package/build/plugin/rules/import/import-order.spec.d.ts.map +1 -0
  36. package/build/plugin/rules/{import-order.spec.js → import/import-order.spec.js} +40 -40
  37. package/build/plugin/rules/import/import-order.spec.js.map +1 -0
  38. package/build/plugin/rules/import/no-import-type.d.ts +4 -0
  39. package/build/plugin/rules/import/no-import-type.d.ts.map +1 -0
  40. package/build/plugin/rules/import/no-import-type.js +35 -0
  41. package/build/plugin/rules/import/no-import-type.js.map +1 -0
  42. package/build/plugin/rules/import/no-import-type.spec.d.ts +2 -0
  43. package/build/plugin/rules/import/no-import-type.spec.d.ts.map +1 -0
  44. package/build/plugin/rules/import/no-import-type.spec.js +60 -0
  45. package/build/plugin/rules/import/no-import-type.spec.js.map +1 -0
  46. package/build/plugin/rules/import/no-js-import.d.ts +4 -0
  47. package/build/plugin/rules/import/no-js-import.d.ts.map +1 -0
  48. package/build/plugin/rules/import/no-js-import.js +33 -0
  49. package/build/plugin/rules/import/no-js-import.js.map +1 -0
  50. package/build/plugin/rules/import/no-js-import.spec.d.ts +2 -0
  51. package/build/plugin/rules/import/no-js-import.spec.d.ts.map +1 -0
  52. package/build/plugin/rules/import/no-js-import.spec.js +68 -0
  53. package/build/plugin/rules/import/no-js-import.spec.js.map +1 -0
  54. package/build/plugin/rules/naming-patterns.d.ts +1 -1
  55. package/build/plugin/rules/naming-patterns.d.ts.map +1 -1
  56. package/build/plugin/rules/naming-patterns.spec.js +1 -1
  57. package/build/plugin/rules/naming-patterns.spec.js.map +1 -1
  58. package/build/scripts/dynamo-fix.d.ts +3 -0
  59. package/build/scripts/dynamo-fix.d.ts.map +1 -0
  60. package/build/scripts/dynamo-fix.js +92 -0
  61. package/build/scripts/dynamo-fix.js.map +1 -0
  62. package/build/scripts/eslintrc-audit.js.map +1 -1
  63. package/build/scripts/fix-return-types.d.ts +3 -0
  64. package/build/scripts/fix-return-types.d.ts.map +1 -0
  65. package/build/scripts/fix-return-types.js +109 -0
  66. package/build/scripts/fix-return-types.js.map +1 -0
  67. package/build/scripts/validate-imports.js +10 -9
  68. package/build/scripts/validate-imports.js.map +1 -1
  69. package/build/scripts/validate-naming.js +11 -26
  70. package/build/scripts/validate-naming.js.map +1 -1
  71. package/build-test/plugin/rules/import-order.d.ts +1 -1
  72. package/build-test/plugin/rules/naming-patterns.d.ts +1 -1
  73. package/eslint.config.js +55 -0
  74. package/futdevpro-dynamo-eslint-01.14.2.tgz +0 -0
  75. package/package.json +27 -18
  76. package/samples/poc-violations.ts +32 -3
  77. package/src/configs/base.ts +14 -4
  78. package/src/configs/fsm.ts +6 -2
  79. package/src/configs/ngx-package.ts +4 -0
  80. package/src/configs/ngx.ts +4 -0
  81. package/src/configs/nts-package.ts +4 -0
  82. package/src/configs/nts.ts +5 -1
  83. package/src/plugin/index.ts +9 -1
  84. package/src/plugin/rules/{import-order.spec.ts → import/import-order.spec.ts} +46 -40
  85. package/src/plugin/rules/{import-order.ts → import/import-order.ts} +20 -18
  86. package/src/plugin/rules/import/no-import-type.spec.ts +69 -0
  87. package/src/plugin/rules/import/no-import-type.ts +37 -0
  88. package/src/plugin/rules/import/no-js-import.spec.ts +82 -0
  89. package/src/plugin/rules/import/no-js-import.ts +35 -0
  90. package/src/plugin/rules/naming-patterns.spec.ts +3 -1
  91. package/src/plugin/rules/naming-patterns.ts +1 -1
  92. package/src/scripts/dynamo-fix.ts +108 -0
  93. package/src/scripts/eslintrc-audit.ts +6 -2
  94. package/src/scripts/fix-return-types.ts +146 -0
  95. package/src/scripts/validate-imports.ts +95 -13
  96. package/src/scripts/validate-naming.ts +16 -28
  97. package/.eslintrc.json +0 -16
  98. package/INTEGRATION.md +0 -74
  99. package/POC-README.md +0 -147
  100. package/build/plugin/rules/import-order.d.ts +0 -4
  101. package/build/plugin/rules/import-order.d.ts.map +0 -1
  102. package/build/plugin/rules/import-order.js.map +0 -1
  103. package/build/plugin/rules/import-order.spec.d.ts.map +0 -1
  104. package/build/plugin/rules/import-order.spec.js.map +0 -1
  105. package/futdevpro-dynamo-eslint-01.12.01.tgz +0 -0
  106. /package/build/plugin/rules/{import-order.spec.d.ts → import/import-order.spec.d.ts} +0 -0
@@ -11,24 +11,25 @@ describe('| import-order', () => {
11
11
  const mockContext = {
12
12
  getSourceCode: () => ({
13
13
  ast: {},
14
- getLines: () => ['line1', 'line2', 'line3']
14
+ getLines: () => [ 'line1', 'line2', 'line3' ],
15
15
  }),
16
16
  getFilename: () => 'test.ts',
17
17
  report: () => {},
18
18
  } as any;
19
19
 
20
20
  const result = importOrderRule.create(mockContext);
21
+
21
22
  expect(typeof result).toBe('object');
22
23
  expect(typeof result.Program).toBe('function');
23
24
  });
24
25
 
25
26
  it('| should detect forbidden NPM-packages imports', () => {
26
27
  const mockContext = {
27
- getSourceCode: () => ({
28
+ sourceCode: {
28
29
  ast: {},
29
- getLines: () => ['import { Something } from \'../../../NPM-packages/some-package\';']
30
- }),
31
- getFilename: () => 'test.ts',
30
+ getLines: () => [ 'import { Something } from \'../../../NPM-packages/some-package\';' ],
31
+ },
32
+ filename: 'test.ts',
32
33
  report: (options: any) => {
33
34
  expect(options.messageId).toBe('forbiddenNpmPackages');
34
35
  },
@@ -42,22 +43,23 @@ describe('| import-order', () => {
42
43
  type: 'ImportDeclaration',
43
44
  source: { value: '../../../NPM-packages/some-package' },
44
45
  importKind: 'value',
45
- loc: { start: { line: 1 }, end: { line: 1 } }
46
- }
47
- ]
46
+ loc: { start: { line: 1 }, end: { line: 1 } },
47
+ },
48
+ ],
48
49
  } as any;
49
50
 
50
51
  const rule = importOrderRule.create(mockContext);
52
+
51
53
  rule.Program(mockNode);
52
54
  });
53
55
 
54
56
  it('| should detect forbidden .js extension imports', () => {
55
57
  const mockContext = {
56
- getSourceCode: () => ({
58
+ sourceCode: {
57
59
  ast: {},
58
- getLines: () => ['import { Something } from \'./some-file.js\';']
59
- }),
60
- getFilename: () => 'test.ts',
60
+ getLines: () => [ 'import { Something } from \'./some-file.js\';' ],
61
+ },
62
+ filename: 'test.ts',
61
63
  report: (options: any) => {
62
64
  expect(options.messageId).toBe('forbiddenJsExtension');
63
65
  },
@@ -71,22 +73,23 @@ describe('| import-order', () => {
71
73
  type: 'ImportDeclaration',
72
74
  source: { value: './some-file.js' },
73
75
  importKind: 'value',
74
- loc: { start: { line: 1 }, end: { line: 1 } }
75
- }
76
- ]
76
+ loc: { start: { line: 1 }, end: { line: 1 } },
77
+ },
78
+ ],
77
79
  } as any;
78
80
 
79
81
  const rule = importOrderRule.create(mockContext);
82
+
80
83
  rule.Program(mockNode);
81
84
  });
82
85
 
83
86
  it('| should detect forbidden import type usage', () => {
84
87
  const mockContext = {
85
- getSourceCode: () => ({
88
+ sourceCode: {
86
89
  ast: {},
87
- getLines: () => ['import type { SomeType } from \'./some-file\';']
88
- }),
89
- getFilename: () => 'test.ts',
90
+ getLines: () => [ 'import type { SomeType } from \'./some-file\';' ],
91
+ },
92
+ filename: 'test.ts',
90
93
  report: (options: any) => {
91
94
  expect(options.messageId).toBe('forbiddenImportType');
92
95
  },
@@ -100,26 +103,27 @@ describe('| import-order', () => {
100
103
  type: 'ImportDeclaration',
101
104
  source: { value: './some-file' },
102
105
  importKind: 'type',
103
- loc: { start: { line: 1 }, end: { line: 1 } }
104
- }
105
- ]
106
+ loc: { start: { line: 1 }, end: { line: 1 } },
107
+ },
108
+ ],
106
109
  } as any;
107
110
 
108
111
  const rule = importOrderRule.create(mockContext);
112
+
109
113
  rule.Program(mockNode);
110
114
  });
111
115
 
112
116
  it('| should detect misordered imports', () => {
113
117
  let reportCount = 0;
114
118
  const mockContext = {
115
- getSourceCode: () => ({
119
+ sourceCode: {
116
120
  ast: {},
117
121
  getLines: () => [
118
122
  'import { DyFM_Error } from \'@futdevpro/fsm-dynamo\';',
119
- 'import { Component } from \'@angular/core\';'
120
- ]
121
- }),
122
- getFilename: () => 'test.ts',
123
+ 'import { Component } from \'@angular/core\';',
124
+ ],
125
+ },
126
+ filename: 'test.ts',
123
127
  report: (options: any) => {
124
128
  if (options.messageId === 'misordered') {
125
129
  reportCount++;
@@ -135,18 +139,19 @@ describe('| import-order', () => {
135
139
  type: 'ImportDeclaration',
136
140
  source: { value: '@futdevpro/fsm-dynamo' },
137
141
  importKind: 'value',
138
- loc: { start: { line: 1 }, end: { line: 1 } }
142
+ loc: { start: { line: 1 }, end: { line: 1 } },
139
143
  },
140
144
  {
141
145
  type: 'ImportDeclaration',
142
146
  source: { value: '@angular/core' },
143
147
  importKind: 'value',
144
- loc: { start: { line: 2 }, end: { line: 2 } }
145
- }
146
- ]
148
+ loc: { start: { line: 2 }, end: { line: 2 } },
149
+ },
150
+ ],
147
151
  } as any;
148
152
 
149
153
  const rule = importOrderRule.create(mockContext);
154
+
150
155
  rule.Program(mockNode);
151
156
 
152
157
  expect(reportCount).toBeGreaterThan(0);
@@ -155,14 +160,14 @@ describe('| import-order', () => {
155
160
  it('| should detect missing empty line between groups', () => {
156
161
  let reportCount = 0;
157
162
  const mockContext = {
158
- getSourceCode: () => ({
163
+ sourceCode: {
159
164
  ast: {},
160
165
  getLines: () => [
161
166
  'import { Component } from \'@angular/core\';',
162
- 'import { DyFM_Error } from \'@futdevpro/fsm-dynamo\';'
163
- ]
164
- }),
165
- getFilename: () => 'test.ts',
167
+ 'import { DyFM_Error } from \'@futdevpro/fsm-dynamo\';',
168
+ ],
169
+ },
170
+ filename: 'test.ts',
166
171
  report: (options: any) => {
167
172
  if (options.messageId === 'missingEmptyLine') {
168
173
  reportCount++;
@@ -178,18 +183,19 @@ describe('| import-order', () => {
178
183
  type: 'ImportDeclaration',
179
184
  source: { value: '@angular/core' },
180
185
  importKind: 'value',
181
- loc: { start: { line: 1 }, end: { line: 1 } }
186
+ loc: { start: { line: 1 }, end: { line: 1 } },
182
187
  },
183
188
  {
184
189
  type: 'ImportDeclaration',
185
190
  source: { value: '@futdevpro/fsm-dynamo' },
186
191
  importKind: 'value',
187
- loc: { start: { line: 2 }, end: { line: 2 } }
188
- }
189
- ]
192
+ loc: { start: { line: 2 }, end: { line: 2 } },
193
+ },
194
+ ],
190
195
  } as any;
191
196
 
192
197
  const rule = importOrderRule.create(mockContext);
198
+
193
199
  rule.Program(mockNode);
194
200
 
195
201
  expect(reportCount).toBeGreaterThan(0);
@@ -1,4 +1,4 @@
1
- import type { Rule } from 'eslint';
1
+ import { Rule } from 'eslint';
2
2
 
3
3
  interface ImportGroup {
4
4
  type: 'non-futdevpro' | 'futdevpro' | 'other-modules' | 'same-module';
@@ -13,16 +13,14 @@ const rule: Rule.RuleModule = {
13
13
  messages: {
14
14
  misordered: 'Import statements should be grouped and ordered by convention.',
15
15
  forbiddenNpmPackages: 'Import from "*/../NPM-packages/*" is forbidden. Use "@futdevpro/*" instead.',
16
- forbiddenJsExtension: 'Import with ".js" extension is forbidden. Use ".ts" or no extension.',
17
- forbiddenImportType: 'Use of "import type" is forbidden.',
18
16
  missingEmptyLine: 'Missing empty line between import groups.',
19
17
  extraEmptyLine: 'Extra empty line detected.',
20
18
  },
21
19
  fixable: 'code',
22
20
  },
23
21
  create(context) {
24
- const sourceCode = context.getSourceCode();
25
- const filename = context.getFilename();
22
+ const sourceCode = context.sourceCode;
23
+ const filename = context.filename;
26
24
 
27
25
  function getImportGroup(importNode: any): ImportGroup['type'] {
28
26
  const source = importNode.source.value as string;
@@ -67,23 +65,16 @@ const rule: Rule.RuleModule = {
67
65
  context.report({
68
66
  node: importNode.source,
69
67
  messageId: 'forbiddenNpmPackages',
68
+ fix(fixer) {
69
+ // Replace NPM-packages path with @futdevpro equivalent
70
+ const newSource = source.replace(/.*\/NPM-packages\/([^\/]+)/, '@futdevpro/$1');
71
+
72
+ return fixer.replaceText(importNode.source, `'${newSource}'`);
73
+ },
70
74
  });
71
75
  }
72
76
 
73
- if (source.endsWith('.js')) {
74
- context.report({
75
- node: importNode.source,
76
- messageId: 'forbiddenJsExtension',
77
- });
78
- }
79
77
 
80
- // Check for import type usage
81
- if (importNode.importKind === 'type') {
82
- context.report({
83
- node: importNode,
84
- messageId: 'forbiddenImportType',
85
- });
86
- }
87
78
  }
88
79
 
89
80
  function validateImportOrdering(importNodes: any[]) {
@@ -100,6 +91,7 @@ const rule: Rule.RuleModule = {
100
91
  importNodes.forEach(importNode => {
101
92
  const groupType = getImportGroup(importNode);
102
93
  const group = groups.find(g => g.type === groupType);
94
+
103
95
  if (group) {
104
96
  group.imports.push(importNode);
105
97
  }
@@ -110,6 +102,7 @@ const rule: Rule.RuleModule = {
110
102
 
111
103
  // Check if imports are in correct order
112
104
  let currentGroupIndex = 0;
105
+
113
106
  for (let i = 0; i < importNodes.length; i++) {
114
107
  const importNode = importNodes[i];
115
108
  const expectedGroupType = getImportGroup(importNode);
@@ -120,6 +113,11 @@ const rule: Rule.RuleModule = {
120
113
  context.report({
121
114
  node: importNode,
122
115
  messageId: 'misordered',
116
+ fix(fixer) {
117
+ // This is complex to fix automatically, so we'll just report for now
118
+ // Future enhancement: reorder imports automatically
119
+ return null;
120
+ },
123
121
  });
124
122
  }
125
123
 
@@ -141,6 +139,10 @@ const rule: Rule.RuleModule = {
141
139
  context.report({
142
140
  node: firstImportOfNextGroup,
143
141
  messageId: 'missingEmptyLine',
142
+ fix(fixer) {
143
+ // Add empty line before the first import of next group
144
+ return fixer.insertTextBefore(firstImportOfNextGroup, '\n');
145
+ },
144
146
  });
145
147
  }
146
148
  }
@@ -0,0 +1,69 @@
1
+ import noImportTypeRule from './no-import-type';
2
+
3
+ describe('| no-import-type', () => {
4
+ it('| should be a valid ESLint rule', () => {
5
+ expect(noImportTypeRule.meta?.type).toBe('suggestion');
6
+ expect(noImportTypeRule.meta?.docs?.description).toContain('import type');
7
+ expect(noImportTypeRule.meta?.fixable).toBe('code');
8
+ });
9
+
10
+ it('| should have create function that returns object with ImportDeclaration method', () => {
11
+ const mockContext = {
12
+ sourceCode: {
13
+ getText: (node: any) => 'import type { SomeType } from \'./some-file\';',
14
+ },
15
+ report: () => {},
16
+ } as any;
17
+
18
+ const result = noImportTypeRule.create(mockContext);
19
+
20
+ expect(typeof result).toBe('object');
21
+ expect(typeof result.ImportDeclaration).toBe('function');
22
+ });
23
+
24
+ it('| should detect forbidden import type usage', () => {
25
+ const mockContext = {
26
+ sourceCode: {
27
+ getText: (node: any) => 'import type { SomeType } from \'./some-file\';',
28
+ },
29
+ report: (options: any) => {
30
+ expect(options.messageId).toBe('forbiddenImportType');
31
+ },
32
+ } as any;
33
+
34
+ const mockNode = {
35
+ type: 'ImportDeclaration',
36
+ importKind: 'type',
37
+ loc: { start: { line: 1 }, end: { line: 1 } },
38
+ } as any;
39
+
40
+ const rule = noImportTypeRule.create(mockContext);
41
+
42
+ rule.ImportDeclaration(mockNode);
43
+ });
44
+
45
+ it('| should not report errors for regular imports', () => {
46
+ const mockContext = {
47
+ sourceCode: {
48
+ getText: (node: any) => 'import { SomeType } from \'./some-file\';',
49
+ },
50
+ report: (options: any) => {
51
+ // Should not be called for regular imports
52
+ fail('Should not report errors for regular imports');
53
+ },
54
+ } as any;
55
+
56
+ const mockNode = {
57
+ type: 'ImportDeclaration',
58
+ importKind: 'value',
59
+ loc: { start: { line: 1 }, end: { line: 1 } },
60
+ } as any;
61
+
62
+ const rule = noImportTypeRule.create(mockContext);
63
+
64
+ rule.ImportDeclaration(mockNode);
65
+
66
+ // If we get here without the report function being called, the test passes
67
+ expect(true).toBe(true);
68
+ });
69
+ });
@@ -0,0 +1,37 @@
1
+ import { Rule } from 'eslint';
2
+
3
+ const rule: Rule.RuleModule = {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: { description: 'Forbid use of "import type" syntax' },
7
+ schema: [],
8
+ messages: {
9
+ forbiddenImportType: 'Use of "import type" is forbidden.',
10
+ },
11
+ fixable: 'code',
12
+ },
13
+ create(context) {
14
+ const sourceCode = context.sourceCode;
15
+
16
+ return {
17
+ ImportDeclaration(node: any) {
18
+ // Check for import type usage
19
+ if (node.importKind === 'type') {
20
+ context.report({
21
+ node,
22
+ messageId: 'forbiddenImportType',
23
+ fix(fixer) {
24
+ // Remove 'type' keyword
25
+ const importText = sourceCode.getText(node);
26
+ const newImportText = importText.replace(/import\s+type\s+/, 'import ');
27
+
28
+ return fixer.replaceText(node, newImportText);
29
+ },
30
+ });
31
+ }
32
+ },
33
+ };
34
+ },
35
+ };
36
+
37
+ export default rule;
@@ -0,0 +1,82 @@
1
+ import noJsExtensionRule from './no-js-import';
2
+
3
+ describe('| no-js-import', () => {
4
+ it('| should be a valid ESLint rule', () => {
5
+ expect(noJsExtensionRule.meta?.type).toBe('suggestion');
6
+ expect(noJsExtensionRule.meta?.docs?.description).toContain('.js');
7
+ expect(noJsExtensionRule.meta?.fixable).toBe('code');
8
+ });
9
+
10
+ it('| should have create function that returns object with ImportDeclaration method', () => {
11
+ const mockContext = {
12
+ report: () => {},
13
+ } as any;
14
+
15
+ const result = noJsExtensionRule.create(mockContext);
16
+
17
+ expect(typeof result).toBe('object');
18
+ expect(typeof result.ImportDeclaration).toBe('function');
19
+ });
20
+
21
+ it('| should detect forbidden .js extension imports', () => {
22
+ const mockContext = {
23
+ report: (options: any) => {
24
+ expect(options.messageId).toBe('forbiddenJsExtension');
25
+ },
26
+ } as any;
27
+
28
+ const mockNode = {
29
+ type: 'ImportDeclaration',
30
+ source: { value: './some-file.js' },
31
+ loc: { start: { line: 1 }, end: { line: 1 } },
32
+ } as any;
33
+
34
+ const rule = noJsExtensionRule.create(mockContext);
35
+
36
+ rule.ImportDeclaration(mockNode);
37
+ });
38
+
39
+ it('| should not report errors for imports without .js extension', () => {
40
+ const mockContext = {
41
+ report: (options: any) => {
42
+ // Should not be called for imports without .js extension
43
+ fail('Should not report errors for imports without .js extension');
44
+ },
45
+ } as any;
46
+
47
+ const mockNode = {
48
+ type: 'ImportDeclaration',
49
+ source: { value: './some-file' },
50
+ loc: { start: { line: 1 }, end: { line: 1 } },
51
+ } as any;
52
+
53
+ const rule = noJsExtensionRule.create(mockContext);
54
+
55
+ rule.ImportDeclaration(mockNode);
56
+
57
+ // If we get here without the report function being called, the test passes
58
+ expect(true).toBe(true);
59
+ });
60
+
61
+ it('| should not report errors for imports with .ts extension', () => {
62
+ const mockContext = {
63
+ report: (options: any) => {
64
+ // Should not be called for imports with .ts extension
65
+ fail('Should not report errors for imports with .ts extension');
66
+ },
67
+ } as any;
68
+
69
+ const mockNode = {
70
+ type: 'ImportDeclaration',
71
+ source: { value: './some-file.ts' },
72
+ loc: { start: { line: 1 }, end: { line: 1 } },
73
+ } as any;
74
+
75
+ const rule = noJsExtensionRule.create(mockContext);
76
+
77
+ rule.ImportDeclaration(mockNode);
78
+
79
+ // If we get here without the report function being called, the test passes
80
+ expect(true).toBe(true);
81
+ });
82
+ });
@@ -0,0 +1,35 @@
1
+ import { Rule } from 'eslint';
2
+
3
+ const rule: Rule.RuleModule = {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: { description: 'Forbid imports with ".js" extension' },
7
+ schema: [],
8
+ messages: {
9
+ forbiddenJsExtension: 'Import with ".js" extension is forbidden. Use ".ts" or no extension.',
10
+ },
11
+ fixable: 'code',
12
+ },
13
+ create(context) {
14
+ return {
15
+ ImportDeclaration(node: any) {
16
+ const source = node.source.value as string;
17
+
18
+ if (source.endsWith('.js')) {
19
+ context.report({
20
+ node: node.source,
21
+ messageId: 'forbiddenJsExtension',
22
+ fix(fixer) {
23
+ // Remove .js extension
24
+ const newSource = source.replace(/\.js$/, '');
25
+
26
+ return fixer.replaceText(node.source, `'${newSource}'`);
27
+ },
28
+ });
29
+ }
30
+ },
31
+ };
32
+ },
33
+ };
34
+
35
+ export default rule;
@@ -12,6 +12,7 @@ describe('| naming-patterns', () => {
12
12
  } as any;
13
13
 
14
14
  const result = namingPatternsRule.create(mockContext);
15
+
15
16
  expect(typeof result).toBe('object');
16
17
  expect(typeof result.Identifier).toBe('function');
17
18
  });
@@ -27,10 +28,11 @@ describe('| naming-patterns', () => {
27
28
  const mockNode = {
28
29
  type: 'Identifier' as const,
29
30
  name: 'validVariableName',
30
- loc: { start: { line: 1 }, end: { line: 1 } }
31
+ loc: { start: { line: 1 }, end: { line: 1 } },
31
32
  } as any;
32
33
 
33
34
  const rule = namingPatternsRule.create(mockContext);
35
+
34
36
  rule.Identifier(mockNode);
35
37
 
36
38
  // If we get here without the report function being called, the test passes
@@ -1,4 +1,4 @@
1
- import type { Rule } from 'eslint';
1
+ import { Rule } from 'eslint';
2
2
  // import * as dyfmUtils from '@futdevpro/fsm-dynamo';
3
3
 
4
4
  const rule: Rule.RuleModule = {
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env node
2
+ import fg from 'fast-glob';
3
+ import { ESLint } from 'eslint';
4
+ import { writeFileSync } from 'fs';
5
+
6
+ interface FixResult {
7
+ file: string;
8
+ fixed: boolean;
9
+ errors: number;
10
+ warnings: number;
11
+ fixes: number;
12
+ }
13
+
14
+ async function fixFile(filePath: string): Promise<FixResult> {
15
+ const eslint = new ESLint({
16
+ baseConfig: [
17
+ { ignores: [ 'build/**', 'dist/**', 'node_modules/**' ] },
18
+ {
19
+ files: [ '**/*.{ts,tsx}' ],
20
+ languageOptions: {
21
+ parser: require('@typescript-eslint/parser'),
22
+ parserOptions: { ecmaVersion: 2020, sourceType: 'module' },
23
+ },
24
+ plugins: {
25
+ '@futdevpro/dynamo': {
26
+ rules: {
27
+ 'import-order': require('../plugin/rules/import-order').default,
28
+ 'naming-patterns': require('../plugin/rules/naming-patterns').default,
29
+ },
30
+ },
31
+ },
32
+ rules: {
33
+ '@futdevpro/dynamo/import-order': 'error',
34
+ '@futdevpro/dynamo/naming-patterns': 'warn',
35
+ },
36
+ },
37
+ ],
38
+ fix: true, // Enable auto-fixing
39
+ });
40
+
41
+ const results = await eslint.lintFiles([ filePath ]);
42
+ const result = results[0];
43
+
44
+ if (result && result.output) {
45
+ // Write the fixed content back to the file
46
+ writeFileSync(filePath, result.output);
47
+ }
48
+
49
+ return {
50
+ file: filePath,
51
+ fixed: result && result.output !== undefined,
52
+ errors: result.messages.filter(msg => msg.severity === 2).length,
53
+ warnings: result.messages.filter(msg => msg.severity === 1).length,
54
+ fixes: result.fixableErrorCount + result.fixableWarningCount,
55
+ };
56
+ }
57
+
58
+ async function main() {
59
+ const files = await fg([ '**/*.{ts,tsx}' ], {
60
+ ignore: [ '**/node_modules/**', '**/build/**', '**/dist/**', '**/*.spec.ts', '**/*.test.ts' ],
61
+ });
62
+
63
+ console.log(`[dynamo-fix] Fixing ${files.length} files...`);
64
+
65
+ const results: FixResult[] = [];
66
+ let totalFixed = 0;
67
+ let totalErrors = 0;
68
+ let totalWarnings = 0;
69
+ let totalFixes = 0;
70
+
71
+ for (const file of files) {
72
+ try {
73
+ const result = await fixFile(file);
74
+
75
+ results.push(result);
76
+
77
+ if (result.fixed) {
78
+ totalFixed++;
79
+ console.log(`✅ Fixed: ${result.file}`);
80
+ }
81
+
82
+ totalErrors += result.errors;
83
+ totalWarnings += result.warnings;
84
+ totalFixes += result.fixes;
85
+ } catch (error) {
86
+ console.error(`❌ Error processing ${file}:`, error);
87
+ }
88
+ }
89
+
90
+ // Report results
91
+ console.log(`\n📊 Fix Summary:`);
92
+ console.log(` Files processed: ${files.length}`);
93
+ console.log(` Files fixed: ${totalFixed}`);
94
+ console.log(` Total errors: ${totalErrors}`);
95
+ console.log(` Total warnings: ${totalWarnings}`);
96
+ console.log(` Total fixes applied: ${totalFixes}`);
97
+
98
+ if (totalFixed === 0) {
99
+ console.log('✅ No files needed fixing!');
100
+ } else {
101
+ console.log(`\n🎉 Successfully fixed ${totalFixed} files!`);
102
+ }
103
+ }
104
+
105
+ main().catch((err) => {
106
+ console.error('Fix failed:', err);
107
+ process.exit(1);
108
+ });
@@ -7,6 +7,7 @@ type AnyJson = any;
7
7
  function safeParse(jsonPath: string): AnyJson | null {
8
8
  try {
9
9
  const content = readFileSync(jsonPath, 'utf8');
10
+
10
11
  return JSON.parse(content);
11
12
  } catch {
12
13
  return null;
@@ -14,21 +15,24 @@ function safeParse(jsonPath: string): AnyJson | null {
14
15
  }
15
16
 
16
17
  async function main() {
17
- const files = await fg(['**/.eslintrc.json'], { ignore: ['**/node_modules/**'] });
18
+ const files = await fg([ '**/.eslintrc.json' ], { ignore: [ '**/node_modules/**' ] });
18
19
  const ruleCounts: Record<string, number> = {};
19
20
  const total = files.length;
20
21
 
21
22
  for (const p of files) {
22
23
  const cfg = safeParse(p);
24
+
23
25
  if (!cfg?.rules) continue;
26
+
24
27
  for (const key of Object.keys(cfg.rules)) {
25
28
  ruleCounts[key] = (ruleCounts[key] ?? 0) + 1;
26
29
  }
27
30
  }
28
31
 
29
32
  const entries = Object.entries(ruleCounts).sort((a, b) => b[1] - a[1]);
33
+
30
34
  console.log(`[dynamo-eslintrc-audit] analyzed ${total} files`);
31
- console.table(entries.slice(0, 50).map(([rule, count]) => ({ rule, count })));
35
+ console.table(entries.slice(0, 50).map(([ rule, count ]) => ({ rule, count })));
32
36
  }
33
37
 
34
38
  main().catch((err) => {