@croct/eslint-plugin 0.2.3 → 0.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.
@@ -19,6 +19,7 @@ export declare const configs: {
19
19
  '@croct/jsx-attribute-spacing': string;
20
20
  'react/jsx-wrap-multilines': string;
21
21
  'react/display-name': string;
22
+ 'jsx-quotes': string[];
22
23
  'react/jsx-newline': (string | {
23
24
  prevent: boolean;
24
25
  })[];
@@ -74,12 +75,6 @@ export declare const configs: {
74
75
  };
75
76
  })[];
76
77
  };
77
- overrides: {
78
- files: string[];
79
- rules: {
80
- 'sort-keys-fix/sort-keys-fix': string;
81
- };
82
- }[];
83
78
  };
84
79
  typescript: {
85
80
  extends: string[];
@@ -89,6 +84,7 @@ export declare const configs: {
89
84
  extends: string[];
90
85
  parser: string;
91
86
  rules: {
87
+ 'import/export': string;
92
88
  '@typescript-eslint/array-type': (string | {
93
89
  default: string;
94
90
  })[];
@@ -149,9 +145,6 @@ export declare const configs: {
149
145
  })[];
150
146
  'no-undef': string;
151
147
  '@typescript-eslint/no-namespace': string;
152
- '@typescript-eslint/no-redeclare': (string | {
153
- ignoreDeclarationMerge: boolean;
154
- })[];
155
148
  'no-new-object'?: undefined;
156
149
  };
157
150
  plugins?: undefined;
@@ -162,6 +155,7 @@ export declare const configs: {
162
155
  plugins: string[];
163
156
  rules: {
164
157
  'no-new-object': string;
158
+ 'import/export'?: undefined;
165
159
  '@typescript-eslint/array-type'?: undefined;
166
160
  '@typescript-eslint/prefer-as-const'?: undefined;
167
161
  '@typescript-eslint/adjacent-overload-signatures'?: undefined;
@@ -189,7 +183,6 @@ export declare const configs: {
189
183
  '@typescript-eslint/member-delimiter-style'?: undefined;
190
184
  'no-undef'?: undefined;
191
185
  '@typescript-eslint/no-namespace'?: undefined;
192
- '@typescript-eslint/no-redeclare'?: undefined;
193
186
  };
194
187
  env: {
195
188
  jest: boolean;
@@ -205,6 +198,7 @@ export declare const configs: {
205
198
  '@croct/complex-expression-spacing': string;
206
199
  '@croct/newline-per-chained-call': string;
207
200
  '@croct/min-chained-call-depth': string;
201
+ '@croct/parameter-destructuring': string;
208
202
  'eslint-comments/disable-enable-pair': (string | {
209
203
  allowWholeFile: boolean;
210
204
  })[];
@@ -298,6 +292,11 @@ export declare const configs: {
298
292
  next: string;
299
293
  })[];
300
294
  'no-useless-escape': string;
295
+ 'newline-destructuring/newline': (string | {
296
+ maxLength: number;
297
+ itemsWithRest: number;
298
+ items: number;
299
+ })[];
301
300
  };
302
301
  overrides: {
303
302
  files: string[];
@@ -6,6 +6,7 @@ export declare const javascript: {
6
6
  '@croct/complex-expression-spacing': string;
7
7
  '@croct/newline-per-chained-call': string;
8
8
  '@croct/min-chained-call-depth': string;
9
+ '@croct/parameter-destructuring': string;
9
10
  'eslint-comments/disable-enable-pair': (string | {
10
11
  allowWholeFile: boolean;
11
12
  })[];
@@ -99,6 +100,11 @@ export declare const javascript: {
99
100
  next: string;
100
101
  })[];
101
102
  'no-useless-escape': string;
103
+ 'newline-destructuring/newline': (string | {
104
+ maxLength: number;
105
+ itemsWithRest: number;
106
+ items: number;
107
+ })[];
102
108
  };
103
109
  overrides: {
104
110
  files: string[];
@@ -12,6 +12,7 @@ exports.javascript = {
12
12
  'import',
13
13
  'no-smart-quotes',
14
14
  'import-newlines',
15
+ 'newline-destructuring',
15
16
  '@croct',
16
17
  ],
17
18
  rules: {
@@ -19,6 +20,7 @@ exports.javascript = {
19
20
  '@croct/complex-expression-spacing': 'error',
20
21
  '@croct/newline-per-chained-call': 'error',
21
22
  '@croct/min-chained-call-depth': 'error',
23
+ '@croct/parameter-destructuring': 'error',
22
24
  'eslint-comments/disable-enable-pair': [
23
25
  'error',
24
26
  {
@@ -214,6 +216,14 @@ exports.javascript = {
214
216
  },
215
217
  ],
216
218
  'no-useless-escape': 'error',
219
+ 'newline-destructuring/newline': [
220
+ 'error',
221
+ {
222
+ maxLength: 100,
223
+ itemsWithRest: Infinity,
224
+ items: Infinity,
225
+ },
226
+ ],
217
227
  },
218
228
  overrides: [
219
229
  {
@@ -5,6 +5,7 @@ export declare const react: {
5
5
  '@croct/jsx-attribute-spacing': string;
6
6
  'react/jsx-wrap-multilines': string;
7
7
  'react/display-name': string;
8
+ 'jsx-quotes': string[];
8
9
  'react/jsx-newline': (string | {
9
10
  prevent: boolean;
10
11
  })[];
@@ -60,10 +61,4 @@ export declare const react: {
60
61
  };
61
62
  })[];
62
63
  };
63
- overrides: {
64
- files: string[];
65
- rules: {
66
- 'sort-keys-fix/sort-keys-fix': string;
67
- };
68
- }[];
69
64
  };
package/configs/react.js CHANGED
@@ -17,12 +17,15 @@ exports.react = {
17
17
  'testing-library',
18
18
  'jest-dom',
19
19
  '@croct',
20
- 'sort-keys-fix',
21
20
  ],
22
21
  rules: {
23
22
  '@croct/jsx-attribute-spacing': 'error',
24
23
  'react/jsx-wrap-multilines': 'error',
25
24
  'react/display-name': 'off',
25
+ 'jsx-quotes': [
26
+ 'error',
27
+ 'prefer-double',
28
+ ],
26
29
  'react/jsx-newline': [
27
30
  'error',
28
31
  {
@@ -121,12 +124,4 @@ exports.react = {
121
124
  },
122
125
  ],
123
126
  },
124
- overrides: [
125
- {
126
- files: ['**/styles.ts'],
127
- rules: {
128
- 'sort-keys-fix/sort-keys-fix': 'error',
129
- },
130
- },
131
- ],
132
127
  };
@@ -6,6 +6,7 @@ export declare const typescript: {
6
6
  extends: string[];
7
7
  parser: string;
8
8
  rules: {
9
+ 'import/export': string;
9
10
  '@typescript-eslint/array-type': (string | {
10
11
  default: string;
11
12
  })[];
@@ -66,9 +67,6 @@ export declare const typescript: {
66
67
  })[];
67
68
  'no-undef': string;
68
69
  '@typescript-eslint/no-namespace': string;
69
- '@typescript-eslint/no-redeclare': (string | {
70
- ignoreDeclarationMerge: boolean;
71
- })[];
72
70
  'no-new-object'?: undefined;
73
71
  };
74
72
  plugins?: undefined;
@@ -79,6 +77,7 @@ export declare const typescript: {
79
77
  plugins: string[];
80
78
  rules: {
81
79
  'no-new-object': string;
80
+ 'import/export'?: undefined;
82
81
  '@typescript-eslint/array-type'?: undefined;
83
82
  '@typescript-eslint/prefer-as-const'?: undefined;
84
83
  '@typescript-eslint/adjacent-overload-signatures'?: undefined;
@@ -106,7 +105,6 @@ export declare const typescript: {
106
105
  '@typescript-eslint/member-delimiter-style'?: undefined;
107
106
  'no-undef'?: undefined;
108
107
  '@typescript-eslint/no-namespace'?: undefined;
109
- '@typescript-eslint/no-redeclare'?: undefined;
110
108
  };
111
109
  env: {
112
110
  jest: boolean;
@@ -13,6 +13,7 @@ exports.typescript = {
13
13
  extends: ['plugin:@typescript-eslint/recommended'],
14
14
  parser: '@typescript-eslint/parser',
15
15
  rules: {
16
+ 'import/export': 'off',
16
17
  '@typescript-eslint/array-type': ['error', {
17
18
  default: 'array-simple',
18
19
  }],
@@ -78,9 +79,6 @@ exports.typescript = {
78
79
  }],
79
80
  'no-undef': 'off',
80
81
  '@typescript-eslint/no-namespace': 'off',
81
- '@typescript-eslint/no-redeclare': ['error', {
82
- ignoreDeclarationMerge: true,
83
- }],
84
82
  },
85
83
  },
86
84
  {
package/index.d.ts CHANGED
@@ -1,27 +1,30 @@
1
1
  declare const configuration: {
2
2
  rules: {
3
3
  'argument-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
4
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression | import("@typescript-eslint/types/dist/ast-spec").NewExpression) => void;
5
- NewExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression | import("@typescript-eslint/types/dist/ast-spec").NewExpression) => void;
4
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression | import("@typescript-eslint/types/dist/generated/ast-spec").NewExpression) => void;
5
+ NewExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression | import("@typescript-eslint/types/dist/generated/ast-spec").NewExpression) => void;
6
6
  }>;
7
7
  'jsx-attribute-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
8
- JSXAttribute: (node: import("@typescript-eslint/types/dist/ast-spec").JSXAttribute) => void;
8
+ JSXAttribute: (node: import("@typescript-eslint/types/dist/generated/ast-spec").JSXAttribute) => void;
9
9
  }>;
10
10
  'complex-expression-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
11
- ArrowFunctionExpression: (node: import("@typescript-eslint/types/dist/ast-spec").ArrowFunctionExpression) => void;
12
- IfStatement: (node: import("@typescript-eslint/types/dist/ast-spec").IfStatement) => void;
11
+ ArrowFunctionExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").ArrowFunctionExpression) => void;
12
+ IfStatement: (node: import("@typescript-eslint/types/dist/generated/ast-spec").IfStatement) => void;
13
13
  }>;
14
14
  'newline-per-chained-call': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
15
15
  ignoreChainWithDepth: number;
16
16
  }[], {
17
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
18
- MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
17
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
18
+ MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
19
19
  }>;
20
20
  'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
21
21
  maxLineLength: number;
22
22
  }[], {
23
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
24
- MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
23
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
24
+ MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
25
+ }>;
26
+ 'parameter-destructuring': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedDestructuring", never[], {
27
+ ObjectPattern: (node: import("@typescript-eslint/types/dist/generated/ast-spec").ObjectPattern) => void;
25
28
  }>;
