@activatus/code-standards 3.0.1 → 3.0.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.
@@ -7,6 +7,45 @@ import unicorn from "eslint-plugin-unicorn";
7
7
  import globals from "globals";
8
8
  import { configs as typescript } from "typescript-eslint";
9
9
 
10
+ // Code patterns that are errors in every file.
11
+ const RESTRICTED_SYNTAX = [
12
+ {
13
+ selector: "ClassDeclaration",
14
+ message: "Use functions, not classes.",
15
+ },
16
+ {
17
+ selector: "ClassExpression",
18
+ message: "Use functions, not classes.",
19
+ },
20
+ {
21
+ selector: "VariableDeclarator > FunctionExpression",
22
+ message: "Use an arrow function.",
23
+ },
24
+ {
25
+ selector: "VariableDeclaration[kind='let']",
26
+ message:
27
+ "Use const. If this value really must be reassigned, disable this rule on this line with a comment saying why.",
28
+ },
29
+ {
30
+ selector: "FunctionDeclaration[params.length>1]",
31
+ message:
32
+ "Use a single object parameter when a function needs more than one value.",
33
+ },
34
+ {
35
+ selector:
36
+ "VariableDeclarator > :matches(ArrowFunctionExpression, FunctionExpression)[params.length>1]",
37
+ message:
38
+ "Use a single object parameter when a function needs more than one value.",
39
+ },
40
+ ];
41
+
42
+ // Type a value where it is declared. Story files are the exception: see below.
43
+ const NO_SATISFIES = {
44
+ selector: "TSSatisfiesExpression",
45
+ message:
46
+ "Type a value where it is declared, not with satisfies afterwards.",
47
+ };
48
+
10
49
  export default [
11
50
  { ignores: ["dist/", "build/", "coverage/", "**/vendor/**"] },
12
51
  js.configs.recommended,
@@ -44,34 +83,8 @@ export default [
44
83
  ],
45
84
  "no-restricted-syntax": [
46
85
  "error",
47
- {
48
- selector: "ClassDeclaration",
49
- message: "Use functions, not classes.",
50
- },
51
- {
52
- selector: "ClassExpression",
53
- message: "Use functions, not classes.",
54
- },
55
- {
56
- selector: "VariableDeclarator > FunctionExpression",
57
- message: "Use an arrow function.",
58
- },
59
- {
60
- selector: "VariableDeclaration[kind='let']",
61
- message:
62
- "Use const. If this value really must be reassigned, disable this rule on this line with a comment saying why.",
63
- },
64
- {
65
- selector: "FunctionDeclaration[params.length>1]",
66
- message:
67
- "Use a single object parameter when a function needs more than one value.",
68
- },
69
- {
70
- selector:
71
- "VariableDeclarator > :matches(ArrowFunctionExpression, FunctionExpression)[params.length>1]",
72
- message:
73
- "Use a single object parameter when a function needs more than one value.",
74
- },
86
+ NO_SATISFIES,
87
+ ...RESTRICTED_SYNTAX,
75
88
  ],
76
89
  "import-x/no-cycle": "error",
77
90
  "import-x/no-default-export": "error",
@@ -150,5 +163,12 @@ export default [
150
163
  files: ["**/*.config.{js,mjs,ts}"],
151
164
  rules: { "unicorn/no-top-level-side-effects": "off" },
152
165
  },
166
+ {
167
+ // Storybook's own docs type stories with `satisfies Meta<typeof Component>`, so story files may use it.
168
+ files: ["**/*.stories.{ts,tsx}"],
169
+ rules: {
170
+ "no-restricted-syntax": ["error", ...RESTRICTED_SYNTAX],
171
+ },
172
+ },
153
173
  prettier,
154
174
  ];