@croct/eslint-plugin 0.2.3 → 0.3.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 +4 -0
- package/configs/javascript.d.ts +4 -0
- package/configs/javascript.js +5 -0
- package/index.d.ts +16 -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
|
@@ -205,6 +205,7 @@ export declare const configs: {
|
|
|
205
205
|
'@croct/complex-expression-spacing': string;
|
|
206
206
|
'@croct/newline-per-chained-call': string;
|
|
207
207
|
'@croct/min-chained-call-depth': string;
|
|
208
|
+
'@croct/parameter-destructuring': string;
|
|
208
209
|
'eslint-comments/disable-enable-pair': (string | {
|
|
209
210
|
allowWholeFile: boolean;
|
|
210
211
|
})[];
|
|
@@ -298,6 +299,9 @@ export declare const configs: {
|
|
|
298
299
|
next: string;
|
|
299
300
|
})[];
|
|
300
301
|
'no-useless-escape': string;
|
|
302
|
+
'newline-destructuring/newline': (string | {
|
|
303
|
+
maxLength: number;
|
|
304
|
+
})[];
|
|
301
305
|
};
|
|
302
306
|
overrides: {
|
|
303
307
|
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,9 @@ 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
|
+
})[];
|
|
102
106
|
};
|
|
103
107
|
overrides: {
|
|
104
108
|
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,9 @@ exports.javascript = {
|
|
|
214
216
|
},
|
|
215
217
|
],
|
|
216
218
|
'no-useless-escape': 'error',
|
|
219
|
+
'newline-destructuring/newline': ['error', {
|
|
220
|
+
maxLength: 100,
|
|
221
|
+
}],
|
|
217
222
|
},
|
|
218
223
|
overrides: [
|
|
219
224
|
{
|
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: {
|
|
@@ -231,6 +234,7 @@ declare const configuration: {
|
|
|
231
234
|
'@croct/complex-expression-spacing': string;
|
|
232
235
|
'@croct/newline-per-chained-call': string;
|
|
233
236
|
'@croct/min-chained-call-depth': string;
|
|
237
|
+
'@croct/parameter-destructuring': string;
|
|
234
238
|
'eslint-comments/disable-enable-pair': (string | {
|
|
235
239
|
allowWholeFile: boolean;
|
|
236
240
|
})[];
|
|
@@ -324,6 +328,9 @@ declare const configuration: {
|
|
|
324
328
|
next: string;
|
|
325
329
|
})[];
|
|
326
330
|
'no-useless-escape': string;
|
|
331
|
+
'newline-destructuring/newline': (string | {
|
|
332
|
+
maxLength: number;
|
|
333
|
+
})[];
|
|
327
334
|
};
|
|
328
335
|
overrides: {
|
|
329
336
|
files: string[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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
|
+
});
|