26
29
  };
27
30
  configs: {
@@ -45,6 +48,7 @@ declare const configuration: {
45
48
  '@croct/jsx-attribute-spacing': string;
46
49
  'react/jsx-wrap-multilines': string;
47
50
  'react/display-name': string;
51
+ 'jsx-quotes': string[];
48
52
  'react/jsx-newline': (string | {
49
53
  prevent: boolean;
50
54
  })[];
@@ -100,12 +104,6 @@ declare const configuration: {
100
104
  };
101
105
  })[];
102
106
  };
103
- overrides: {
104
- files: string[];
105
- rules: {
106
- 'sort-keys-fix/sort-keys-fix': string;
107
- };
108
- }[];
109
107
  };
110
108
  typescript: {
111
109
  extends: string[];
@@ -115,6 +113,7 @@ declare const configuration: {
115
113
  extends: string[];
116
114
  parser: string;
117
115
  rules: {
116
+ 'import/export': string;
118
117
  '@typescript-eslint/array-type': (string | {
119
118
  default: string;
120
119
  })[];
@@ -175,9 +174,6 @@ declare const configuration: {
175
174
  })[];
176
175
  'no-undef': string;
177
176
  '@typescript-eslint/no-namespace': string;
178
- '@typescript-eslint/no-redeclare': (string | {
179
- ignoreDeclarationMerge: boolean;
180
- })[];
181
177
  'no-new-object'?: undefined;
182
178
  };
183
179
  plugins?: undefined;
@@ -188,6 +184,7 @@ declare const configuration: {
188
184
  plugins: string[];
189
185
  rules: {
190
186
  'no-new-object': string;
187
+ 'import/export'?: undefined;
191
188
  '@typescript-eslint/array-type'?: undefined;
192
189
  '@typescript-eslint/prefer-as-const'?: undefined;
193
190
  '@typescript-eslint/adjacent-overload-signatures'?: undefined;
@@ -215,7 +212,6 @@ declare const configuration: {
215
212
  '@typescript-eslint/member-delimiter-style'?: undefined;
216
213
  'no-undef'?: undefined;
217
214
  '@typescript-eslint/no-namespace'?: undefined;
218
- '@typescript-eslint/no-redeclare'?: undefined;
219
215
  };
220
216
  env: {
221
217
  jest: boolean;
@@ -231,6 +227,7 @@ declare const configuration: {
231
227
  '@croct/complex-expression-spacing': string;
232
228
  '@croct/newline-per-chained-call': string;
233
229
  '@croct/min-chained-call-depth': string;
230
+ '@croct/parameter-destructuring': string;
234
231
  'eslint-comments/disable-enable-pair': (string | {
235
232
  allowWholeFile: boolean;
236
233
  })[];
@@ -324,6 +321,11 @@ declare const configuration: {
324
321
  next: string;
325
322
  })[];
326
323
  'no-useless-escape': string;
324
+ 'newline-destructuring/newline': (string | {
325
+ maxLength: number;
326
+ itemsWithRest: number;
327
+ items: number;
328
+ })[];
327
329
  };
328
330
  overrides: {
329
331
  files: string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/eslint-plugin",
3
- "version": "0.2.3",
3
+ "version": "0.5.0",
4
4
  "description": "ESLint rules and presets applied to all Croct JavaScript projects.",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -48,6 +48,7 @@
48
48
  "eslint-plugin-jest": "^26.1",
49
49
  "eslint-plugin-jest-dom": "^4.0",
50
50
  "eslint-plugin-jsx-a11y": "^6.5",
51
+ "eslint-plugin-newline-destructuring": "^1.0.1",
51
52
  "eslint-plugin-no-smart-quotes": "^1.3",
52
53
  "eslint-plugin-react": "^7.28",
53
54
  "eslint-plugin-react-hooks": "^4.3",
@@ -62,7 +63,6 @@
62
63
  "eslint": "^8.8",
63
64
  "eslint-plugin-eslint-plugin": "^4.1.0",
64
65
  "eslint-plugin-self": "^1.2.1",
65
- "eslint-plugin-sort-keys-fix": "^1.1.2",
66
66
  "jest": "^27.5",
67
67
  "ts-jest": "^27.1",
68
68
  "typescript": "^4.5"
package/rules/index.d.ts CHANGED
@@ -1,25 +1,28 @@
1
1
  export declare const rules: {
2
2
  'argument-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
3
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression | import("@typescript-eslint/types/dist/ast-spec").NewExpression) => void;
4
- NewExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression | import("@typescript-eslint/types/dist/ast-spec").NewExpression) => void;
3
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression | import("@typescript-eslint/types/dist/generated/ast-spec").NewExpression) => void;
4
+ NewExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression | import("@typescript-eslint/types/dist/generated/ast-spec").NewExpression) => void;
5
5
  }>;
