@croct/eslint-plugin 0.2.3-rc.1 → 0.4.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/configs/index.d.ts +9 -0
- package/configs/javascript.d.ts +6 -0
- package/configs/javascript.js +10 -0
- package/configs/react.d.ts +1 -0
- package/configs/react.js +4 -0
- package/configs/typescript.d.ts +2 -0
- package/configs/typescript.js +1 -0
- package/index.d.ts +21 -9
- package/package.json +2 -1
- package/rules/index.d.ts +12 -9
- package/rules/index.js +2 -0
- package/rules/parameter-destructuring/index.d.ts +3 -0
- package/rules/parameter-destructuring/index.js +66 -0
package/configs/index.d.ts
CHANGED
|
@@ -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
|
})[];
|
|
@@ -89,6 +90,7 @@ export declare const configs: {
|
|
|
89
90
|
extends: string[];
|
|
90
91
|
parser: string;
|
|
91
92
|
rules: {
|
|
93
|
+
'import/export': string;
|
|
92
94
|
'@typescript-eslint/array-type': (string | {
|
|
93
95
|
default: string;
|
|
94
96
|
})[];
|
|
@@ -162,6 +164,7 @@ export declare const configs: {
|
|
|
162
164
|
plugins: string[];
|
|
163
165
|
rules: {
|
|
164
166
|
'no-new-object': string;
|
|
167
|
+
'import/export'?: undefined;
|
|
165
168
|
'@typescript-eslint/array-type'?: undefined;
|
|
166
169
|
'@typescript-eslint/prefer-as-const'?: undefined;
|
|
167
170
|
'@typescript-eslint/adjacent-overload-signatures'?: undefined;
|
|
@@ -205,6 +208,7 @@ export declare const configs: {
|
|
|
205
208
|
'@croct/complex-expression-spacing': string;
|
|
206
209
|
'@croct/newline-per-chained-call': string;
|
|
207
210
|
'@croct/min-chained-call-depth': string;
|
|
211
|
+
'@croct/parameter-destructuring': string;
|
|
208
212
|
'eslint-comments/disable-enable-pair': (string | {
|
|
209
213
|
allowWholeFile: boolean;
|
|
210
214
|
})[];
|
|
@@ -298,6 +302,11 @@ export declare const configs: {
|
|
|
298
302
|
next: string;
|
|
299
303
|
})[];
|
|
300
304
|
'no-useless-escape': string;
|
|
305
|
+
'newline-destructuring/newline': (string | {
|
|
306
|
+
maxLength: number;
|
|
307
|
+
itemsWithRest: number;
|
|
308
|
+
items: number;
|
|
309
|
+
})[];
|
|
301
310
|
};
|
|
302
311
|
overrides: {
|
|
303
312
|
files: string[];
|
package/configs/javascript.d.ts
CHANGED
|
@@ -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[];
|
package/configs/javascript.js
CHANGED
|
@@ -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
|
{
|
package/configs/react.d.ts
CHANGED
package/configs/react.js
CHANGED
package/configs/typescript.d.ts
CHANGED
|
@@ -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
|
})[];
|
|
@@ -79,6 +80,7 @@ export declare const typescript: {
|
|
|
79
80
|
plugins: string[];
|
|
80
81
|
rules: {
|
|
81
82
|
'no-new-object': string;
|
|
83
|
+
'import/export'?: undefined;
|
|
82
84
|
'@typescript-eslint/array-type'?: undefined;
|
|
83
85
|
'@typescript-eslint/prefer-as-const'?: undefined;
|
|
84
86
|
'@typescript-eslint/adjacent-overload-signatures'?: undefined;
|
package/configs/typescript.js
CHANGED
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
|
})[];
|
|
@@ -115,6 +119,7 @@ declare const configuration: {
|
|
|
115
119
|
extends: string[];
|
|
116
120
|
parser: string;
|
|
117
121
|
rules: {
|
|
122
|
+
'import/export': string;
|
|
118
123
|
'@typescript-eslint/array-type': (string | {
|
|
119
124
|
default: string;
|
|
120
125
|
})[];
|
|
@@ -188,6 +193,7 @@ declare const configuration: {
|
|
|
188
193
|
plugins: string[];
|
|
189
194
|
rules: {
|
|
190
195
|
'no-new-object': string;
|
|
196
|
+
'import/export'?: undefined;
|
|
191
197
|
'@typescript-eslint/array-type'?: undefined;
|
|
192
198
|
'@typescript-eslint/prefer-as-const'?: undefined;
|
|
193
199
|
'@typescript-eslint/adjacent-overload-signatures'?: undefined;
|
|
@@ -231,6 +237,7 @@ declare const configuration: {
|
|
|
231
237
|
'@croct/complex-expression-spacing': string;
|
|
232
238
|
'@croct/newline-per-chained-call': string;
|
|
233
239
|
'@croct/min-chained-call-depth': string;
|
|
240
|
+
'@croct/parameter-destructuring': string;
|
|
234
241
|
'eslint-comments/disable-enable-pair': (string | {
|
|
235
242
|
allowWholeFile: boolean;
|
|
236
243
|
})[];
|
|
@@ -324,6 +331,11 @@ declare const configuration: {
|
|
|
324
331
|
next: string;
|
|
325
332
|
})[];
|
|
326
333
|
'no-useless-escape': string;
|
|
334
|
+
'newline-destructuring/newline': (string | {
|
|
335
|
+
maxLength: number;
|
|
336
|
+
itemsWithRest: number;
|
|
337
|
+
items: number;
|
|
338
|
+
})[];
|
|
327
339
|
};
|
|
328
340
|
overrides: {
|
|
329
341
|
files: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.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",
|
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
|
};
|
|
@@ -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
|
+
});
|