eslint-config-seek 11.1.1 → 11.1.3
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/base.js +12 -3
- package/package.json +6 -4
- package/rules/unsafe-to-chain-command.js +88 -0
package/base.js
CHANGED
|
@@ -4,6 +4,9 @@ const root = require('find-root')(process.cwd());
|
|
|
4
4
|
const OFF = 0;
|
|
5
5
|
const ERROR = 2;
|
|
6
6
|
|
|
7
|
+
const rulesDirPlugin = require('eslint-plugin-rulesdir');
|
|
8
|
+
rulesDirPlugin.RULES_DIR = path.join(__dirname, 'rules');
|
|
9
|
+
|
|
7
10
|
const baseRules = {
|
|
8
11
|
// Possible Errors
|
|
9
12
|
'no-console': ERROR,
|
|
@@ -210,11 +213,17 @@ const baseConfig = {
|
|
|
210
213
|
{
|
|
211
214
|
// Cypress config
|
|
212
215
|
files: [`**/cypress/**/*.{${allExtensions}}`],
|
|
216
|
+
// eslint-plugin-cypress doesn't support ESLint v8.
|
|
217
|
+
// Use fork by `@finsit` until this is solved.
|
|
218
|
+
// https://github.com/cypress-io/eslint-plugin-cypress/issues/89
|
|
219
|
+
extends: ['plugin:@finsit/cypress/recommended'],
|
|
213
220
|
env: {
|
|
214
|
-
'cypress/globals': true,
|
|
221
|
+
'@finsit/cypress/globals': true,
|
|
222
|
+
},
|
|
223
|
+
plugins: ['@finsit/cypress', 'rulesdir'],
|
|
224
|
+
rules: {
|
|
225
|
+
'rulesdir/unsafe-to-chain-command': ERROR,
|
|
215
226
|
},
|
|
216
|
-
extends: ['plugin:cypress/recommended'],
|
|
217
|
-
plugins: ['cypress'],
|
|
218
227
|
},
|
|
219
228
|
],
|
|
220
229
|
};
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-config-seek",
|
|
3
|
-
"version": "11.1.
|
|
3
|
+
"version": "11.1.3",
|
|
4
4
|
"description": "ESLint configuration used by SEEK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"index.js",
|
|
8
8
|
"base.js",
|
|
9
|
-
"extensions.js"
|
|
9
|
+
"extensions.js",
|
|
10
|
+
"rules/*"
|
|
10
11
|
],
|
|
11
12
|
"repository": {
|
|
12
13
|
"type": "git",
|
|
@@ -22,15 +23,16 @@
|
|
|
22
23
|
"@babel/core": "^7.21.0",
|
|
23
24
|
"@babel/eslint-parser": "^7.19.1",
|
|
24
25
|
"@babel/preset-react": "^7.18.6",
|
|
26
|
+
"@finsit/eslint-plugin-cypress": "^3.1.1",
|
|
25
27
|
"@typescript-eslint/eslint-plugin": "^5.53.0",
|
|
26
28
|
"@typescript-eslint/parser": "^5.53.0",
|
|
27
29
|
"eslint-config-prettier": "^8.6.0",
|
|
28
30
|
"eslint-import-resolver-typescript": "3.5.3",
|
|
29
|
-
"eslint-plugin-cypress": "^2.12.1",
|
|
30
31
|
"eslint-plugin-import": "^2.27.5",
|
|
31
32
|
"eslint-plugin-jest": "^27.2.1",
|
|
32
33
|
"eslint-plugin-react": "^7.32.2",
|
|
33
34
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
+
"eslint-plugin-rulesdir": "^0.2.2",
|
|
34
36
|
"find-root": "^1.1.0"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"eslint": ">=6",
|
|
45
47
|
"typescript": ">=4.5"
|
|
46
48
|
},
|
|
47
|
-
"packageManager": "pnpm@
|
|
49
|
+
"packageManager": "pnpm@8.5.1",
|
|
48
50
|
"volta": {
|
|
49
51
|
"node": "16.19.1"
|
|
50
52
|
},
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** This rule is copied from the original `eslint-plugin-cypress` so we can use the fork (which
|
|
2
|
+
* supports eslint 8) while having the same recommended rules as the upstream
|
|
3
|
+
* https://github.com/foretagsplatsen/eslint-plugin-cypress
|
|
4
|
+
* https://github.com/cypress-io/eslint-plugin-cypress/blob/c626ad543f65babf1def5caabd1bc9bb9900d2c7/lib/rules/unsafe-to-chain-command.js
|
|
5
|
+
*/
|
|
6
|
+
// eslint-disable-next-line strict
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
meta: {
|
|
11
|
+
docs: {
|
|
12
|
+
description: 'Actions should be in the end of chains, not in the middle',
|
|
13
|
+
category: 'Possible Errors',
|
|
14
|
+
recommended: true,
|
|
15
|
+
url: 'https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle',
|
|
16
|
+
},
|
|
17
|
+
schema: [],
|
|
18
|
+
messages: {
|
|
19
|
+
unexpected:
|
|
20
|
+
'It is unsafe to chain further commands that rely on the subject after this command. It is best to split the chain, chaining again from `cy.` in a next command line.',
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
return {
|
|
25
|
+
CallExpression(node) {
|
|
26
|
+
if (
|
|
27
|
+
isRootCypress(node) &&
|
|
28
|
+
isActionUnsafeToChain(node) &&
|
|
29
|
+
node.parent.type === 'MemberExpression'
|
|
30
|
+
) {
|
|
31
|
+
context.report({ node, messageId: 'unexpected' });
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function isRootCypress(node) {
|
|
39
|
+
while (node.type === 'CallExpression') {
|
|
40
|
+
if (node.callee.type !== 'MemberExpression') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (
|
|
45
|
+
node.callee.object.type === 'Identifier' &&
|
|
46
|
+
node.callee.object.name === 'cy'
|
|
47
|
+
) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// eslint-disable-next-line no-param-reassign
|
|
52
|
+
node = node.callee.object;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isActionUnsafeToChain(node) {
|
|
59
|
+
// commands listed in the documentation with text: 'It is unsafe to chain further commands that rely on the subject after xxx'
|
|
60
|
+
const unsafeToChainActions = [
|
|
61
|
+
'blur',
|
|
62
|
+
'clear',
|
|
63
|
+
'click',
|
|
64
|
+
'check',
|
|
65
|
+
'dblclick',
|
|
66
|
+
'each',
|
|
67
|
+
'focus',
|
|
68
|
+
'rightclick',
|
|
69
|
+
'screenshot',
|
|
70
|
+
'scrollIntoView',
|
|
71
|
+
'scrollTo',
|
|
72
|
+
'select',
|
|
73
|
+
'selectFile',
|
|
74
|
+
'spread',
|
|
75
|
+
'submit',
|
|
76
|
+
'type',
|
|
77
|
+
'trigger',
|
|
78
|
+
'uncheck',
|
|
79
|
+
'within',
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
node.callee &&
|
|
84
|
+
node.callee.property &&
|
|
85
|
+
node.callee.property.type === 'Identifier' &&
|
|
86
|
+
unsafeToChainActions.includes(node.callee.property.name)
|
|
87
|
+
);
|
|
88
|
+
}
|