@croct/eslint-plugin 0.3.0 → 0.6.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 +5 -10
- package/configs/javascript.d.ts +2 -0
- package/configs/javascript.js +7 -2
- package/configs/react.d.ts +1 -6
- package/configs/react.js +4 -9
- package/configs/typescript.d.ts +2 -4
- package/configs/typescript.js +1 -3
- package/index.d.ts +12 -13
- package/package.json +1 -2
- package/rules/index.d.ts +7 -3
- package/rules/min-chained-call-depth/index.d.ts +6 -2
- package/rules/min-chained-call-depth/index.js +58 -18
- package/rules/newline-per-chained-call/index.d.ts +1 -1
- package/rules/newline-per-chained-call/index.js +3 -3
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
|
})[];
|
|
@@ -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;
|
|
@@ -301,6 +294,8 @@ export declare const configs: {
|
|
|
301
294
|
'no-useless-escape': string;
|
|
302
295
|
'newline-destructuring/newline': (string | {
|
|
303
296
|
maxLength: number;
|
|
297
|
+
itemsWithRest: number;
|
|
298
|
+
items: number;
|
|
304
299
|
})[];
|
|
305
300
|
};
|
|
306
301
|
overrides: {
|
package/configs/javascript.d.ts
CHANGED
package/configs/javascript.js
CHANGED
|
@@ -216,9 +216,14 @@ exports.javascript = {
|
|
|
216
216
|
},
|
|
217
217
|
],
|
|
218
218
|
'no-useless-escape': 'error',
|
|
219
|
-
'newline-destructuring/newline': [
|
|
219
|
+
'newline-destructuring/newline': [
|
|
220
|
+
'error',
|
|
221
|
+
{
|
|
220
222
|
maxLength: 100,
|
|
221
|
-
|
|
223
|
+
itemsWithRest: Infinity,
|
|
224
|
+
items: Infinity,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
222
227
|
},
|
|
223
228
|
overrides: [
|
|
224
229
|
{
|
package/configs/react.d.ts
CHANGED
|
@@ -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
|
};
|
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
|
})[];
|
|
@@ -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;
|
package/configs/typescript.js
CHANGED
|
@@ -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
|
@@ -12,14 +12,18 @@ declare const configuration: {
|
|
|
12
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
|
+
ignoreChainDeeperThan: number;
|
|
16
16
|
}[], {
|
|
17
17
|
CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
|
|
18
18
|
MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
|
|
19
19
|
}>;
|
|
20
|
-
'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
|
|
20
|
+
'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
|
|
21
21
|
maxLineLength: number;
|
|
22
|
-
|
|
22
|
+
ignoreChainDeeperThan?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
ignoreChainDeeperThan: number;
|
|
25
|
+
maxLineLength?: undefined;
|
|
26
|
+
})[], {
|
|
23
27
|
CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
|
|
24
28
|
MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
|
|
25
29
|
}>;
|
|
@@ -48,6 +52,7 @@ declare const configuration: {
|
|
|
48
52
|
'@croct/jsx-attribute-spacing': string;
|
|
49
53
|
'react/jsx-wrap-multilines': string;
|
|
50
54
|
'react/display-name': string;
|
|
55
|
+
'jsx-quotes': string[];
|
|
51
56
|
'react/jsx-newline': (string | {
|
|
52
57
|
prevent: boolean;
|
|
53
58
|
})[];
|
|
@@ -103,12 +108,6 @@ declare const configuration: {
|
|
|
103
108
|
};
|
|
104
109
|
})[];
|
|
105
110
|
};
|
|
106
|
-
overrides: {
|
|
107
|
-
files: string[];
|
|
108
|
-
rules: {
|
|
109
|
-
'sort-keys-fix/sort-keys-fix': string;
|
|
110
|
-
};
|
|
111
|
-
}[];
|
|
112
111
|
};
|
|
113
112
|
typescript: {
|
|
114
113
|
extends: string[];
|
|
@@ -118,6 +117,7 @@ declare const configuration: {
|
|
|
118
117
|
extends: string[];
|
|
119
118
|
parser: string;
|
|
120
119
|
rules: {
|
|
120
|
+
'import/export': string;
|
|
121
121
|
'@typescript-eslint/array-type': (string | {
|
|
122
122
|
default: string;
|
|
123
123
|
})[];
|
|
@@ -178,9 +178,6 @@ declare const configuration: {
|
|
|
178
178
|
})[];
|
|
179
179
|
'no-undef': string;
|
|
180
180
|
'@typescript-eslint/no-namespace': string;
|
|
181
|
-
'@typescript-eslint/no-redeclare': (string | {
|
|
182
|
-
ignoreDeclarationMerge: boolean;
|
|
183
|
-
})[];
|
|
184
181
|
'no-new-object'?: undefined;
|
|
185
182
|
};
|
|
186
183
|
plugins?: undefined;
|
|
@@ -191,6 +188,7 @@ declare const configuration: {
|
|
|
191
188
|
plugins: string[];
|
|
192
189
|
rules: {
|
|
193
190
|
'no-new-object': string;
|
|
191
|
+
'import/export'?: undefined;
|
|
194
192
|
'@typescript-eslint/array-type'?: undefined;
|
|
195
193
|
'@typescript-eslint/prefer-as-const'?: undefined;
|
|
196
194
|
'@typescript-eslint/adjacent-overload-signatures'?: undefined;
|
|
@@ -218,7 +216,6 @@ declare const configuration: {
|
|
|
218
216
|
'@typescript-eslint/member-delimiter-style'?: undefined;
|
|
219
217
|
'no-undef'?: undefined;
|
|
220
218
|
'@typescript-eslint/no-namespace'?: undefined;
|
|
221
|
-
'@typescript-eslint/no-redeclare'?: undefined;
|
|
222
219
|
};
|
|
223
220
|
env: {
|
|
224
221
|
jest: boolean;
|
|
@@ -330,6 +327,8 @@ declare const configuration: {
|
|
|
330
327
|
'no-useless-escape': string;
|
|
331
328
|
'newline-destructuring/newline': (string | {
|
|
332
329
|
maxLength: number;
|
|
330
|
+
itemsWithRest: number;
|
|
331
|
+
items: number;
|
|
333
332
|
})[];
|
|
334
333
|
};
|
|
335
334
|
overrides: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "ESLint rules and presets applied to all Croct JavaScript projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -63,7 +63,6 @@
|
|
|
63
63
|
"eslint": "^8.8",
|
|
64
64
|
"eslint-plugin-eslint-plugin": "^4.1.0",
|
|
65
65
|
"eslint-plugin-self": "^1.2.1",
|
|
66
|
-
"eslint-plugin-sort-keys-fix": "^1.1.2",
|
|
67
66
|
"jest": "^27.5",
|
|
68
67
|
"ts-jest": "^27.1",
|
|
69
68
|
"typescript": "^4.5"
|
package/rules/index.d.ts
CHANGED
|
@@ -11,14 +11,18 @@ export declare const rules: {
|
|
|
11
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
|
+
ignoreChainDeeperThan: number;
|
|
15
15
|
}[], {
|
|
16
16
|
CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
|
|
17
17
|
MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
|
|
18
18
|
}>;
|
|
19
|
-
'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
|
|
19
|
+
'min-chained-call-depth': import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
|
|
20
20
|
maxLineLength: number;
|
|
21
|
-
|
|
21
|
+
ignoreChainDeeperThan?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
ignoreChainDeeperThan: number;
|
|
24
|
+
maxLineLength?: undefined;
|
|
25
|
+
})[], {
|
|
22
26
|
CallExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").CallExpression) => void;
|
|
23
27
|
MemberExpression: (node: import("@typescript-eslint/types/dist/generated/ast-spec").MemberExpression) => void;
|
|
24
28
|
}>;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/experimental-utils';
|
|
2
|
-
export declare const minChainedCallDepth: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", {
|
|
2
|
+
export declare const minChainedCallDepth: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"unexpectedLineBreak", ({
|
|
3
3
|
maxLineLength: number;
|
|
4
|
-
|
|
4
|
+
ignoreChainDeeperThan?: undefined;
|
|
5
|
+
} | {
|
|
6
|
+
ignoreChainDeeperThan: number;
|
|
7
|
+
maxLineLength?: undefined;
|
|
8
|
+
})[], {
|
|
5
9
|
CallExpression: (node: TSESTree.CallExpression) => void;
|
|
6
10
|
MemberExpression: (node: TSESTree.MemberExpression) => void;
|
|
7
11
|
}>;
|
|
@@ -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)({
|
|
@@ -21,6 +27,12 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
21
27
|
minimum: 1,
|
|
22
28
|
default: 100,
|
|
23
29
|
},
|
|
30
|
+
ignoreChainDeeperThan: {
|
|
31
|
+
type: 'integer',
|
|
32
|
+
minimum: 1,
|
|
33
|
+
maximum: 10,
|
|
34
|
+
default: 2,
|
|
35
|
+
},
|
|
24
36
|
},
|
|
25
37
|
additionalProperties: false,
|
|
26
38
|
},
|
|
@@ -33,19 +45,23 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
33
45
|
{
|
|
34
46
|
maxLineLength: 100,
|
|
35
47
|
},
|
|
48
|
+
{
|
|
49
|
+
ignoreChainDeeperThan: 3,
|
|
50
|
+
},
|
|
36
51
|
],
|
|
37
52
|
create: context => {
|
|
38
53
|
const sourceCode = context.getSourceCode();
|
|
54
|
+
let maxDepth = 0;
|
|
39
55
|
function getDepth(node) {
|
|
40
56
|
let depth = 0;
|
|
41
57
|
let currentNode = node;
|
|
42
|
-
while (currentNode.type ===
|
|
43
|
-
|| currentNode.type ===
|
|
44
|
-
if (currentNode.type ===
|
|
58
|
+
while (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
|
|
59
|
+
|| currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
60
|
+
if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression) {
|
|
45
61
|
currentNode = currentNode.object;
|
|
46
62
|
depth += 1;
|
|
47
63
|
}
|
|
48
|
-
else if (currentNode.type ===
|
|
64
|
+
else if (currentNode.type === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
|
|
49
65
|
currentNode = currentNode.callee;
|
|
50
66
|
}
|
|
51
67
|
}
|
|
@@ -53,8 +69,8 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
53
69
|
}
|
|
54
70
|
function check(node) {
|
|
55
71
|
var _a, _b;
|
|
56
|
-
// If the node is a member expression inside a call expression skip,
|
|
57
|
-
// that we consider the correct line length of the result.
|
|
72
|
+
// If the node is a member expression inside a call/new expression skip,
|
|
73
|
+
// this is to ensure that we consider the correct line length of the result.
|
|
58
74
|
//
|
|
59
75
|
// Example:
|
|
60
76
|
// ```ts
|
|
@@ -63,37 +79,61 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
63
79
|
// ```
|
|
64
80
|
// The replacement of this input should be `foo.bar();`, which has 10 character.
|
|
65
81
|
// Without this check it would consider the length up to `r`, which is 7.
|
|
66
|
-
if (node.type ===
|
|
82
|
+
if (node.type === experimental_utils_1.AST_NODE_TYPES.MemberExpression
|
|
83
|
+
&& ((_a = node.parent) === null || _a === void 0 ? void 0 : _a.type) === experimental_utils_1.AST_NODE_TYPES.CallExpression) {
|
|
67
84
|
return;
|
|
68
85
|
}
|
|
69
|
-
// If the node is a call expression we need to validate it's callee as a member
|
|
86
|
+
// If the node is a call/new expression we need to validate it's callee as a member
|
|
70
87
|
// expression.
|
|
71
88
|
// If the node itself is already a member expression, like the
|
|
72
89
|
// `property` in `this.property.function()`, we validate the node directly.
|
|
73
|
-
const callee = node.type ===
|
|
90
|
+
const callee = node.type === experimental_utils_1.AST_NODE_TYPES.CallExpression
|
|
91
|
+
? node.callee
|
|
92
|
+
: node;
|
|
74
93
|
if (
|
|
75
|
-
// If the callee is not a member expression,
|
|
94
|
+
// If the callee is not a member expression, skip.
|
|
76
95
|
// For example, root level calls like `foo();`.
|
|
77
|
-
callee.type !==
|
|
78
|
-
// If the callee is a computed member expression, like `foo[bar]()`,
|
|
96
|
+
callee.type !== experimental_utils_1.AST_NODE_TYPES.MemberExpression
|
|
97
|
+
// If the callee is a computed member expression, like `foo[bar]()`, skip.
|
|
79
98
|
|| callee.computed
|
|
80
|
-
|
|
99
|
+
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment --
|
|
100
|
+
* NewExpression is a possible callee object type
|
|
101
|
+
*/
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
|| callee.object.type === experimental_utils_1.AST_NODE_TYPES.NewExpression
|
|
104
|
+
// If the callee is already in the same line as it's object, skip.
|
|
81
105
|
|| callee.object.loc.end.line === callee.property.loc.start.line) {
|
|
82
106
|
return;
|
|
83
107
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
108
|
+
const currentDepth = getDepth(callee);
|
|
109
|
+
maxDepth = Math.max(maxDepth, currentDepth);
|
|
110
|
+
// Only affect the root level as the total depth is must be known.
|
|
111
|
+
// If the current call is nested inside another call, skip.
|
|
112
|
+
if (currentDepth > 1) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
const { maxLineLength = 100, ignoreChainDeeperThan = 2 } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : {};
|
|
116
|
+
// If the max depth is greater than ignore threshold, skip
|
|
117
|
+
//
|
|
118
|
+
// Example:
|
|
119
|
+
// ```ts
|
|
120
|
+
// Array(10)
|
|
121
|
+
// .fill(0)
|
|
122
|
+
// .map(x => x + 1)
|
|
123
|
+
// .slice(0, 5);
|
|
124
|
+
// ```
|
|
125
|
+
// In this case the depth is 3, and the default value of ignoreChainDeeperThan is 2.
|
|
126
|
+
// So the check can be skipped.
|
|
127
|
+
if (maxDepth > ignoreChainDeeperThan) {
|
|
87
128
|
return;
|
|
88
129
|
}
|
|
89
|
-
const { maxLineLength = 100 } = (_b = context.options[0]) !== null && _b !== void 0 ? _b : {};
|
|
90
130
|
const { property } = callee;
|
|
91
131
|
const lastToken = sourceCode.getLastToken(node, {
|
|
92
132
|
filter: token => token.loc.end.line === property.loc.start.line,
|
|
93
133
|
});
|
|
94
134
|
const semicolon = sourceCode.getLastToken(node.parent, {
|
|
95
135
|
filter: token => (token.loc.start.line === property.loc.start.line
|
|
96
|
-
&& token.type ===
|
|
136
|
+
&& token.type === experimental_utils_1.AST_TOKEN_TYPES.Punctuator
|
|
97
137
|
&& token.value === ';'),
|
|
98
138
|
});
|
|
99
139
|
const lineLength = callee.object.loc.end.column
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TSESTree } from '@typescript-eslint/experimental-utils';
|
|
2
2
|
export declare const newlinePerChainedCall: import("@typescript-eslint/utils/dist/ts-eslint/Rule").RuleModule<"expectedLineBreak", {
|
|
3
|
-
|
|
3
|
+
ignoreChainDeeperThan: number;
|
|
4
4
|
}[], {
|
|
5
5
|
CallExpression: (node: TSESTree.CallExpression) => void;
|
|
6
6
|
MemberExpression: (node: TSESTree.MemberExpression) => void;
|
|
@@ -16,7 +16,7 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
16
16
|
{
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
|
-
|
|
19
|
+
ignoreChainDeeperThan: {
|
|
20
20
|
type: 'integer',
|
|
21
21
|
minimum: 1,
|
|
22
22
|
maximum: 10,
|
|
@@ -32,13 +32,13 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
32
32
|
},
|
|
33
33
|
defaultOptions: [
|
|
34
34
|
{
|
|
35
|
-
|
|
35
|
+
ignoreChainDeeperThan: 2,
|
|
36
36
|
},
|
|
37
37
|
],
|
|
38
38
|
create: context => {
|
|
39
39
|
var _a, _b;
|
|
40
40
|
const options = (_a = context.options[0]) !== null && _a !== void 0 ? _a : {};
|
|
41
|
-
const ignoreChainWithDepth = (_b = options.
|
|
41
|
+
const ignoreChainWithDepth = (_b = options.ignoreChainDeeperThan) !== null && _b !== void 0 ? _b : 2;
|
|
42
42
|
const sourceCode = context.getSourceCode();
|
|
43
43
|
function getPropertyText(node) {
|
|
44
44
|
const prefix = '.';
|