eslint-config-decent 1.4.0 → 1.4.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.
- package/dist/index.cjs +23 -15
- package/dist/index.d.cts +10 -9
- package/dist/index.d.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.mjs +23 -15
- package/package.json +10 -9
- package/src/eslint.ts +4 -4
- package/src/extension.ts +2 -2
- package/src/index.ts +1 -0
- package/src/jsdoc.ts +3 -2
- package/src/mocha.ts +2 -2
- package/src/promise.ts +2 -2
- package/src/react.ts +2 -2
- package/src/rules/requireExtensionRule.ts +20 -13
- package/src/rules/requireIndexRule.ts +20 -12
- package/src/security.ts +2 -2
- package/src/types/eslint-js.d.ts +3 -3
- package/src/types/eslint-plugin-jsx-a11y.d.ts +3 -3
- package/src/types/eslint-plugin-mocha.d.ts +3 -3
- package/src/types/eslint-plugin-promise.d.ts +2 -2
- package/src/types/eslint-plugin-react-hooks.d.ts +2 -2
- package/src/types/eslint-plugin-react.d.ts +3 -3
- package/src/types/eslint-plugin-security.d.ts +2 -2
- package/src/types/eslint-plugin-testing-library.d.ts +3 -3
- package/src/types/eslint-plugin-unicorn.d.ts +2 -2
- package/src/typescriptEslint.ts +2 -2
- package/src/unicorn.ts +2 -2
package/dist/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ const tsEslint = require('typescript-eslint');
|
|
|
6
6
|
const prettier = require('eslint-plugin-prettier/recommended');
|
|
7
7
|
const fs = require('fs');
|
|
8
8
|
const path = require('path');
|
|
9
|
+
const utils = require('@typescript-eslint/utils');
|
|
9
10
|
const jsdoc = require('eslint-plugin-jsdoc');
|
|
10
11
|
const mocha = require('eslint-plugin-mocha');
|
|
11
12
|
const promise = require('eslint-plugin-promise');
|
|
@@ -280,28 +281,31 @@ const configs$8 = {
|
|
|
280
281
|
cjs
|
|
281
282
|
};
|
|
282
283
|
|
|
283
|
-
const requireExtensionRule = {
|
|
284
|
+
const requireExtensionRule = utils.ESLintUtils.RuleCreator(() => "https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireExtensionRule.ts")({
|
|
285
|
+
name: "require-extension",
|
|
284
286
|
meta: {
|
|
285
287
|
type: "suggestion",
|
|
286
288
|
docs: {
|
|
287
|
-
description: "Ensure import and export statements include a file extension"
|
|
288
|
-
category: "Best Practices",
|
|
289
|
-
recommended: true
|
|
289
|
+
description: "Ensure import and export statements include a file extension"
|
|
290
290
|
},
|
|
291
291
|
fixable: "code",
|
|
292
|
-
schema: []
|
|
292
|
+
schema: [],
|
|
293
|
+
messages: {
|
|
294
|
+
requireExtension: "Relative imports and exports must include a file extension."
|
|
295
|
+
}
|
|
293
296
|
},
|
|
297
|
+
defaultOptions: [],
|
|
294
298
|
create(context) {
|
|
295
299
|
function checkSource(source) {
|
|
296
300
|
const importPath = source.value;
|
|
297
301
|
if (!importPath || !importPath.startsWith(".") || importPath.endsWith(".js")) {
|
|
298
302
|
return;
|
|
299
303
|
}
|
|
300
|
-
const resolvedPath = path.resolve(path.dirname(context.
|
|
304
|
+
const resolvedPath = path.resolve(path.dirname(context.getFilename()), importPath);
|
|
301
305
|
if (!fs.existsSync(resolvedPath)) {
|
|
302
306
|
context.report({
|
|
303
307
|
node: source,
|
|
304
|
-
|
|
308
|
+
messageId: "requireExtension",
|
|
305
309
|
fix(fixer) {
|
|
306
310
|
const fixedPath = `${importPath}.js`;
|
|
307
311
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -323,19 +327,22 @@ const requireExtensionRule = {
|
|
|
323
327
|
}
|
|
324
328
|
};
|
|
325
329
|
}
|
|
326
|
-
};
|
|
330
|
+
});
|
|
327
331
|
|
|
328
|
-
const requireIndexRule = {
|
|
332
|
+
const requireIndexRule = utils.ESLintUtils.RuleCreator(() => "https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireIndexRule.ts")({
|
|
333
|
+
name: "require-index",
|
|
329
334
|
meta: {
|
|
330
335
|
type: "suggestion",
|
|
331
336
|
docs: {
|
|
332
|
-
description: "Ensure directory import and export statements use index.js"
|
|
333
|
-
category: "Best Practices",
|
|
334
|
-
recommended: true
|
|
337
|
+
description: "Ensure directory import and export statements use index.js"
|
|
335
338
|
},
|
|
336
339
|
fixable: "code",
|
|
337
|
-
schema: []
|
|
340
|
+
schema: [],
|
|
341
|
+
messages: {
|
|
342
|
+
requireExtension: "Directory imports and exports must use index.js."
|
|
343
|
+
}
|
|
338
344
|
},
|
|
345
|
+
defaultOptions: [],
|
|
339
346
|
create(context) {
|
|
340
347
|
function checkSource(source) {
|
|
341
348
|
const importPath = source.value;
|
|
@@ -344,7 +351,7 @@ const requireIndexRule = {
|
|
|
344
351
|
if (isDirectory) {
|
|
345
352
|
context.report({
|
|
346
353
|
node: source,
|
|
347
|
-
|
|
354
|
+
messageId: "requireExtension",
|
|
348
355
|
fix(fixer) {
|
|
349
356
|
const fixedPath = importPath.replace(/\/?$/, "/index.js");
|
|
350
357
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -366,7 +373,7 @@ const requireIndexRule = {
|
|
|
366
373
|
}
|
|
367
374
|
};
|
|
368
375
|
}
|
|
369
|
-
};
|
|
376
|
+
});
|
|
370
377
|
|
|
371
378
|
const base$7 = {
|
|
372
379
|
plugins: {
|
|
@@ -403,6 +410,7 @@ const base$6 = {
|
|
|
403
410
|
}
|
|
404
411
|
},
|
|
405
412
|
plugins: {
|
|
413
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
406
414
|
jsdoc: jsdoc__default
|
|
407
415
|
},
|
|
408
416
|
rules: {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { ConfigWithExtends } from 'typescript-eslint';
|
|
2
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
3
|
|
|
3
4
|
declare const configs$6: {
|
|
4
|
-
base:
|
|
5
|
-
cjsAndEsm:
|
|
6
|
-
cjs:
|
|
5
|
+
base: TSESLint.FlatConfig.Config;
|
|
6
|
+
cjsAndEsm: TSESLint.FlatConfig.Config;
|
|
7
|
+
cjs: TSESLint.FlatConfig.Config;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
declare const configs$5: {
|
|
10
|
-
base:
|
|
11
|
+
base: TSESLint.FlatConfig.Config;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
declare const configs$4: {
|
|
14
|
-
base:
|
|
15
|
+
base: TSESLint.FlatConfig.Config;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
declare const configs$3: {
|
|
18
|
-
base:
|
|
19
|
+
base: TSESLint.FlatConfig.Config;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
declare const configs$2: {
|
|
22
|
-
base:
|
|
23
|
+
base: TSESLint.FlatConfig.Config;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
declare const configs$1: {
|
|
26
|
-
base:
|
|
27
|
+
base: TSESLint.FlatConfig.Config;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
declare const configs: {
|
|
30
|
-
base:
|
|
31
|
+
base: TSESLint.FlatConfig.Config;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
interface DefaultConfigOptions {
|
package/dist/index.d.mts
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { ConfigWithExtends } from 'typescript-eslint';
|
|
2
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
3
|
|
|
3
4
|
declare const configs$6: {
|
|
4
|
-
base:
|
|
5
|
-
cjsAndEsm:
|
|
6
|
-
cjs:
|
|
5
|
+
base: TSESLint.FlatConfig.Config;
|
|
6
|
+
cjsAndEsm: TSESLint.FlatConfig.Config;
|
|
7
|
+
cjs: TSESLint.FlatConfig.Config;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
declare const configs$5: {
|
|
10
|
-
base:
|
|
11
|
+
base: TSESLint.FlatConfig.Config;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
declare const configs$4: {
|
|
14
|
-
base:
|
|
15
|
+
base: TSESLint.FlatConfig.Config;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
declare const configs$3: {
|
|
18
|
-
base:
|
|
19
|
+
base: TSESLint.FlatConfig.Config;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
declare const configs$2: {
|
|
22
|
-
base:
|
|
23
|
+
base: TSESLint.FlatConfig.Config;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
declare const configs$1: {
|
|
26
|
-
base:
|
|
27
|
+
base: TSESLint.FlatConfig.Config;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
declare const configs: {
|
|
30
|
-
base:
|
|
31
|
+
base: TSESLint.FlatConfig.Config;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
interface DefaultConfigOptions {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,33 +1,34 @@
|
|
|
1
1
|
import { ConfigWithExtends } from 'typescript-eslint';
|
|
2
|
+
import { TSESLint } from '@typescript-eslint/utils';
|
|
2
3
|
|
|
3
4
|
declare const configs$6: {
|
|
4
|
-
base:
|
|
5
|
-
cjsAndEsm:
|
|
6
|
-
cjs:
|
|
5
|
+
base: TSESLint.FlatConfig.Config;
|
|
6
|
+
cjsAndEsm: TSESLint.FlatConfig.Config;
|
|
7
|
+
cjs: TSESLint.FlatConfig.Config;
|
|
7
8
|
};
|
|
8
9
|
|
|
9
10
|
declare const configs$5: {
|
|
10
|
-
base:
|
|
11
|
+
base: TSESLint.FlatConfig.Config;
|
|
11
12
|
};
|
|
12
13
|
|
|
13
14
|
declare const configs$4: {
|
|
14
|
-
base:
|
|
15
|
+
base: TSESLint.FlatConfig.Config;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
18
|
declare const configs$3: {
|
|
18
|
-
base:
|
|
19
|
+
base: TSESLint.FlatConfig.Config;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
declare const configs$2: {
|
|
22
|
-
base:
|
|
23
|
+
base: TSESLint.FlatConfig.Config;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
declare const configs$1: {
|
|
26
|
-
base:
|
|
27
|
+
base: TSESLint.FlatConfig.Config;
|
|
27
28
|
};
|
|
28
29
|
|
|
29
30
|
declare const configs: {
|
|
30
|
-
base:
|
|
31
|
+
base: TSESLint.FlatConfig.Config;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
interface DefaultConfigOptions {
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import tsEslint from 'typescript-eslint';
|
|
|
4
4
|
import prettier from 'eslint-plugin-prettier/recommended';
|
|
5
5
|
import { existsSync, lstatSync } from 'fs';
|
|
6
6
|
import { resolve, dirname } from 'path';
|
|
7
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
7
8
|
import jsdoc from 'eslint-plugin-jsdoc';
|
|
8
9
|
import mocha from 'eslint-plugin-mocha';
|
|
9
10
|
import promise from 'eslint-plugin-promise';
|
|
@@ -262,28 +263,31 @@ const configs$8 = {
|
|
|
262
263
|
cjs
|
|
263
264
|
};
|
|
264
265
|
|
|
265
|
-
const requireExtensionRule = {
|
|
266
|
+
const requireExtensionRule = ESLintUtils.RuleCreator(() => "https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireExtensionRule.ts")({
|
|
267
|
+
name: "require-extension",
|
|
266
268
|
meta: {
|
|
267
269
|
type: "suggestion",
|
|
268
270
|
docs: {
|
|
269
|
-
description: "Ensure import and export statements include a file extension"
|
|
270
|
-
category: "Best Practices",
|
|
271
|
-
recommended: true
|
|
271
|
+
description: "Ensure import and export statements include a file extension"
|
|
272
272
|
},
|
|
273
273
|
fixable: "code",
|
|
274
|
-
schema: []
|
|
274
|
+
schema: [],
|
|
275
|
+
messages: {
|
|
276
|
+
requireExtension: "Relative imports and exports must include a file extension."
|
|
277
|
+
}
|
|
275
278
|
},
|
|
279
|
+
defaultOptions: [],
|
|
276
280
|
create(context) {
|
|
277
281
|
function checkSource(source) {
|
|
278
282
|
const importPath = source.value;
|
|
279
283
|
if (!importPath || !importPath.startsWith(".") || importPath.endsWith(".js")) {
|
|
280
284
|
return;
|
|
281
285
|
}
|
|
282
|
-
const resolvedPath = resolve(dirname(context.
|
|
286
|
+
const resolvedPath = resolve(dirname(context.getFilename()), importPath);
|
|
283
287
|
if (!existsSync(resolvedPath)) {
|
|
284
288
|
context.report({
|
|
285
289
|
node: source,
|
|
286
|
-
|
|
290
|
+
messageId: "requireExtension",
|
|
287
291
|
fix(fixer) {
|
|
288
292
|
const fixedPath = `${importPath}.js`;
|
|
289
293
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -305,19 +309,22 @@ const requireExtensionRule = {
|
|
|
305
309
|
}
|
|
306
310
|
};
|
|
307
311
|
}
|
|
308
|
-
};
|
|
312
|
+
});
|
|
309
313
|
|
|
310
|
-
const requireIndexRule = {
|
|
314
|
+
const requireIndexRule = ESLintUtils.RuleCreator(() => "https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireIndexRule.ts")({
|
|
315
|
+
name: "require-index",
|
|
311
316
|
meta: {
|
|
312
317
|
type: "suggestion",
|
|
313
318
|
docs: {
|
|
314
|
-
description: "Ensure directory import and export statements use index.js"
|
|
315
|
-
category: "Best Practices",
|
|
316
|
-
recommended: true
|
|
319
|
+
description: "Ensure directory import and export statements use index.js"
|
|
317
320
|
},
|
|
318
321
|
fixable: "code",
|
|
319
|
-
schema: []
|
|
322
|
+
schema: [],
|
|
323
|
+
messages: {
|
|
324
|
+
requireExtension: "Directory imports and exports must use index.js."
|
|
325
|
+
}
|
|
320
326
|
},
|
|
327
|
+
defaultOptions: [],
|
|
321
328
|
create(context) {
|
|
322
329
|
function checkSource(source) {
|
|
323
330
|
const importPath = source.value;
|
|
@@ -326,7 +333,7 @@ const requireIndexRule = {
|
|
|
326
333
|
if (isDirectory) {
|
|
327
334
|
context.report({
|
|
328
335
|
node: source,
|
|
329
|
-
|
|
336
|
+
messageId: "requireExtension",
|
|
330
337
|
fix(fixer) {
|
|
331
338
|
const fixedPath = importPath.replace(/\/?$/, "/index.js");
|
|
332
339
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -348,7 +355,7 @@ const requireIndexRule = {
|
|
|
348
355
|
}
|
|
349
356
|
};
|
|
350
357
|
}
|
|
351
|
-
};
|
|
358
|
+
});
|
|
352
359
|
|
|
353
360
|
const base$7 = {
|
|
354
361
|
plugins: {
|
|
@@ -385,6 +392,7 @@ const base$6 = {
|
|
|
385
392
|
}
|
|
386
393
|
},
|
|
387
394
|
plugins: {
|
|
395
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
388
396
|
jsdoc
|
|
389
397
|
},
|
|
390
398
|
rules: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-decent",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "A decent ESLint configuration",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -72,31 +72,32 @@
|
|
|
72
72
|
"node": ">=20.11.0"
|
|
73
73
|
},
|
|
74
74
|
"dependencies": {
|
|
75
|
-
"@eslint/js": "^9.
|
|
75
|
+
"@eslint/js": "^9.7.0",
|
|
76
|
+
"@typescript-eslint/utils": "8.0.0-alpha.46",
|
|
76
77
|
"eslint-config-prettier": "^9.1.0",
|
|
77
78
|
"eslint-plugin-jsdoc": "^48.7.0",
|
|
78
79
|
"eslint-plugin-mocha": "^10.4.3",
|
|
79
|
-
"eslint-plugin-prettier": "^5.1
|
|
80
|
+
"eslint-plugin-prettier": "^5.2.1",
|
|
80
81
|
"eslint-plugin-promise": "^6.4.0",
|
|
81
82
|
"eslint-plugin-jsx-a11y": "^6.9.0",
|
|
82
|
-
"eslint-plugin-react": "^7.34.
|
|
83
|
+
"eslint-plugin-react": "^7.34.4",
|
|
83
84
|
"eslint-plugin-react-hooks": "^4.6.2",
|
|
84
85
|
"eslint-plugin-security": "^3.0.1",
|
|
85
86
|
"eslint-plugin-testing-library": "^6.2.2",
|
|
86
87
|
"eslint-plugin-unicorn": "^54.0.0",
|
|
87
88
|
"globals": "^15.8.0",
|
|
88
|
-
"typescript-eslint": "8.0.0-alpha.
|
|
89
|
+
"typescript-eslint": "8.0.0-alpha.46"
|
|
89
90
|
},
|
|
90
91
|
"devDependencies": {
|
|
91
|
-
"@swc/core": "1.
|
|
92
|
+
"@swc/core": "1.7.0",
|
|
92
93
|
"@types/node": ">=20",
|
|
93
|
-
"eslint": "^9.
|
|
94
|
-
"husky": "^9.
|
|
94
|
+
"eslint": "^9.7.0",
|
|
95
|
+
"husky": "^9.1.1",
|
|
95
96
|
"lint-staged": "^15.2.7",
|
|
96
97
|
"markdownlint-cli": "^0.41.0",
|
|
97
98
|
"npm-run-all": "^4.1.5",
|
|
98
99
|
"pinst": "^3.0.0",
|
|
99
|
-
"prettier": "^3.3.
|
|
100
|
+
"prettier": "^3.3.3",
|
|
100
101
|
"typescript": "^5.5.3",
|
|
101
102
|
"unbuild": "2.0.0"
|
|
102
103
|
},
|
package/src/eslint.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
2
|
|
|
3
|
-
const base:
|
|
3
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
4
4
|
rules: {
|
|
5
5
|
'array-callback-return': ['error', { allowImplicit: true }],
|
|
6
6
|
'block-scoped-var': 'error',
|
|
@@ -201,7 +201,7 @@ const base: ConfigWithExtends = {
|
|
|
201
201
|
},
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
const cjsAndEsm:
|
|
204
|
+
const cjsAndEsm: TSESLint.FlatConfig.Config = {
|
|
205
205
|
rules: {
|
|
206
206
|
curly: ['error', 'multi-line'],
|
|
207
207
|
'dot-notation': ['error', { allowKeywords: true }],
|
|
@@ -236,7 +236,7 @@ const cjsAndEsm: ConfigWithExtends = {
|
|
|
236
236
|
},
|
|
237
237
|
};
|
|
238
238
|
|
|
239
|
-
const cjs:
|
|
239
|
+
const cjs: TSESLint.FlatConfig.Config = {
|
|
240
240
|
rules: {
|
|
241
241
|
strict: ['error', 'global'],
|
|
242
242
|
},
|
package/src/extension.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { ConfigWithExtends } from 'typescript-eslint';
|
|
2
1
|
import { requireExtensionRule } from './rules/requireExtensionRule.js';
|
|
3
2
|
import { requireIndexRule } from './rules/requireIndexRule.js';
|
|
3
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
4
4
|
|
|
5
|
-
const base:
|
|
5
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
6
6
|
plugins: {
|
|
7
7
|
'decent-extension': {
|
|
8
8
|
meta: {
|
package/src/index.ts
CHANGED
package/src/jsdoc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import jsdoc from 'eslint-plugin-jsdoc';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
const base:
|
|
4
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
5
5
|
settings: {
|
|
6
6
|
jsdoc: {
|
|
7
7
|
preferredTypes: {
|
|
@@ -14,6 +14,7 @@ const base: ConfigWithExtends = {
|
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
plugins: {
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
17
18
|
jsdoc,
|
|
18
19
|
},
|
|
19
20
|
rules: {
|
package/src/mocha.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import mocha from 'eslint-plugin-mocha';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
const base:
|
|
4
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
5
5
|
plugins: {
|
|
6
6
|
mocha,
|
|
7
7
|
},
|
package/src/promise.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import promise from 'eslint-plugin-promise';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
const base:
|
|
4
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
5
5
|
plugins: {
|
|
6
6
|
promise,
|
|
7
7
|
},
|
package/src/react.ts
CHANGED
|
@@ -2,9 +2,9 @@ import a11y from 'eslint-plugin-jsx-a11y';
|
|
|
2
2
|
import react from 'eslint-plugin-react';
|
|
3
3
|
import reactHooks from 'eslint-plugin-react-hooks';
|
|
4
4
|
import testingLibrary from 'eslint-plugin-testing-library';
|
|
5
|
-
import type {
|
|
5
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
6
6
|
|
|
7
|
-
const base:
|
|
7
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
8
8
|
plugins: {
|
|
9
9
|
'jsx-a11y': a11y,
|
|
10
10
|
react,
|
|
@@ -1,34 +1,41 @@
|
|
|
1
1
|
import { existsSync } from 'fs';
|
|
2
2
|
import { dirname, resolve } from 'path';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
4
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
type Options = [];
|
|
7
|
+
type MessageIds = 'requireExtension';
|
|
8
|
+
|
|
9
|
+
export const requireExtensionRule = ESLintUtils.RuleCreator(() => 'https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireExtensionRule.ts')<Options, MessageIds>({
|
|
10
|
+
name: 'require-extension',
|
|
6
11
|
meta: {
|
|
7
12
|
type: 'suggestion',
|
|
8
13
|
docs: {
|
|
9
14
|
description: 'Ensure import and export statements include a file extension',
|
|
10
|
-
category: 'Best Practices',
|
|
11
|
-
recommended: true,
|
|
12
15
|
},
|
|
13
16
|
fixable: 'code',
|
|
14
17
|
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
requireExtension: 'Relative imports and exports must include a file extension.',
|
|
20
|
+
},
|
|
15
21
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create(context) {
|
|
24
|
+
function checkSource(source: TSESTree.StringLiteral): void {
|
|
25
|
+
const importPath = source.value;
|
|
19
26
|
|
|
20
27
|
if (!importPath || !importPath.startsWith('.') || importPath.endsWith('.js')) {
|
|
21
28
|
return;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
const resolvedPath = resolve(dirname(context.
|
|
31
|
+
const resolvedPath = resolve(dirname(context.getFilename()), importPath);
|
|
25
32
|
|
|
26
33
|
// If the import/export path doesn't end with a file extension, report an error
|
|
27
34
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
28
35
|
if (!existsSync(resolvedPath)) {
|
|
29
36
|
context.report({
|
|
30
37
|
node: source,
|
|
31
|
-
|
|
38
|
+
messageId: 'requireExtension',
|
|
32
39
|
fix(fixer) {
|
|
33
40
|
const fixedPath = `${importPath}.js`;
|
|
34
41
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -38,17 +45,17 @@ export const requireExtensionRule: Rule.RuleModule = {
|
|
|
38
45
|
}
|
|
39
46
|
|
|
40
47
|
return {
|
|
41
|
-
ImportDeclaration(node:
|
|
48
|
+
ImportDeclaration(node: TSESTree.ImportDeclaration): void {
|
|
42
49
|
checkSource(node.source);
|
|
43
50
|
},
|
|
44
|
-
ExportNamedDeclaration(node:
|
|
51
|
+
ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void {
|
|
45
52
|
if (node.source) {
|
|
46
53
|
checkSource(node.source);
|
|
47
54
|
}
|
|
48
55
|
},
|
|
49
|
-
ExportAllDeclaration(node:
|
|
56
|
+
ExportAllDeclaration(node: TSESTree.ExportAllDeclaration): void {
|
|
50
57
|
checkSource(node.source);
|
|
51
58
|
},
|
|
52
59
|
};
|
|
53
60
|
},
|
|
54
|
-
};
|
|
61
|
+
});
|
|
@@ -1,31 +1,39 @@
|
|
|
1
1
|
import { existsSync, lstatSync } from 'fs';
|
|
2
2
|
import { resolve, dirname } from 'path';
|
|
3
|
-
import type {
|
|
3
|
+
import type { TSESTree } from '@typescript-eslint/utils';
|
|
4
|
+
import { ESLintUtils } from '@typescript-eslint/utils';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
type Options = [];
|
|
7
|
+
type MessageIds = 'requireExtension';
|
|
8
|
+
|
|
9
|
+
export const requireIndexRule = ESLintUtils.RuleCreator(() => 'https://github.com/jgeurts/eslint-config-decent/tree/main/src/rules/requireIndexRule.ts')<Options, MessageIds>({
|
|
10
|
+
name: 'require-index',
|
|
6
11
|
meta: {
|
|
7
12
|
type: 'suggestion',
|
|
8
13
|
docs: {
|
|
9
14
|
description: 'Ensure directory import and export statements use index.js',
|
|
10
|
-
category: 'Best Practices',
|
|
11
|
-
recommended: true,
|
|
12
15
|
},
|
|
13
16
|
fixable: 'code',
|
|
14
17
|
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
requireExtension: 'Directory imports and exports must use index.js.',
|
|
20
|
+
},
|
|
15
21
|
},
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
22
|
+
defaultOptions: [],
|
|
23
|
+
create(context) {
|
|
24
|
+
function checkSource(source: TSESTree.StringLiteral): void {
|
|
25
|
+
const importPath = source.value;
|
|
19
26
|
|
|
20
27
|
// Resolve the path relative to the file being linted
|
|
21
28
|
const resolvedPath = resolve(dirname(context.filename), importPath);
|
|
22
29
|
|
|
23
30
|
// eslint-disable-next-line security/detect-non-literal-fs-filename
|
|
24
31
|
const isDirectory = existsSync(resolvedPath) && lstatSync(resolvedPath).isDirectory();
|
|
32
|
+
// If the import/export path doesn't end with a file extension, report an error
|
|
25
33
|
if (isDirectory) {
|
|
26
34
|
context.report({
|
|
27
35
|
node: source,
|
|
28
|
-
|
|
36
|
+
messageId: 'requireExtension',
|
|
29
37
|
fix(fixer) {
|
|
30
38
|
const fixedPath = importPath.replace(/\/?$/, '/index.js');
|
|
31
39
|
return fixer.replaceText(source, `'${fixedPath}'`);
|
|
@@ -35,17 +43,17 @@ export const requireIndexRule: Rule.RuleModule = {
|
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
return {
|
|
38
|
-
ImportDeclaration(node:
|
|
46
|
+
ImportDeclaration(node: TSESTree.ImportDeclaration): void {
|
|
39
47
|
checkSource(node.source);
|
|
40
48
|
},
|
|
41
|
-
ExportNamedDeclaration(node:
|
|
49
|
+
ExportNamedDeclaration(node: TSESTree.ExportNamedDeclaration): void {
|
|
42
50
|
if (node.source) {
|
|
43
51
|
checkSource(node.source);
|
|
44
52
|
}
|
|
45
53
|
},
|
|
46
|
-
ExportAllDeclaration(node:
|
|
54
|
+
ExportAllDeclaration(node: TSESTree.ExportAllDeclaration): void {
|
|
47
55
|
checkSource(node.source);
|
|
48
56
|
},
|
|
49
57
|
};
|
|
50
58
|
},
|
|
51
|
-
};
|
|
59
|
+
});
|
package/src/security.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import security from 'eslint-plugin-security';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
const base:
|
|
4
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
5
5
|
plugins: {
|
|
6
6
|
security,
|
|
7
7
|
},
|
package/src/types/eslint-js.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module '@eslint/js' {
|
|
2
|
-
import type {
|
|
3
|
-
const value:
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
const value: TSESLint.FlatConfig.Plugin & {
|
|
4
4
|
configs: {
|
|
5
|
-
recommended:
|
|
5
|
+
recommended: TSESLint.FlatConfig.Config;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export default value;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module 'eslint-plugin-jsx-a11y' {
|
|
2
|
-
import type {
|
|
3
|
-
const value:
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
const value: TSESLint.FlatConfig.Plugin & {
|
|
4
4
|
configs: {
|
|
5
|
-
recommended:
|
|
5
|
+
recommended: TSESLint.FlatConfig.Config;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export default value;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module 'eslint-plugin-mocha' {
|
|
2
|
-
import type {
|
|
3
|
-
const value:
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
const value: TSESLint.FlatConfig.Plugin & {
|
|
4
4
|
configs: {
|
|
5
|
-
recommended:
|
|
5
|
+
recommended: TSESLint.FlatConfig.Config;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export default value;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module 'eslint-plugin-react' {
|
|
2
|
-
import type {
|
|
3
|
-
const value:
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
const value: TSESLint.FlatConfig.Plugin & {
|
|
4
4
|
configs: {
|
|
5
|
-
recommended:
|
|
5
|
+
recommended: TSESLint.FlatConfig.Config;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export default value;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
declare module 'eslint-plugin-testing-library' {
|
|
2
|
-
import type {
|
|
3
|
-
const value:
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
|
+
const value: TSESLint.FlatConfig.Plugin & {
|
|
4
4
|
configs: {
|
|
5
|
-
react:
|
|
5
|
+
react: TSESLint.FlatConfig.Config;
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
export default value;
|
package/src/typescriptEslint.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
2
2
|
|
|
3
|
-
const base:
|
|
3
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
4
4
|
rules: {
|
|
5
5
|
'no-loss-of-precision': 'off',
|
|
6
6
|
'no-loop-func': 'off',
|
package/src/unicorn.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import unicorn from 'eslint-plugin-unicorn';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TSESLint } from '@typescript-eslint/utils';
|
|
3
3
|
|
|
4
|
-
const base:
|
|
4
|
+
const base: TSESLint.FlatConfig.Config = {
|
|
5
5
|
plugins: {
|
|
6
6
|
unicorn,
|
|
7
7
|
},
|