6
6
  'jsx-attribute-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
7
- JSXAttribute: (node: import("@typescript-eslint/types/dist/ast-spec").JSXAttribute) => void;
7
+ JSXAttribute: (node: import("@typescript-eslint/types/dist/generated/ast-spec").JSXAttribute) => void;
8
8
  }>;
9
9
  'complex-expression-spacing': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"missing", never[], {
10
- ArrowFunctionExpression: (node: import("@typescript-eslint/types/dist/ast-spec").ArrowFunctionExpression) => void;
11
- IfStatement: (node: import("@typescript-eslint/types/dist/ast-spec").IfStatement) => void;
10
+ ArrowFunctionExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").ArrowFunctionExpression) => void;
11
+ IfStatement: (node: import("@typescript-eslint/types/dist/generated/ast-spec").IfStatement) => void;
12
12
  }>;
13
13
  'newline-per-chained-call': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
14
14
  ignoreChainWithDepth: number;
15
15
  }[], {
16
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
17
- MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
16
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
17
+ MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
18
18
  }>;
19
19
  'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
20
20
  maxLineLength: number;
21
21
  }[], {
22
- CallExpression: (node: import("@typescript-eslint/types/dist/ast-spec").CallExpression) => void;
23
- MemberExpression: (node: import("@typescript-eslint/types/dist/ast-spec").MemberExpression) => void;
22
+ CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
23
+ MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
24
+ }>;
25
+ 'parameter-destructuring': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedDestructuring", never[], {
26
+ ObjectPattern: (node: import("@typescript-eslint/types/dist/generated/ast-spec").ObjectPattern) => void;
24
27
  }>;
