@croct/eslint-plugin 0.7.1 → 0.8.1
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/README.md +1 -3
- package/configs/cypress.js +27 -19
- package/configs/index.js +10 -11
- package/configs/javascript.js +886 -239
- package/configs/react.js +342 -118
- package/configs/typescript.js +96 -83
- package/index.js +26 -4
- package/package.json +29 -30
- package/rules/argument-spacing/index.js +3 -3
- package/rules/complex-expression-spacing/index.js +4 -4
- package/rules/jsx-attribute-spacing/index.js +4 -3
- package/rules/min-chained-call-depth/index.js +1 -8
- package/rules/newline-per-chained-call/index.js +18 -18
- package/rules/parameter-destructuring/index.js +0 -1
package/index.js
CHANGED
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.rules = exports.configs = void 0;
|
|
2
4
|
const rules_1 = require("./rules");
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
+
Object.defineProperty(exports, "rules", { enumerable: true, get: function () { return rules_1.rules; } });
|
|
6
|
+
const javascript_1 = require("./configs/javascript");
|
|
7
|
+
const typescript_1 = require("./configs/typescript");
|
|
8
|
+
const react_1 = require("./configs/react");
|
|
9
|
+
const cypress_1 = require("./configs/cypress");
|
|
10
|
+
// Create the plugin with just the rules first
|
|
11
|
+
const plugin = {
|
|
12
|
+
// Cast from TypeScript Rule Module to ESLint RuleDefinition.
|
|
13
|
+
// Due to variance, TS can't verify the type directly.
|
|
5
14
|
rules: rules_1.rules,
|
|
6
|
-
configs:
|
|
15
|
+
configs: {},
|
|
7
16
|
};
|
|
8
|
-
|
|
17
|
+
// Create configs with the plugin reference
|
|
18
|
+
const javascriptConfig = (0, javascript_1.createJavaScriptConfig)(plugin);
|
|
19
|
+
const typescriptConfig = (0, typescript_1.createTypescriptConfig)(plugin, javascriptConfig);
|
|
20
|
+
const reactConfig = (0, react_1.createReactConfig)(plugin, javascriptConfig);
|
|
21
|
+
const cypressConfig = (0, cypress_1.createCypressConfig)(plugin, javascriptConfig);
|
|
22
|
+
exports.configs = {
|
|
23
|
+
javascript: javascriptConfig,
|
|
24
|
+
typescript: typescriptConfig,
|
|
25
|
+
react: reactConfig,
|
|
26
|
+
cypress: cypressConfig,
|
|
27
|
+
};
|
|
28
|
+
Object.assign(plugin.configs, exports.configs);
|
|
29
|
+
// Export the plugin as default
|
|
30
|
+
exports.default = plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@croct/eslint-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"description": "ESLint rules and presets applied to all Croct JavaScript projects.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|
|
@@ -36,39 +36,38 @@
|
|
|
36
36
|
"cypress"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@
|
|
41
|
-
"@typescript-eslint/utils": "^
|
|
42
|
-
"eslint-
|
|
43
|
-
"eslint-
|
|
44
|
-
"eslint-plugin-
|
|
45
|
-
"eslint-plugin-
|
|
46
|
-
"eslint-plugin-
|
|
47
|
-
"eslint-plugin-
|
|
48
|
-
"eslint-plugin-
|
|
49
|
-
"eslint-plugin-
|
|
50
|
-
"eslint-plugin-
|
|
51
|
-
"eslint-plugin-
|
|
52
|
-
"
|
|
53
|
-
"eslint
|
|
54
|
-
"eslint-plugin-react-hooks": "^4.3",
|
|
55
|
-
"eslint-plugin-testing-library": "^6.0.0"
|
|
39
|
+
"@eslint-community/eslint-plugin-eslint-comments": "^4.5.0",
|
|
40
|
+
"@stylistic/eslint-plugin": "^5.7.0",
|
|
41
|
+
"@typescript-eslint/utils": "^8.53.0",
|
|
42
|
+
"eslint-plugin-cypress": "^5.2.1",
|
|
43
|
+
"eslint-plugin-import-newlines": "^1.4.0",
|
|
44
|
+
"eslint-plugin-import-x": "^4.16.1",
|
|
45
|
+
"eslint-plugin-jest": "^29.12.1",
|
|
46
|
+
"eslint-plugin-jest-dom": "^5.5.0",
|
|
47
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
48
|
+
"eslint-plugin-newline-destructuring": "^1.2.2",
|
|
49
|
+
"eslint-plugin-react": "^7.37.5",
|
|
50
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
51
|
+
"eslint-plugin-testing-library": "^7.15.4",
|
|
52
|
+
"globals": "^17.0.0",
|
|
53
|
+
"typescript-eslint": "^8.53.0"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
|
-
"@types/
|
|
59
|
-
"@types/
|
|
60
|
-
"@
|
|
61
|
-
"@typescript-eslint/
|
|
62
|
-
"@typescript-eslint/types": "^
|
|
63
|
-
"eslint": "^8.
|
|
64
|
-
"eslint
|
|
56
|
+
"@types/jest": "^29.5.14",
|
|
57
|
+
"@types/semver": "^7.5.8",
|
|
58
|
+
"@typescript-eslint/parser": "^8.53.0",
|
|
59
|
+
"@typescript-eslint/rule-tester": "^8.53.0",
|
|
60
|
+
"@typescript-eslint/types": "^8.53.0",
|
|
61
|
+
"@typescript-eslint/typescript-estree": "^8.53.0",
|
|
62
|
+
"eslint": "^9.28.0",
|
|
63
|
+
"eslint-plugin-eslint-plugin": "^6.4.0",
|
|
65
64
|
"eslint-plugin-self": "^1.2.1",
|
|
66
|
-
"jest": "^29.
|
|
67
|
-
"ts-jest": "^29.
|
|
68
|
-
"typescript": "
|
|
65
|
+
"jest": "^29.7.0",
|
|
66
|
+
"ts-jest": "^29.3.4",
|
|
67
|
+
"typescript": "~5.9.0"
|
|
69
68
|
},
|
|
70
69
|
"peerDependencies": {
|
|
71
|
-
"@typescript-eslint/parser": ">=
|
|
72
|
-
"eslint": ">=
|
|
70
|
+
"@typescript-eslint/parser": ">= 8",
|
|
71
|
+
"eslint": ">= 9"
|
|
73
72
|
}
|
|
74
73
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.argumentSpacing = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
5
|
const createRule_1 = require("../createRule");
|
|
5
6
|
exports.argumentSpacing = (0, createRule_1.createRule)({
|
|
6
7
|
name: 'argument-spacing',
|
|
@@ -9,7 +10,6 @@ exports.argumentSpacing = (0, createRule_1.createRule)({
|
|
|
9
10
|
docs: {
|
|
10
11
|
description: 'Enforces a surrounding line break before and after '
|
|
11
12
|
+ 'the argument list in multiline functional calls.',
|
|
12
|
-
recommended: 'recommended',
|
|
13
13
|
},
|
|
14
14
|
fixable: 'whitespace',
|
|
15
15
|
schema: [],
|
|
@@ -35,8 +35,8 @@ exports.argumentSpacing = (0, createRule_1.createRule)({
|
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
const lastArgumentFirstToken = sourceCode.getFirstToken(lastArgument);
|
|
38
|
-
if ((lastArgument.type !==
|
|
39
|
-
|| lastArgument.body.type ===
|
|
38
|
+
if ((lastArgument.type !== utils_1.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression
|
|
39
|
+
|| lastArgument.body.type === utils_1.TSESTree.AST_NODE_TYPES.BlockStatement)
|
|
40
40
|
&& firstToken.loc.start.line === lastArgumentFirstToken.loc.start.line) {
|
|
41
41
|
return;
|
|
42
42
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.complexExpressionSpacing = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
5
|
const createRule_1 = require("../createRule");
|
|
5
6
|
exports.complexExpressionSpacing = (0, createRule_1.createRule)({
|
|
6
7
|
name: 'complex-expression-spacing',
|
|
@@ -8,7 +9,6 @@ exports.complexExpressionSpacing = (0, createRule_1.createRule)({
|
|
|
8
9
|
type: 'suggestion',
|
|
9
10
|
docs: {
|
|
10
11
|
description: 'Enforces a surrounding line break in complex expression.',
|
|
11
|
-
recommended: 'recommended',
|
|
12
12
|
},
|
|
13
13
|
fixable: 'whitespace',
|
|
14
14
|
schema: [],
|
|
@@ -21,10 +21,10 @@ exports.complexExpressionSpacing = (0, createRule_1.createRule)({
|
|
|
21
21
|
const sourceCode = context.getSourceCode();
|
|
22
22
|
function check(node) {
|
|
23
23
|
const parentPreviousToken = sourceCode.getTokenBefore(node, {
|
|
24
|
-
filter: token => token.type ===
|
|
24
|
+
filter: token => token.type === utils_1.TSESTree.AST_TOKEN_TYPES.Punctuator,
|
|
25
25
|
});
|
|
26
26
|
const parentNextToken = sourceCode.getTokenAfter(node, {
|
|
27
|
-
filter: token => token.type ===
|
|
27
|
+
filter: token => token.type === utils_1.TSESTree.AST_TOKEN_TYPES.Punctuator,
|
|
28
28
|
});
|
|
29
29
|
if (parentPreviousToken.loc.end.line === parentNextToken.loc.start.line) {
|
|
30
30
|
return;
|
|
@@ -54,7 +54,7 @@ exports.complexExpressionSpacing = (0, createRule_1.createRule)({
|
|
|
54
54
|
return {
|
|
55
55
|
ArrowFunctionExpression: (node) => {
|
|
56
56
|
const { body } = node;
|
|
57
|
-
if (body.type ===
|
|
57
|
+
if (body.type === utils_1.TSESTree.AST_NODE_TYPES.ConditionalExpression) {
|
|
58
58
|
check(body);
|
|
59
59
|
}
|
|
60
60
|
},
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.jsxAttributeSpacing = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
5
|
const createRule_1 = require("../createRule");
|
|
5
6
|
exports.jsxAttributeSpacing = (0, createRule_1.createRule)({
|
|
6
7
|
name: 'jsx-attribute-spacing',
|
|
@@ -8,7 +9,6 @@ exports.jsxAttributeSpacing = (0, createRule_1.createRule)({
|
|
|
8
9
|
type: 'suggestion',
|
|
9
10
|
docs: {
|
|
10
11
|
description: 'Enforces a surrounding line break in multiline JSX attributes.',
|
|
11
|
-
recommended: 'recommended',
|
|
12
12
|
},
|
|
13
13
|
fixable: 'whitespace',
|
|
14
14
|
schema: [],
|
|
@@ -21,12 +21,13 @@ exports.jsxAttributeSpacing = (0, createRule_1.createRule)({
|
|
|
21
21
|
const sourceCode = context.getSourceCode();
|
|
22
22
|
function check(node) {
|
|
23
23
|
const { value } = node;
|
|
24
|
-
if (value
|
|
24
|
+
if (value?.type !== utils_1.TSESTree.AST_NODE_TYPES.JSXExpressionContainer) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
const firstToken = sourceCode.getFirstToken(value.expression);
|
|
28
28
|
const lastToken = sourceCode.getLastToken(value.expression);
|
|
29
|
-
if ((firstToken.type ===
|
|
29
|
+
if ((firstToken.type === utils_1.TSESTree.AST_TOKEN_TYPES.Punctuator
|
|
30
|
+
&& lastToken.type === utils_1.TSESTree.AST_TOKEN_TYPES.Punctuator)
|
|
30
31
|
|| (firstToken.loc.start.line === lastToken.loc.end.line)) {
|
|
31
32
|
return;
|
|
32
33
|
}
|
|
@@ -10,7 +10,6 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
10
10
|
type: 'layout',
|
|
11
11
|
docs: {
|
|
12
12
|
description: 'Enforces a minimum depth for multiline chained calls.',
|
|
13
|
-
recommended: 'stylistic',
|
|
14
13
|
},
|
|
15
14
|
fixable: 'whitespace',
|
|
16
15
|
schema: [
|
|
@@ -39,9 +38,7 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
39
38
|
defaultOptions: [
|
|
40
39
|
{
|
|
41
40
|
maxLineLength: 100,
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
ignoreChainDeeperThan: 3,
|
|
41
|
+
ignoreChainDeeperThan: 2,
|
|
45
42
|
},
|
|
46
43
|
],
|
|
47
44
|
create: context => {
|
|
@@ -90,10 +87,6 @@ exports.minChainedCallDepth = (0, createRule_1.createRule)({
|
|
|
90
87
|
callee.type !== utils_1.AST_NODE_TYPES.MemberExpression
|
|
91
88
|
// If the callee is a computed member expression, like `foo[bar]()`, skip.
|
|
92
89
|
|| callee.computed
|
|
93
|
-
/* eslint-disable-next-line @typescript-eslint/ban-ts-comment --
|
|
94
|
-
* NewExpression is a possible callee object type
|
|
95
|
-
*/
|
|
96
|
-
// @ts-ignore
|
|
97
90
|
|| callee.object.type === utils_1.AST_NODE_TYPES.NewExpression
|
|
98
91
|
// If the callee is already in the same line as it's object, skip.
|
|
99
92
|
|| callee.object.loc.end.line === callee.property.loc.start.line) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.newlinePerChainedCall = void 0;
|
|
4
|
+
const utils_1 = require("@typescript-eslint/utils");
|
|
4
5
|
const createRule_1 = require("../createRule");
|
|
5
6
|
const LINEBREAK_MATCHER = /\r\n|[\r\n\u2028\u2029]/u;
|
|
6
7
|
exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
@@ -9,7 +10,6 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
9
10
|
type: 'layout',
|
|
10
11
|
docs: {
|
|
11
12
|
description: 'Require a newline after each call in a method chain',
|
|
12
|
-
recommended: 'recommended',
|
|
13
13
|
},
|
|
14
14
|
fixable: 'whitespace',
|
|
15
15
|
schema: [
|
|
@@ -48,30 +48,30 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
48
48
|
return node.object.loc.end.line === node.property.loc.start.line;
|
|
49
49
|
}
|
|
50
50
|
function isNotClosingParenToken(token) {
|
|
51
|
-
return token.value !== ')' || token.type !==
|
|
51
|
+
return token.value !== ')' || token.type !== utils_1.TSESTree.AST_TOKEN_TYPES.Punctuator;
|
|
52
52
|
}
|
|
53
53
|
function validateCallExpressionIgnoreDepth(node) {
|
|
54
54
|
let hasCallExpression = false;
|
|
55
|
-
if (node.type ===
|
|
55
|
+
if (node.type === utils_1.TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
56
56
|
hasCallExpression = true;
|
|
57
57
|
}
|
|
58
|
-
if (
|
|
59
|
-
&& node.parent.type !==
|
|
60
|
-
&& node.parent.type !==
|
|
58
|
+
if (node.parent != null
|
|
59
|
+
&& node.parent.type !== utils_1.TSESTree.AST_NODE_TYPES.CallExpression
|
|
60
|
+
&& node.parent.type !== utils_1.TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
61
61
|
const memberExpressions = [];
|
|
62
|
-
let currentNode = (
|
|
62
|
+
let currentNode = ('callee' in node
|
|
63
63
|
? node.callee
|
|
64
64
|
: node);
|
|
65
|
-
while (currentNode.type ===
|
|
66
|
-
|| currentNode.type ===
|
|
67
|
-
if (currentNode.type ===
|
|
68
|
-
if (currentNode.property.type ===
|
|
65
|
+
while (currentNode.type === utils_1.TSESTree.AST_NODE_TYPES.CallExpression
|
|
66
|
+
|| currentNode.type === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
67
|
+
if (currentNode.type === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
68
|
+
if (currentNode.property.type === utils_1.TSESTree.AST_NODE_TYPES.Identifier
|
|
69
69
|
&& !currentNode.computed) {
|
|
70
70
|
memberExpressions.push(currentNode);
|
|
71
71
|
}
|
|
72
72
|
currentNode = currentNode.object;
|
|
73
73
|
}
|
|
74
|
-
else if (currentNode.type ===
|
|
74
|
+
else if (currentNode.type === utils_1.TSESTree.AST_NODE_TYPES.CallExpression) {
|
|
75
75
|
currentNode = currentNode.callee;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
@@ -81,11 +81,11 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
81
81
|
const expressionsOnSameLine = memberExpressions
|
|
82
82
|
.filter(hasObjectAndPropertyOnSameLine);
|
|
83
83
|
const rootNode = expressionsOnSameLine[expressionsOnSameLine.length - 1];
|
|
84
|
-
if (rootNode.type ===
|
|
85
|
-
&& (rootNode.parent
|
|
86
|
-
|| rootNode.parent
|
|
87
|
-
&& (rootNode.object.type ===
|
|
88
|
-
|| rootNode.object.type ===
|
|
84
|
+
if (rootNode.type === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression
|
|
85
|
+
&& (rootNode.parent != null && (rootNode.parent.type === utils_1.TSESTree.AST_NODE_TYPES.CallExpression
|
|
86
|
+
|| rootNode.parent.type === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression))
|
|
87
|
+
&& (rootNode.object.type === utils_1.TSESTree.AST_NODE_TYPES.ThisExpression
|
|
88
|
+
|| rootNode.object.type === utils_1.TSESTree.AST_NODE_TYPES.Identifier)) {
|
|
89
89
|
expressionsOnSameLine.pop();
|
|
90
90
|
}
|
|
91
91
|
expressionsOnSameLine.forEach(memberExpression => {
|
|
@@ -107,7 +107,7 @@ exports.newlinePerChainedCall = (0, createRule_1.createRule)({
|
|
|
107
107
|
}
|
|
108
108
|
return {
|
|
109
109
|
CallExpression: (node) => {
|
|
110
|
-
if (node.callee?.type ===
|
|
110
|
+
if (node.callee?.type === utils_1.TSESTree.AST_NODE_TYPES.MemberExpression) {
|
|
111
111
|
validateCallExpressionIgnoreDepth(node);
|
|
112
112
|
}
|
|
113
113
|
},
|