eslint-plugin-raflint 1.4.1 → 1.5.0
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.d.ts +3 -0
- package/{index.js → dist/index.js} +2 -2
- package/dist/rules/noConditionalObjectSpread.d.ts +3 -0
- package/dist/rules/noConditionalObjectSpread.js +13 -0
- package/dist/rules/noPathJoin.d.ts +3 -0
- package/dist/rules/noPathJoin.js +34 -0
- package/package.json +24 -14
- package/TESTING.md +0 -18
- package/assets/testExample.js +0 -22
- package/eslint.config.js +0 -286
- package/eslinttest.config.js +0 -13
- package/rules/noConditionalObjectSpread.js +0 -14
- package/rules/noPathJoin.js +0 -43
- package/test/noConditionalObjectSpread.test.js +0 -46
- package/test/noPathJoin.test.js +0 -78
- package/todo.txt +0 -96
package/dist/index.d.ts
ADDED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import noConditionalObjectSpread from './rules/noConditionalObjectSpread.js';
|
|
2
2
|
import noPathJoin from './rules/noPathJoin.js';
|
|
3
|
-
|
|
4
|
-
export default {
|
|
3
|
+
const plugin = {
|
|
5
4
|
rules: {
|
|
6
5
|
'no-conditional-object-spread': noConditionalObjectSpread,
|
|
7
6
|
'no-path-join': noPathJoin,
|
|
8
7
|
},
|
|
9
8
|
};
|
|
9
|
+
export default plugin;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const rule = {
|
|
2
|
+
create: (context) => ({
|
|
3
|
+
SpreadElement(node) {
|
|
4
|
+
if (node.argument.type === 'ConditionalExpression' || node.argument.type === 'LogicalExpression') {
|
|
5
|
+
context.report({
|
|
6
|
+
node,
|
|
7
|
+
message: 'Conditional object spread is not allowed.',
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
}),
|
|
12
|
+
};
|
|
13
|
+
export default rule;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const rule = {
|
|
2
|
+
meta: {
|
|
3
|
+
type: 'suggestion',
|
|
4
|
+
docs: {
|
|
5
|
+
description: 'Disallow path.join() in favor of template strings',
|
|
6
|
+
recommended: true,
|
|
7
|
+
},
|
|
8
|
+
fixable: 'code',
|
|
9
|
+
schema: [],
|
|
10
|
+
},
|
|
11
|
+
create(context) {
|
|
12
|
+
return {
|
|
13
|
+
CallExpression(node) {
|
|
14
|
+
if (!(node.callee.type === 'MemberExpression' && node.callee.object.name === 'path' && node.callee.property.name === 'join' && node.arguments.length >= 2)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
18
|
+
const parts = node.arguments.map((argument) => {
|
|
19
|
+
if (argument.type === 'Literal' && typeof argument.value === 'string') {
|
|
20
|
+
return argument.value;
|
|
21
|
+
}
|
|
22
|
+
return `\${${sourceCode.getText(argument)}}`;
|
|
23
|
+
});
|
|
24
|
+
const replacement = `\`${parts.join('/')}\``;
|
|
25
|
+
context.report({
|
|
26
|
+
node,
|
|
27
|
+
message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples',
|
|
28
|
+
fix: (fixer) => fixer.replaceText(node, replacement),
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
export default rule;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-raflint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"keywords": [],
|
|
@@ -11,38 +11,48 @@
|
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"author": "Raphael Piccolo",
|
|
13
13
|
"type": "module",
|
|
14
|
-
"
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"exports": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
15
20
|
"scripts": {
|
|
21
|
+
"build": "tsc",
|
|
16
22
|
"cov": "c8 npm run test",
|
|
17
23
|
"prepare": "husky",
|
|
18
|
-
"
|
|
24
|
+
"prepublishOnly": "npm run build",
|
|
25
|
+
"test": "SILENT=1 mocha --timeout 60000 {,lib/**/,test/**/}*.test.ts"
|
|
19
26
|
},
|
|
20
27
|
"dependencies": {
|
|
21
|
-
"@babel/eslint-parser": "^8.0.
|
|
22
|
-
"eslint-plugin-n": "^18.1
|
|
23
|
-
"eslint-plugin-sonarjs": "^4.0
|
|
24
|
-
"eslint-plugin-unicorn": "^
|
|
28
|
+
"@babel/eslint-parser": "^8.0.1",
|
|
29
|
+
"eslint-plugin-n": "^18.2.1",
|
|
30
|
+
"eslint-plugin-sonarjs": "^4.1.0",
|
|
31
|
+
"eslint-plugin-unicorn": "^69.0.0"
|
|
25
32
|
},
|
|
26
33
|
"devDependencies": {
|
|
27
34
|
"@eslint/js": "^10.0.1",
|
|
28
35
|
"@stoplight/spectral-cli": "^6.16.0",
|
|
29
36
|
"c8": "^11.0.0",
|
|
30
37
|
"eslint": "^10.5.0",
|
|
31
|
-
"eslint-plugin-import-x": "^4.
|
|
38
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
32
39
|
"eslint-plugin-promise": "^7.3.0",
|
|
33
|
-
"eslint-plugin-raflint": "^1.4.
|
|
34
|
-
"globals": "^17.
|
|
40
|
+
"eslint-plugin-raflint": "^1.4.1",
|
|
41
|
+
"globals": "^17.7.0",
|
|
35
42
|
"husky": "^9.1.7",
|
|
36
|
-
"lint-staged": "^17.0.
|
|
43
|
+
"lint-staged": "^17.0.8",
|
|
37
44
|
"markdownlint": "^0.41.0",
|
|
38
45
|
"mocha": "^11.7.6",
|
|
39
|
-
"prettier": "^3.
|
|
40
|
-
"ts-api-utils": "^2.5.0"
|
|
46
|
+
"prettier": "^3.9.1",
|
|
47
|
+
"ts-api-utils": "^2.5.0",
|
|
48
|
+
"tsx": "^4.22.4",
|
|
49
|
+
"typescript": "^6.0.3"
|
|
41
50
|
},
|
|
42
51
|
"engines": {
|
|
43
52
|
"node": ">=21.0.0"
|
|
44
53
|
},
|
|
45
54
|
"allowScripts": {
|
|
46
|
-
"unrs-resolver": true
|
|
55
|
+
"unrs-resolver": true,
|
|
56
|
+
"esbuild": true
|
|
47
57
|
}
|
|
48
58
|
}
|
package/TESTING.md
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
# Comment tester la règle no-path-join
|
|
2
|
-
## Test manuel avec le fichier d'exemple
|
|
3
|
-
|
|
4
|
-
Un fichier d'exemple `assets/testExample.js` a été créé pour démontrer le fonctionnement de la règle. Pour tester manuellement:
|
|
5
|
-
|
|
6
|
-
1. Vérifier que la règle détecte les problèmes:
|
|
7
|
-
|
|
8
|
-
```bash
|
|
9
|
-
npx eslint -c eslinttest.config.js assets/testExample.js
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Vous devriez voir des erreurs pour les lignes contenant `path.join(directory, filename)` et `path.join(process.cwd(), 'file.txt')`.
|
|
13
|
-
|
|
14
|
-
2. Vérifier que la règle corrige automatiquement le code:
|
|
15
|
-
|
|
16
|
-
```bash
|
|
17
|
-
npx eslint -c eslinttest.config.js assets/testExample.js --fix
|
|
18
|
-
```
|
package/assets/testExample.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
// Exemple de code utilisant path.join() qui sera détecté par notre règle
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
|
|
4
|
-
// Définition des variables pour éviter les erreurs ESLint
|
|
5
|
-
const directory = '/home/user';
|
|
6
|
-
const filename = 'file.txt';
|
|
7
|
-
const root = '/';
|
|
8
|
-
|
|
9
|
-
// Ce code sera détecté et corrigé par notre règle
|
|
10
|
-
const filePath1 = `${directory}/${filename}`;
|
|
11
|
-
|
|
12
|
-
// Ce code sera détecté et corrigé par notre règle
|
|
13
|
-
const filePath2 = `${process.cwd()}/file.txt`;
|
|
14
|
-
|
|
15
|
-
// Ce code ne sera pas détecté car il a plus de 2 arguments
|
|
16
|
-
const filePath3 = path.join(root, directory, filename);
|
|
17
|
-
|
|
18
|
-
// Ce code est déjà au format recommandé
|
|
19
|
-
const filePath4 = `${directory}/${filename}`;
|
|
20
|
-
|
|
21
|
-
// Pour éviter les erreurs "unused variable"
|
|
22
|
-
console.log(filePath1, filePath2, filePath3, filePath4);
|
package/eslint.config.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
import sonarjs from 'eslint-plugin-sonarjs';
|
|
2
|
-
import unicorn from 'eslint-plugin-unicorn';
|
|
3
|
-
import promise from 'eslint-plugin-promise';
|
|
4
|
-
import n from 'eslint-plugin-n';
|
|
5
|
-
import raflint from 'eslint-plugin-raflint';
|
|
6
|
-
import pluginimport from 'eslint-plugin-import-x';
|
|
7
|
-
import babelParser from '@babel/eslint-parser';
|
|
8
|
-
import js from '@eslint/js';
|
|
9
|
-
import globals from 'globals';
|
|
10
|
-
|
|
11
|
-
export default [
|
|
12
|
-
// eslint:recommended,
|
|
13
|
-
js.configs.recommended,
|
|
14
|
-
|
|
15
|
-
// unicorn
|
|
16
|
-
unicorn.configs['flat/recommended'],
|
|
17
|
-
|
|
18
|
-
// n
|
|
19
|
-
n.configs['flat/recommended'],
|
|
20
|
-
|
|
21
|
-
// sonarjs
|
|
22
|
-
sonarjs.configs.recommended,
|
|
23
|
-
|
|
24
|
-
// promise
|
|
25
|
-
promise.configs['flat/recommended'],
|
|
26
|
-
|
|
27
|
-
// plugin:import/recommended,
|
|
28
|
-
pluginimport.flatConfigs.recommended,
|
|
29
|
-
|
|
30
|
-
{
|
|
31
|
-
ignores: ['legacy/', 'dist/', 'node_modules/', 'web/', 'public/', 'coverage/', 'data/', 'vendor/', 'react/', 'js/', 'assets/', '**/old/'],
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
languageOptions: {
|
|
35
|
-
globals: {
|
|
36
|
-
...globals.browser,
|
|
37
|
-
...globals.node,
|
|
38
|
-
...globals.mocha,
|
|
39
|
-
},
|
|
40
|
-
parser: babelParser,
|
|
41
|
-
parserOptions: {
|
|
42
|
-
ecmaVersion: 'latest',
|
|
43
|
-
sourceType: 'module',
|
|
44
|
-
requireConfigFile: false,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
plugins: {
|
|
48
|
-
raflint,
|
|
49
|
-
},
|
|
50
|
-
rules: {
|
|
51
|
-
'sonarjs/no-empty-function': 0,
|
|
52
|
-
'sonarjs/no-unused-expressions': 0,
|
|
53
|
-
'sonarjs/no-unsafe-unzip': 0,
|
|
54
|
-
'sonarjs/os-command': 0,
|
|
55
|
-
'sonarjs/cors': 0,
|
|
56
|
-
'sonarjs/publicly-writable-directories': 0,
|
|
57
|
-
'sonarjs/file-permissions': 0,
|
|
58
|
-
'sonarjs/no-empty-test-file': 0,
|
|
59
|
-
'import-x/no-named-as-default-member': 0,
|
|
60
|
-
'import-x/no-unresolved': [
|
|
61
|
-
'error',
|
|
62
|
-
{
|
|
63
|
-
ignore: [
|
|
64
|
-
'^yargs/helpers$',
|
|
65
|
-
'^p-queue$',
|
|
66
|
-
'^@vitejs/plugin-react$',
|
|
67
|
-
'^public-ip$',
|
|
68
|
-
'^@modelcontextprotocol/sdk/',
|
|
69
|
-
'^@maizzle/framework$',
|
|
70
|
-
'^file-type$',
|
|
71
|
-
'^vite$',
|
|
72
|
-
'^windows-1252$',
|
|
73
|
-
'^csv-parse/sync$'
|
|
74
|
-
],
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
'sonarjs/regex-complexity': 0,
|
|
78
|
-
'sonarjs/no-clear-text-protocols': 0,
|
|
79
|
-
'sonarjs/no-infinite-loop': 0,
|
|
80
|
-
'sonarjs/no-hardcoded-ip': 0,
|
|
81
|
-
'sonarjs/pluginRules-of-hooks': 0,
|
|
82
|
-
'sonarjs/sonar-no-fallthrough': 0,
|
|
83
|
-
'sonarjs/no-ignored-exceptions': 0,
|
|
84
|
-
'sonarjs/slow-regex': 0,
|
|
85
|
-
'sonarjs/concise-regex': 0,
|
|
86
|
-
'sonarjs/hashing': 0,
|
|
87
|
-
'sonarjs/no-dead-store': 0,
|
|
88
|
-
'sonarjs/no-unused-vars': 0,
|
|
89
|
-
'sonarjs/no-hardcoded-passwords': 0,
|
|
90
|
-
'sonarjs/no-hardcoded-secrets': 0,
|
|
91
|
-
'sonarjs/unnecessary-character-escapes': 0,
|
|
92
|
-
'sonarjs/pseudo-random': 0,
|
|
93
|
-
'sonarjs/no-os-command-from-path': 0,
|
|
94
|
-
'sonarjs/anchor-precedence': 0,
|
|
95
|
-
'sonarjs/no-nested-functions': 0,
|
|
96
|
-
'sonarjs/new-cap': 0,
|
|
97
|
-
'sonarjs/sql-queries': 0,
|
|
98
|
-
'sonarjs/content-length': 0,
|
|
99
|
-
'sonarjs/no-commented-code': 0,
|
|
100
|
-
'raflint/no-conditional-object-spread': ['error'],
|
|
101
|
-
'raflint/no-path-join': ['error'],
|
|
102
|
-
'unicorn/prefer-event-target': 0,
|
|
103
|
-
'unicorn/prefer-structured-clone': 0,
|
|
104
|
-
'unicorn/prefer-string-raw': 0,
|
|
105
|
-
'unicorn/no-anonymous-default-export': 0,
|
|
106
|
-
'unicorn/better-regex': 0,
|
|
107
|
-
'unicorn/catch-error-name': 0,
|
|
108
|
-
'unicorn/consistent-function-scoping': 0,
|
|
109
|
-
'unicorn/expiring-todo-comments': 0,
|
|
110
|
-
'unicorn/explicit-length-check': 0,
|
|
111
|
-
'unicorn/import-style': 0,
|
|
112
|
-
'unicorn/no-array-for-each': 0,
|
|
113
|
-
'unicorn/prefer-single-call': 0,
|
|
114
|
-
'unicorn/no-array-reduce': 0,
|
|
115
|
-
'unicorn/no-lonely-if': 0,
|
|
116
|
-
'unicorn/no-negated-condition': 0,
|
|
117
|
-
'unicorn/no-null': 0,
|
|
118
|
-
'unicorn/no-process-exit': 0,
|
|
119
|
-
'unicorn/no-this-assignment': 0,
|
|
120
|
-
'unicorn/no-unnecessary-await': 0,
|
|
121
|
-
'unicorn/no-unused-properties': 0,
|
|
122
|
-
'unicorn/prefer-code-point': 0,
|
|
123
|
-
'unicorn/prefer-default-parameters': 0,
|
|
124
|
-
'unicorn/prefer-export-from': 0,
|
|
125
|
-
'unicorn/prefer-native-coercion-functions': 0,
|
|
126
|
-
'unicorn/prefer-number-properties': 0,
|
|
127
|
-
'unicorn/prefer-set-has': 0,
|
|
128
|
-
'unicorn/prefer-set-size': 0,
|
|
129
|
-
'unicorn/prefer-spread': 0,
|
|
130
|
-
'unicorn/prefer-string-replace-all': 0,
|
|
131
|
-
'unicorn/prefer-string-slice': 0,
|
|
132
|
-
'unicorn/prefer-switch': 0,
|
|
133
|
-
'unicorn/prefer-ternary': 0,
|
|
134
|
-
'unicorn/prefer-top-level-await': 0,
|
|
135
|
-
'unicorn/prevent-abbreviations': 0,
|
|
136
|
-
'unicorn/consistent-compound-words': 0,
|
|
137
|
-
// ne pas retirer `undefined` passe en argument (souvent requis par la signature -> casse tsc)
|
|
138
|
-
'unicorn/no-useless-undefined': ['error', { checkArguments: false }],
|
|
139
|
-
'unicorn/relative-url-style': 0,
|
|
140
|
-
'unicorn/switch-case-braces': 0,
|
|
141
|
-
'unicorn/template-indent': 0,
|
|
142
|
-
'unicorn/text-encoding-identifier-case': 0,
|
|
143
|
-
'unicorn/prefer-regexp-test': 0,
|
|
144
|
-
'unicorn/prefer-optional-catch-binding': 0,
|
|
145
|
-
'unicorn/filename-case': 0,
|
|
146
|
-
'sonarjs/cognitive-complexity': 0,
|
|
147
|
-
'sonarjs/no-nested-template-literals': 0,
|
|
148
|
-
'sonarjs/no-collapsible-if': 0,
|
|
149
|
-
'sonarjs/no-duplicate-string': 0,
|
|
150
|
-
'sonarjs/prefer-immediate-return': 0,
|
|
151
|
-
'sonarjs/no-identical-functions': 0,
|
|
152
|
-
'sonarjs/prefer-object-literal': 0,
|
|
153
|
-
'sonarjs/prefer-single-boolean-return': 0,
|
|
154
|
-
'n/no-unpublished-import': 0,
|
|
155
|
-
'n/no-unsupported-features/es-syntax': 0,
|
|
156
|
-
'n/no-unsupported-features/node-builtins': 0,
|
|
157
|
-
'n/no-missing-import': 0,
|
|
158
|
-
'n/no-process-exit': 0,
|
|
159
|
-
|
|
160
|
-
// si on l'active ça pose pb dans check / automerge
|
|
161
|
-
'n/shebang': 0,
|
|
162
|
-
|
|
163
|
-
'one-var-declaration-per-line': ['error', 'always'],
|
|
164
|
-
'one-var': ['error', 'never'],
|
|
165
|
-
'no-unused-expressions': 'error',
|
|
166
|
-
'no-nested-ternary': 'error',
|
|
167
|
-
'no-use-before-define': [
|
|
168
|
-
'error',
|
|
169
|
-
{
|
|
170
|
-
functions: false,
|
|
171
|
-
classes: false,
|
|
172
|
-
variables: true,
|
|
173
|
-
allowNamedExports: false,
|
|
174
|
-
},
|
|
175
|
-
],
|
|
176
|
-
'no-new-native-nonconstructor': 'error',
|
|
177
|
-
'no-empty-static-block': 'error',
|
|
178
|
-
'symbol-description': 'error',
|
|
179
|
-
'require-yield': 'error',
|
|
180
|
-
'prefer-spread': 'error',
|
|
181
|
-
'prefer-rest-params': 'error',
|
|
182
|
-
'prefer-object-spread': 'error',
|
|
183
|
-
'prefer-object-has-own': 'error',
|
|
184
|
-
'prefer-numeric-literals': 'error',
|
|
185
|
-
'prefer-exponentiation-operator': 'error',
|
|
186
|
-
'operator-assignment': 'error',
|
|
187
|
-
'no-useless-rename': 'error',
|
|
188
|
-
'no-useless-constructor': 'error',
|
|
189
|
-
'no-useless-computed-key': 'error',
|
|
190
|
-
'no-unused-labels': 'error',
|
|
191
|
-
'no-script-url': 'error',
|
|
192
|
-
'no-new-object': 'error',
|
|
193
|
-
'no-multi-assign': 'error',
|
|
194
|
-
'no-loop-func': 'error',
|
|
195
|
-
'no-inline-comments': 'error',
|
|
196
|
-
'no-implicit-coercion': 'error',
|
|
197
|
-
'no-extra-boolean-cast': 'error',
|
|
198
|
-
'no-confusing-arrow': 'error',
|
|
199
|
-
'no-case-declarations': 'error',
|
|
200
|
-
'no-bitwise': 'error',
|
|
201
|
-
'no-array-constructor': 'error',
|
|
202
|
-
'no-alert': 'error',
|
|
203
|
-
'logical-assignment-operators': 'error',
|
|
204
|
-
'grouped-accessor-pairs': 'error',
|
|
205
|
-
'func-name-matching': 'error',
|
|
206
|
-
'dot-notation': 'error',
|
|
207
|
-
'consistent-this': ['error', 'self'],
|
|
208
|
-
'accessor-pairs': 'error',
|
|
209
|
-
'no-unused-private-class-members': 'error',
|
|
210
|
-
'no-promise-executor-return': 'error',
|
|
211
|
-
'no-duplicate-imports': 'error',
|
|
212
|
-
'no-constant-binary-expression': 'error',
|
|
213
|
-
'no-undef-init': 'error',
|
|
214
|
-
'no-label-var': 'error',
|
|
215
|
-
'init-declarations': ['error', 'always'],
|
|
216
|
-
'wrap-iife': ['error', 'inside'],
|
|
217
|
-
yoda: 'error',
|
|
218
|
-
'vars-on-top': 'error',
|
|
219
|
-
radix: ['error', 'as-needed'],
|
|
220
|
-
'prefer-regex-literals': 'error',
|
|
221
|
-
'prefer-promise-reject-errors': 'error',
|
|
222
|
-
'promise/catch-or-return': ['error', { terminationMethod: ['catch', 'finally'] }],
|
|
223
|
-
'no-warning-comments': 'error',
|
|
224
|
-
'no-void': 'error',
|
|
225
|
-
'no-useless-return': 'error',
|
|
226
|
-
'no-useless-concat': 'error',
|
|
227
|
-
'no-useless-call': 'error',
|
|
228
|
-
'no-throw-literal': 'error',
|
|
229
|
-
'no-sequences': 'error',
|
|
230
|
-
'no-self-compare': 'error',
|
|
231
|
-
'no-return-assign': 'error',
|
|
232
|
-
'no-proto': 'error',
|
|
233
|
-
'no-octal-escape': 'error',
|
|
234
|
-
'no-nonoctal-decimal-escape': 'error',
|
|
235
|
-
'no-new-wrappers': 'error',
|
|
236
|
-
'no-new-func': 'error',
|
|
237
|
-
'no-new': 'error',
|
|
238
|
-
'no-multi-str': 'error',
|
|
239
|
-
'no-multi-spaces': 'error',
|
|
240
|
-
'no-lone-blocks': 'error',
|
|
241
|
-
'no-labels': 'error',
|
|
242
|
-
'no-iterator': 'error',
|
|
243
|
-
'no-empty-function': 'error',
|
|
244
|
-
'block-scoped-var': 'error',
|
|
245
|
-
'prefer-arrow-callback': 'error',
|
|
246
|
-
'no-implied-eval': 'error',
|
|
247
|
-
'no-implicit-globals': 'error',
|
|
248
|
-
'no-floating-decimal': 'error',
|
|
249
|
-
'no-extra-label': 'error',
|
|
250
|
-
'no-extra-bind': 'error',
|
|
251
|
-
'no-extend-native': [
|
|
252
|
-
'error',
|
|
253
|
-
{
|
|
254
|
-
exceptions: ['Object'],
|
|
255
|
-
},
|
|
256
|
-
],
|
|
257
|
-
'no-eval': 'error',
|
|
258
|
-
'no-constant-condition': ['error', { checkLoops: false }],
|
|
259
|
-
'no-eq-null': 'error',
|
|
260
|
-
'no-else-return': 'error',
|
|
261
|
-
'no-unused-vars': 0,
|
|
262
|
-
'no-console': 0,
|
|
263
|
-
'no-empty': 0,
|
|
264
|
-
'no-redeclare': 0,
|
|
265
|
-
'no-useless-escape': 0,
|
|
266
|
-
'no-var': 'error',
|
|
267
|
-
'object-shorthand': ['error', 'properties'],
|
|
268
|
-
'prefer-template': 'error',
|
|
269
|
-
'no-div-regex': 'error',
|
|
270
|
-
'no-constructor-return': 'error',
|
|
271
|
-
'no-caller': 'error',
|
|
272
|
-
'max-classes-per-file': 'error',
|
|
273
|
-
'default-param-last': 'error',
|
|
274
|
-
'default-case-last': 'error',
|
|
275
|
-
'default-case': 'error',
|
|
276
|
-
'array-callback-return': 'error',
|
|
277
|
-
'no-unsafe-optional-chaining': 'error',
|
|
278
|
-
'no-unreachable-loop': 'error',
|
|
279
|
-
'no-template-curly-in-string': 'error',
|
|
280
|
-
'no-loss-of-precision': 'error',
|
|
281
|
-
'no-inner-declarations': 0,
|
|
282
|
-
'no-process-exit': 0,
|
|
283
|
-
'prefer-const': ['error', { destructuring: 'all' }],
|
|
284
|
-
},
|
|
285
|
-
},
|
|
286
|
-
];
|
package/eslinttest.config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
create(context) {
|
|
3
|
-
return {
|
|
4
|
-
SpreadElement(node) {
|
|
5
|
-
if (node.argument.type === 'ConditionalExpression' || node.argument.type === 'LogicalExpression') {
|
|
6
|
-
context.report({
|
|
7
|
-
node,
|
|
8
|
-
message: 'Conditional object spread is not allowed.',
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
},
|
|
14
|
-
};
|
package/rules/noPathJoin.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
meta: {
|
|
3
|
-
type: 'suggestion',
|
|
4
|
-
docs: {
|
|
5
|
-
description: 'Disallow path.join() in favor of template strings',
|
|
6
|
-
category: 'Stylistic Issues',
|
|
7
|
-
recommended: true,
|
|
8
|
-
},
|
|
9
|
-
fixable: 'code',
|
|
10
|
-
schema: [],
|
|
11
|
-
},
|
|
12
|
-
create(context) {
|
|
13
|
-
return {
|
|
14
|
-
CallExpression(node) {
|
|
15
|
-
if (
|
|
16
|
-
node.callee.type === 'MemberExpression' &&
|
|
17
|
-
node.callee.object.name === 'path' &&
|
|
18
|
-
node.callee.property.name === 'join' &&
|
|
19
|
-
node.arguments.length >= 2
|
|
20
|
-
) {
|
|
21
|
-
const sourceCode = context.sourceCode ?? context.getSourceCode();
|
|
22
|
-
|
|
23
|
-
const parts = node.arguments.map((arg) => {
|
|
24
|
-
if (arg.type === 'Literal' && typeof arg.value === 'string') {
|
|
25
|
-
return arg.value;
|
|
26
|
-
}
|
|
27
|
-
return `\${${sourceCode.getText(arg)}}`;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const replacement = `\`${parts.join('/')}\``;
|
|
31
|
-
|
|
32
|
-
context.report({
|
|
33
|
-
node,
|
|
34
|
-
message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples',
|
|
35
|
-
fix(fixer) {
|
|
36
|
-
return fixer.replaceText(node, replacement);
|
|
37
|
-
},
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
},
|
|
43
|
-
};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { RuleTester } from 'eslint';
|
|
2
|
-
import noConditionalObjectSpread from '../rules/noConditionalObjectSpread.js';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
|
|
7
|
-
const ruleTester = new RuleTester({
|
|
8
|
-
languageOptions: {
|
|
9
|
-
parser: await import('@babel/eslint-parser'),
|
|
10
|
-
ecmaVersion: 'latest',
|
|
11
|
-
sourceType: 'module',
|
|
12
|
-
parserOptions: {
|
|
13
|
-
requireConfigFile: false,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
ruleTester.run('no-conditional-object-spread', noConditionalObjectSpread, {
|
|
19
|
-
valid: [
|
|
20
|
-
{
|
|
21
|
-
code: `
|
|
22
|
-
const condition = true;
|
|
23
|
-
const obj = {};
|
|
24
|
-
if (condition) obj.prop = value;
|
|
25
|
-
`,
|
|
26
|
-
},
|
|
27
|
-
],
|
|
28
|
-
invalid: [
|
|
29
|
-
{
|
|
30
|
-
code: `
|
|
31
|
-
const obj = {
|
|
32
|
-
...(condition ? { prop: 'value' } : {}),
|
|
33
|
-
};
|
|
34
|
-
`,
|
|
35
|
-
errors: [{ message: 'Conditional object spread is not allowed.' }],
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
code: `
|
|
39
|
-
const obj = {
|
|
40
|
-
...(condition && { prop: 'value' }),
|
|
41
|
-
};
|
|
42
|
-
`,
|
|
43
|
-
errors: [{ message: 'Conditional object spread is not allowed.' }],
|
|
44
|
-
},
|
|
45
|
-
],
|
|
46
|
-
});
|
package/test/noPathJoin.test.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { RuleTester } from 'eslint';
|
|
2
|
-
import noPathJoin from '../rules/noPathJoin.js';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { fileURLToPath } from 'node:url';
|
|
5
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
-
|
|
7
|
-
const ruleTester = new RuleTester({
|
|
8
|
-
languageOptions: {
|
|
9
|
-
parser: await import('@babel/eslint-parser'),
|
|
10
|
-
ecmaVersion: 'latest',
|
|
11
|
-
sourceType: 'module',
|
|
12
|
-
parserOptions: {
|
|
13
|
-
requireConfigFile: false,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
ruleTester.run('no-path-join', noPathJoin, {
|
|
19
|
-
valid: [
|
|
20
|
-
{
|
|
21
|
-
code: `
|
|
22
|
-
const filePath = \`\${directory}/\${filename}\`;
|
|
23
|
-
`,
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
// Cas avec un seul argument (non concerné)
|
|
27
|
-
code: `
|
|
28
|
-
const filePath = path.join(directory);
|
|
29
|
-
`,
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
// Cas avec un autre objet que path
|
|
33
|
-
code: `
|
|
34
|
-
const result = utils.join(a, b);
|
|
35
|
-
`,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
invalid: [
|
|
39
|
-
{
|
|
40
|
-
code: `
|
|
41
|
-
const filePath = path.join(directory, filename);
|
|
42
|
-
`,
|
|
43
|
-
errors: [{ message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples' }],
|
|
44
|
-
output: `
|
|
45
|
-
const filePath = \`\${directory}/\${filename}\`;
|
|
46
|
-
`,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
code: `
|
|
50
|
-
const filePath = path.join(process.cwd(), 'file.txt');
|
|
51
|
-
`,
|
|
52
|
-
errors: [{ message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples' }],
|
|
53
|
-
output: `
|
|
54
|
-
const filePath = \`\${process.cwd()}/file.txt\`;
|
|
55
|
-
`,
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
// 3 arguments
|
|
59
|
-
code: `
|
|
60
|
-
const filePath = path.join(root, directory, filename);
|
|
61
|
-
`,
|
|
62
|
-
errors: [{ message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples' }],
|
|
63
|
-
output: `
|
|
64
|
-
const filePath = \`\${root}/\${directory}/\${filename}\`;
|
|
65
|
-
`,
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
// Mix variables et littéraux
|
|
69
|
-
code: `
|
|
70
|
-
const filePath = path.join(root, 'uploads', filename);
|
|
71
|
-
`,
|
|
72
|
-
errors: [{ message: 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples' }],
|
|
73
|
-
output: `
|
|
74
|
-
const filePath = \`\${root}/uploads/\${filename}\`;
|
|
75
|
-
`,
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
});
|
package/todo.txt
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
REVIEW DE CODE — 2026-04-26
|
|
2
|
-
============================================
|
|
3
|
-
|
|
4
|
-
Plugin ESLint custom maison. Expose 2 regles :
|
|
5
|
-
- `no-conditional-object-spread` : interdit `{...(cond ? {x:1} : {})}`
|
|
6
|
-
et `{...(cond && {x:1})}`
|
|
7
|
-
- `no-path-join` : interdit `path.join(a, b)` au profit de
|
|
8
|
-
`\`${a}/${b}\`` (avec autofix).
|
|
9
|
-
|
|
10
|
-
13+43 lignes de code metier dans rules/, 124 lignes de tests, 53
|
|
11
|
-
lignes (dont 42 commentees) dans index.js.
|
|
12
|
-
|
|
13
|
-
BUGS / FRAGILITE
|
|
14
|
-
----------------
|
|
15
|
-
[ ] index.js : 42 lignes commentees (CRITIQUE de lisibilite)
|
|
16
|
-
index.js:11-53 : tout un bloc commente avec une version
|
|
17
|
-
"améliorée" du plugin (avec `meta.name`, `meta.version`,
|
|
18
|
-
`configs.flat/recommended`). C'est probablement la version
|
|
19
|
-
"qui marche" sur ESLint 9 flat config, mais elle est commentee.
|
|
20
|
-
L'export actuel (lignes 1-9) est minimal et ne suit pas la
|
|
21
|
-
convention ESLint `meta` (manque name/version). Si ESLint
|
|
22
|
-
detecte le plugin sans meta, certains checks (cache, dedup)
|
|
23
|
-
sont degrades.
|
|
24
|
-
A clarifier : soit reactiver le bloc commente (et garder une
|
|
25
|
-
seule version), soit delete le bloc inutile.
|
|
26
|
-
|
|
27
|
-
[ ] noPathJoin : autofix n'introduit pas de slash safe
|
|
28
|
-
rules/noPathJoin.js:25-27 : `parts.join('/')`. Si l'argument
|
|
29
|
-
est `path.join(__dirname, '..', 'file.js')`, le fix produit
|
|
30
|
-
`\`${__dirname}/../file.js\``. OK.
|
|
31
|
-
Mais si l'argument contient un slash final/début, doublon :
|
|
32
|
-
`path.join('a/', 'b')` => `\`a//b\`` (autofix incorrect).
|
|
33
|
-
Path.join normalise les slashs, le fix non. Edge case rare
|
|
34
|
-
mais reel.
|
|
35
|
-
|
|
36
|
-
[ ] noPathJoin : detection MemberExpression chain
|
|
37
|
-
rules/noPathJoin.js:13 : `node.callee.object.name === 'path'`.
|
|
38
|
-
Si import `import { join } from 'node:path'` et utilise
|
|
39
|
-
`join(a, b)`, pas detecte (pas de `path.join`). Fragmentation
|
|
40
|
-
incomplete.
|
|
41
|
-
|
|
42
|
-
[ ] noPathJoin : detection seulement "path.join(>=2 args)"
|
|
43
|
-
rules/noPathJoin.js:14 : `node.arguments.length >= 2`. Si
|
|
44
|
-
`path.join(a)` (1 seul arg), pas declenche. Mais `path.join
|
|
45
|
-
(a)` est en pratique inutile (path.join('foo') === 'foo'),
|
|
46
|
-
une regle pourrait suggerer de retirer l'appel.
|
|
47
|
-
|
|
48
|
-
[ ] noPathJoin : pas de skip pour les cas corrects
|
|
49
|
-
Si l'utilisateur a deliberement choisi `path.join` pour la
|
|
50
|
-
portabilité Windows (`\\` vs `/`), le fix le casse.
|
|
51
|
-
Convention de la stack : tout est sur Linux donc OK, mais
|
|
52
|
-
a documenter (cf README).
|
|
53
|
-
|
|
54
|
-
[ ] noConditionalObjectSpread : detection trop large
|
|
55
|
-
rules/noConditionalObjectSpread.js:5 : `node.argument.type
|
|
56
|
-
=== 'ConditionalExpression' || 'LogicalExpression'`.
|
|
57
|
-
Detecte aussi :
|
|
58
|
-
const obj = { ...(a || b) };
|
|
59
|
-
qui est un usage VALIDE (a est preferable, sinon b). Faux
|
|
60
|
-
positif. A affiner : check si une des branches est `{}` ou
|
|
61
|
-
null/undefined.
|
|
62
|
-
|
|
63
|
-
[ ] noConditionalObjectSpread : pas d'autofix
|
|
64
|
-
Pas `fixable: 'code'`. Le user doit refactor a la main. Bon
|
|
65
|
-
point puisque le refactor change la semantique (variable de
|
|
66
|
-
sortie modifiee), mais le message d'erreur ne propose pas
|
|
67
|
-
d'alternative claire.
|
|
68
|
-
|
|
69
|
-
[ ] noConditionalObjectSpread : pas de meta
|
|
70
|
-
rules/noConditionalObjectSpread.js : pas de `meta` block.
|
|
71
|
-
Manque `meta.docs.description`, `meta.type`, etc. ESLint
|
|
72
|
-
plant pas, mais best practice.
|
|
73
|
-
|
|
74
|
-
CODE MORT / POLLUTION
|
|
75
|
-
---------------------
|
|
76
|
-
[ ] assets/testExample.js
|
|
77
|
-
Fichier de test manuel. OK pour la documentation.
|
|
78
|
-
|
|
79
|
-
[ ] TESTING.md
|
|
80
|
-
Documentation manuelle separee. A consolider dans README.md.
|
|
81
|
-
|
|
82
|
-
CONVENTIONS
|
|
83
|
-
-----------
|
|
84
|
-
[ ] Mauvaise pratique : meta block manquant sur noConditionalObjectSpread
|
|
85
|
-
Cf bugs.
|
|
86
|
-
|
|
87
|
-
[ ] Pas de versioning des rules
|
|
88
|
-
1.4.0 mais pas de breaking change tracking. Si on rend la
|
|
89
|
-
detection plus stricte, casse les CI des consommateurs.
|
|
90
|
-
|
|
91
|
-
DECISION SUGGEREE
|
|
92
|
-
-----------------
|
|
93
|
-
[ ] Trancher index.js : la version commentee semble plus complete.
|
|
94
|
-
Migrer vers la version commentee (avec meta + configs/flat/
|
|
95
|
-
recommended), tester sur 2-3 projets consommateurs, release
|
|
96
|
-
1.5.0.
|