25
28
  };
package/rules/index.js CHANGED
@@ -6,10 +6,12 @@ const jsx_attribute_spacing_1 = require("./jsx-attribute-spacing");
6
6
  const complex_expression_spacing_1 = require("./complex-expression-spacing");
7
7
  const newline_per_chained_call_1 = require("./newline-per-chained-call");
8
8
  const min_chained_call_depth_1 = require("./min-chained-call-depth");
9
+ const parameter_destructuring_1 = require("./parameter-destructuring");
9
10
  exports.rules = {
10
11
  'argument-spacing': argument_spacing_1.argumentSpacing,
11
12
  'jsx-attribute-spacing': jsx_attribute_spacing_1.jsxAttributeSpacing,
12
13
  'complex-expression-spacing': complex_expression_spacing_1.complexExpressionSpacing,
13
14
  'newline-per-chained-call': newline_per_chained_call_1.newlinePerChainedCall,
14
15
  'min-chained-call-depth': min_chained_call_depth_1.minChainedCallDepth,
16
+ 'parameter-destructuring': parameter_destructuring_1.parameterDestructuring,
15
17
  };
@@ -1,6 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.minChainedCallDepth = void 0;
4
+ /*
5
+ eslint-disable @typescript-eslint/no-non-null-assertion
6
+ --
7
+ Disable the rule to reduce the number of branches
8
+ */
9
+ const experimental_utils_1 = require("@typescript-eslint/experimental-utils");
4
10
  const ast_utils_1 = require("@typescript-eslint/utils/dist/ast-utils");
