eslint-plugin-raflint 1.5.2 → 1.5.4

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/README.md CHANGED
@@ -20,9 +20,20 @@ qui devrait être écrites comme ça:
20
20
  const obj = {};
21
21
  if (condition) obj.prop = value;
22
22
 
23
+ La règle couvre aussi le spread conditionnel dans un **tableau** ou un appel, malgré son nom —
24
+ ne pas la restreindre au parent `ObjectExpression` :
25
+
26
+ const args = [target, ...(Array.isArray(command) ? command : [command])];
27
+
28
+ qui devrait être écrit comme ça:
29
+
30
+ const argv = Array.isArray(command) ? command : [command];
31
+ const args = [target, ...argv];
32
+
23
33
  ## no-path-join
24
34
 
25
- Les utilisations de `path.join()` avec deux arguments qui peuvent être remplacées par des template strings:
35
+ Les utilisations de `path.join()` avec au moins deux arguments, remplacées par des template strings
36
+ (`fixable`, donc réécrites par `eslint --fix`) :
26
37
 
27
38
  const filePath = path.join(directory, filename);
28
39
 
@@ -30,7 +41,10 @@ qui devrait être écrites comme ça:
30
41
 
31
42
  const filePath = `${directory}/${filename}`;
32
43
 
33
- # tester le plugin sur un projet
44
+ Le fix est laissé de côté quand il casserait l'appel : accès calculé (`path[join](a, b)`) et
45
+ argument spread (`path.join(root, ...parts)`), qui n'est pas interpolable.
46
+
47
+ ## tester le plugin sur un projet
34
48
 
35
49
  on peut se mettre dans le dossier ou on veut utiliser le plugin pui lancer :
36
50
 
@@ -1,13 +1,21 @@
1
+ const MESSAGE = 'Conditional object spread is not allowed.';
1
2
  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
- }
3
+ meta: {
4
+ type: 'suggestion',
5
+ docs: {
6
+ description: 'Disallow conditional object spread (`...(cond ? a : b)` / `...(cond && a)`) in favor of explicit branching',
7
+ recommended: true,
10
8
  },
11
- }),
9
+ schema: [],
10
+ },
11
+ create(context) {
12
+ return {
13
+ SpreadElement(node) {
14
+ if (node.argument.type === 'ConditionalExpression' || node.argument.type === 'LogicalExpression') {
15
+ context.report({ node, message: MESSAGE });
16
+ }
17
+ },
18
+ };
19
+ },
12
20
  };
13
21
  export default rule;
@@ -1,6 +1,11 @@
1
1
  // Le backslash doit etre echappe en premier, sinon il redouble ceux ajoutes ensuite.
2
2
  const escapeTemplateLiteral = (value) => value.replaceAll('\\', '\\\\').replaceAll('`', '\\`').replaceAll('${', '\\${');
3
3
  const MESSAGE = 'Utilisez des template strings au lieu de path.join() pour la concaténation de chemins simples';
4
+ const isPathJoinCall = (node) => node.callee.type === 'MemberExpression' &&
5
+ !node.callee.computed &&
6
+ node.callee.object.name === 'path' &&
7
+ node.callee.property.name === 'join' &&
8
+ node.arguments.length >= 2;
4
9
  const rule = {
5
10
  meta: {
6
11
  type: 'suggestion',
@@ -14,10 +19,7 @@ const rule = {
14
19
  create(context) {
15
20
  return {
16
21
  CallExpression(node) {
17
- if (!(node.callee.type === 'MemberExpression' &&
18
- node.callee.object.name === 'path' &&
19
- node.callee.property.name === 'join' &&
20
- node.arguments.length >= 2)) {
22
+ if (!isPathJoinCall(node)) {
21
23
  return;
22
24
  }
23
25
  // Un spread ne peut pas être interpolé (`${...parts}` est une erreur de syntaxe) : on signale sans corriger.
@@ -25,12 +27,11 @@ const rule = {
25
27
  context.report({ node, message: MESSAGE });
26
28
  return;
27
29
  }
28
- const sourceCode = context.sourceCode ?? context.getSourceCode();
29
30
  const parts = node.arguments.map((argument) => {
30
31
  if (argument.type === 'Literal' && typeof argument.value === 'string') {
31
32
  return escapeTemplateLiteral(argument.value);
32
33
  }
33
- return `\${${sourceCode.getText(argument)}}`;
34
+ return `\${${context.sourceCode.getText(argument)}}`;
34
35
  });
35
36
  const replacement = `\`${parts.join('/')}\``;
36
37
  context.report({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-raflint",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [],
@@ -26,30 +26,31 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@babel/eslint-parser": "^8.0.1",
29
- "eslint-plugin-n": "^18.2.2",
29
+ "eslint-plugin-n": "^18.3.0",
30
30
  "eslint-plugin-sonarjs": "^4.2.0",
31
- "eslint-plugin-unicorn": "^72.0.0"
31
+ "eslint-plugin-unicorn": "^74.0.0"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@eslint/js": "^10.0.1",
35
- "@stoplight/spectral-cli": "^6.16.2",
35
+ "@stoplight/spectral-cli": "^6.16.3",
36
36
  "c8": "^12.0.0",
37
37
  "eslint": "^10.5.0",
38
+ "eslint-config-prettier": "^10.1.8",
38
39
  "eslint-import-resolver-typescript": "^4.4.5",
39
40
  "eslint-plugin-import-x": "^4.17.1",
40
41
  "eslint-plugin-promise": "^7.3.0",
41
- "eslint-plugin-raflint": "^1.5.1",
42
+ "eslint-plugin-raflint": "^1.5.2",
42
43
  "eslint-plugin-react-hooks": "^7.1.1",
43
- "globals": "^17.8.0",
44
+ "globals": "^17.11.0",
44
45
  "husky": "^9.1.7",
45
- "lint-staged": "^17.2.0",
46
+ "lint-staged": "^17.4.1",
46
47
  "markdownlint": "^0.41.1",
47
- "mocha": "^11.7.6",
48
+ "mocha": "^11.8.0",
48
49
  "prettier": "^3.9.6",
49
50
  "ts-api-utils": "^2.5.0",
50
- "tsx": "^4.23.1",
51
+ "tsx": "^4.23.13",
51
52
  "typescript": "^6.0.3",
52
- "typescript-eslint": "^8.65.0"
53
+ "typescript-eslint": "^8.68.0"
53
54
  },
54
55
  "engines": {
55
56
  "node": ">=21.0.0"