5
11
  const createRule_1 = require("../createRule");
6
12
  exports.minChainedCallDepth = (0, createRule_1.createRule)({
@@ -39,13 +45,13 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
39
45
  function getDepth(node) {
40
46
  let depth = 0;
41
47
  let currentNode = node;
42
- while (currentNode.type === 'CallExpression'
43
- || currentNode.type === 'MemberExpression') {
44
- if (currentNode.type === 'MemberExpression') {
48
+ while (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
49
+ || currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
50
+ if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
45
51
  currentNode = currentNode.object;
46
52
  depth += 1;
47
53
  }
48
- else if (currentNode.type === 'CallExpression') {
54
+ else if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
49
55
  currentNode = currentNode.callee;
50
56
  }
51
57
  }
@@ -53,8 +59,8 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
53
59
  }
54
60
  function check(node) {
55
61
  var _a, _b;
56
- // If the node is a member expression inside a call expression skip, this is to ensure
57
- // that we consider the correct line length of the result.
62
+ // If the node is a member expression inside a call/new expression skip,
63
+ // this is to ensure that we consider the correct line length of the result.
58
64
  //
59
65
  // Example:
60
66
  // ```ts
@@ -63,20 +69,28 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
63
69
  // ```
64
70
  // The replacement of this input should be `foo.bar();`, which has 10 character.
65
71
  // Without this check it would consider the length up to `r`, which is 7.
66
- if (node.type === 'MemberExpression' && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression') {
72
+ if (node.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression
73
+ && ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
67
74
  return;
68
75
  }
69
- // If the node is a call expression we need to validate it's callee as a member
76
+ // If the node is a call/new expression we need to validate it's callee as a member
70
77
  // expression.
71
78
  // If the node itself is already a member expression, like the
72
79
  // `property` in `this.property.function()`, we validate the node directly.
73
- const callee = node.type === 'CallExpression' ? node.callee : node;
80
+ const callee = node.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
81
+ ? node.callee
82
+ : node;
74
83
  if (
75
84
  // If the callee is not a member expression, we can skip.
76
85
  // For example, root level calls like `foo();`.
77
- callee.type !== 'MemberExpression'
86
+ callee.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression
78
87
  // If the callee is a computed member expression, like `foo[bar]()`, we can skip.
79
88
  || callee.computed
89
+ /* eslint-disable-next-line @typescript-eslint/ban-ts-comment --
90
+ * NewExpression is a possible callee object type
91
+ */
92
+ // @ts-ignore
93
+ || callee.object.type === experimental_utils_1.AST_NODE_TYPES.NewExpression
80
94
  // If the callee is already in the same line as it's object, we can skip.
81
95
  || callee.object.loc.end.line === callee.property.loc.start.line) {
82
96
  return;
@@ -93,7 +107,7 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
93
107
  });
94
108
  const semicolon = sourceCode.getLastToken(node.parent, {
95
109
  filter: token => (token.loc.start.line === property.loc.start.line
96
- && token.type === 'Punctuator'
110
+ && token.type === experimental_utils_1.AST_TOKEN_TYPES.Punctuator
97
111
  && token.value === ';'),
98
112
  });
99
113
  const lineLength = callee.object.loc.end.column
@@ -0,0 +1,3 @@
1
+ export declare const parameterDestructuring: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedDestructuring", never[], {
2
+ ObjectPattern: (node: import("@typescript-eslint/types/dist/generated/ast-spec").ObjectPattern) => void;
3
+ }>;
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parameterDestructuring = void 0;
4
+ /*
5
+ eslint-disable @typescript-eslint/no-non-null-assertion
6
+ --
7
+ Disable the rule to reduce the number of branches
8
+ */
9
+ const types_1 = require("@typescript-eslint/types");
10
+ const createRule_1 = require("../createRule");
11
+ exports.parameterDestructuring = (0, createRule_1.createRule)({
12
+ name: 'parameter-destructuring',
13
+ meta: {
14
+ type: 'layout',
15
+ docs: {
16
+ description: 'Prevent noisy destructuring on parameters',
17
+ recommended: 'error',
18
+ },
19
+ hasSuggestions: true,
20
+ schema: [],
21
+ messages: {
22
+ unexpectedDestructuring: ('Destructuring should not be done in the parameters. '
23
+ + 'Bind to a variable and destructure inside the function.'),
24
+ },
25
+ },
26
+ defaultOptions: [],
27
+ create: context => {
28
+ const sourceCode = context.getSourceCode();
29
+ return {
30
+ ObjectPattern: function checkObjectPattern(node) {
31
+ const { parent } = node;
32
+ // Skip for destructuring in contexts unrelated to function parameters
33
+ if ((parent === null || parent === void 0 ? void 0 : parent.type) !== types_1.AST_NODE_TYPES.FunctionExpression
34
+ && (parent === null || parent === void 0 ? void 0 : parent.type) !== types_1.AST_NODE_TYPES.FunctionDeclaration
35
+ && (parent === null || parent === void 0 ? void 0 : parent.type) !== types_1.AST_NODE_TYPES.ArrowFunctionExpression) {
36
+ return;
37
+ }
38
+ // Allow one-line destructuring
39
+ if (node.loc.start.line === node.loc.end.line) {
40
+ return;
41
+ }
42
+ const { body } = parent;
43
+ context.report({
44
+ node: node,
45
+ messageId: 'unexpectedDestructuring',
46
+ suggest: body.type === types_1.AST_NODE_TYPES.BlockStatement
47
+ ? [
48
+ {
49
+ messageId: 'unexpectedDestructuring',
50
+ fix: (fixer) => [
51
+ // Replace the destructuring with a variable declaration
52
+ fixer.replaceText(node, 'value'),
53
+ // Add the destructuring inside the body
54
+ fixer.insertTextAfter(
55
+ // Null safety: a block expression always have the `{` token
56
+ // opening the body of the function.
57
+ sourceCode.getFirstToken(body), `\nconst ${sourceCode.getText(node)} = value;\n`),
58
+ ],
59
+ },
60
+ ]
61
+ : null,
62
+ });
63
+ },
64
+ };
65
+ },
66
+ });