eslint-plugin-cypress 6.1.0 → 6.2.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
CHANGED
|
@@ -33,7 +33,7 @@ import pluginCypress from 'eslint-plugin-cypress'
|
|
|
33
33
|
The configuration `eslint-plugin-cypress/flat`, which was deprecated in plugin version `5.0.0`, is no longer available.
|
|
34
34
|
Migrate to using the equivalent configuration `eslint-plugin-cypress` by dropping the `/flat` suffix.
|
|
35
35
|
|
|
36
|
-
Refer to ESLint `v10` [Configuration File Resolution](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-resolution) for
|
|
36
|
+
Refer to ESLint `v10` [Configuration File Resolution](https://eslint.org/docs/latest/use/configure/configuration-files#configuration-file-resolution) for hierarchical use of configuration files.
|
|
37
37
|
|
|
38
38
|
## Configurations
|
|
39
39
|
|
|
@@ -52,22 +52,23 @@ These rules enforce some of the [best practices recommended for using Cypress](h
|
|
|
52
52
|
<!-- begin auto-generated rules list -->
|
|
53
53
|
|
|
54
54
|
💼 Configurations enabled in.\
|
|
55
|
-
✅ Set in the `recommended` configuration
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
|
59
|
-
|
|
|
60
|
-
| [
|
|
61
|
-
| [no-
|
|
62
|
-
| [no-async-
|
|
63
|
-
| [no-
|
|
64
|
-
| [no-
|
|
65
|
-
| [no-
|
|
66
|
-
| [no-
|
|
67
|
-
| [no-
|
|
68
|
-
| [no-
|
|
69
|
-
| [
|
|
70
|
-
| [
|
|
55
|
+
✅ Set in the `recommended` configuration.\
|
|
56
|
+
❌ Deprecated.
|
|
57
|
+
|
|
58
|
+
| Name | Description | 💼 | ❌ |
|
|
59
|
+
| :----------------------------------------------------------------------- | :--------------------------------------------------------- | :- | :- |
|
|
60
|
+
| [assertion-before-screenshot](docs/rules/assertion-before-screenshot.md) | require screenshots to be preceded by an assertion | | |
|
|
61
|
+
| [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls | ✅ | |
|
|
62
|
+
| [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | | |
|
|
63
|
+
| [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases | ✅ | |
|
|
64
|
+
| [no-chained-get](docs/rules/no-chained-get.md) | disallow chain of `cy.get()` calls | | |
|
|
65
|
+
| [no-debug](docs/rules/no-debug.md) | disallow using `cy.debug()` calls | | |
|
|
66
|
+
| [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | | |
|
|
67
|
+
| [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | | |
|
|
68
|
+
| [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ | |
|
|
69
|
+
| [no-xpath](docs/rules/no-xpath.md) | disallow using `cy.xpath()` calls | | ❌ |
|
|
70
|
+
| [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | | |
|
|
71
|
+
| [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains | ✅ | |
|
|
71
72
|
|
|
72
73
|
<!-- end auto-generated rules list -->
|
|
73
74
|
<!-- prettier-ignore-end -->
|
package/docs/rules/no-xpath.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
📝 Disallow using `cy.xpath()` calls.
|
|
4
4
|
|
|
5
|
+
❌ This rule is deprecated. The reason for rule deprecation is the underlying deprecation and removal of support for the `@cypress/xpath` npm module in 2023. The rule is currently provided as a convenience to identify existing code that requires migration to supported API calls and it is planned for removal in a future major release of the plugin.
|
|
6
|
+
|
|
5
7
|
<!-- end auto-generated rule header -->
|
|
6
8
|
|
|
7
9
|
This rule disallows the usage of `cy.xpath()` for selecting elements.
|
|
@@ -20,11 +22,13 @@ Examples of **correct** code for this rule:
|
|
|
20
22
|
cy.get('[data-cy="container"]').click()
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
##
|
|
25
|
+
## Migration
|
|
24
26
|
|
|
25
27
|
Both [@cypress/xpath](https://www.npmjs.com/package/@cypress/xpath) and the earlier [cypress-xpath](https://www.npmjs.com/package/cypress-xpath) npm packages are deprecated and no longer supported.
|
|
26
28
|
These packages previously provided the command `cy.xpath()` and they should be uninstalled from the Cypress project after migrating `cy.xpath()` selection to `cy.get()`. See below for more details.
|
|
27
29
|
|
|
30
|
+
After migrating away from `cy.xpath()`, the rule can be set to `off` or can be permanently removed from the ESLint configuration.
|
|
31
|
+
|
|
28
32
|
## Further Reading
|
|
29
33
|
|
|
30
34
|
See [the Cypress Best Practices guide](https://docs.cypress.io/app/core-concepts/best-practices.html#Selecting-Elements).
|
|
@@ -10,6 +10,10 @@ Require `cy.get` to use only selectors that target `data-*` attributes.
|
|
|
10
10
|
|
|
11
11
|
## Rule Details
|
|
12
12
|
|
|
13
|
+
This rule checks the first parameter of each `cy.get`. It supports template literals, variable (re-)assignments and conditional expressions. For conditionals, all branches must conform to this rule.
|
|
14
|
+
|
|
15
|
+
Cypress aliases (as defined by `cy.as`) are always allowed.
|
|
16
|
+
|
|
13
17
|
Examples of **incorrect** code for this rule:
|
|
14
18
|
|
|
15
19
|
```js
|
|
@@ -18,9 +22,17 @@ cy.get('[daedta-cy=submit]').click()
|
|
|
18
22
|
cy.get('[d-cy=submit]')
|
|
19
23
|
cy.get('.btn-large').click()
|
|
20
24
|
cy.get('.btn-.large').click()
|
|
25
|
+
cy.get(condition ? "[data-cy=submit]" : ".btn-large")
|
|
21
26
|
|
|
22
27
|
const CLASS_SELECTOR = ".my-class";
|
|
23
28
|
cy.get(CLASS_SELECTOR)
|
|
29
|
+
|
|
30
|
+
const TYPE = 'submit'
|
|
31
|
+
const SUBMIT_TEMPLATE = `.${TYPE}`
|
|
32
|
+
cy.get(SUBMIT_TEMPLATE)
|
|
33
|
+
|
|
34
|
+
const MY_SUBMIT_TEMPLATE = SUBMIT_TEMPLATE;
|
|
35
|
+
cy.get(MY_SUBMIT_TEMPLATE)
|
|
24
36
|
```
|
|
25
37
|
|
|
26
38
|
Examples of **correct** code for this rule:
|
|
@@ -29,11 +41,17 @@ Examples of **correct** code for this rule:
|
|
|
29
41
|
cy.get('[data-cy=submit]').click()
|
|
30
42
|
cy.get('[data-QA=submit]')
|
|
31
43
|
cy.get(`[data-QA=submit]`)
|
|
32
|
-
|
|
44
|
+
cy.get(condition ? "[data-cy=submit]" : "[data-QA=submit]")
|
|
33
45
|
|
|
34
|
-
```js
|
|
35
46
|
const ASSESSMENT_SUBMIT = "[data-cy=assessment-submit]"
|
|
36
47
|
cy.get(ASSESSMENT_SUBMIT).click()
|
|
48
|
+
|
|
49
|
+
const TYPE = 'submit'
|
|
50
|
+
const SUBMIT_TEMPLATE = `[data-QA=${TYPE}]`
|
|
51
|
+
cy.get(SUBMIT_TEMPLATE)
|
|
52
|
+
|
|
53
|
+
const MY_SUBMIT_TEMPLATE = SUBMIT_TEMPLATE;
|
|
54
|
+
cy.get(MY_SUBMIT_TEMPLATE)
|
|
37
55
|
```
|
|
38
56
|
|
|
39
57
|
## Further Reading
|
package/lib/rules/no-xpath.js
CHANGED
|
@@ -15,6 +15,12 @@ module.exports = {
|
|
|
15
15
|
'cy.xpath() is deprecated and unsupported. '
|
|
16
16
|
+ 'Consider using cy.get() with appropriate selectors instead.',
|
|
17
17
|
},
|
|
18
|
+
deprecated: {
|
|
19
|
+
message:
|
|
20
|
+
'The reason for rule deprecation is the underlying deprecation and removal of support for the `@cypress/xpath` npm module in 2023. '
|
|
21
|
+
+ 'The rule is currently provided as a convenience to identify existing code that requires migration to supported API calls '
|
|
22
|
+
+ 'and it is planned for removal in a future major release of the plugin.',
|
|
23
|
+
},
|
|
18
24
|
},
|
|
19
25
|
|
|
20
26
|
create(context) {
|
|
@@ -19,18 +19,7 @@ module.exports = {
|
|
|
19
19
|
return {
|
|
20
20
|
VariableDeclarator(node) {
|
|
21
21
|
if (node.init && node.id && node.id.type === 'Identifier') {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (node.init.type === 'Literal' && typeof node.init.value === 'string') {
|
|
25
|
-
selectorValue = node.init.value
|
|
26
|
-
}
|
|
27
|
-
else if (node.init.type === 'TemplateLiteral'
|
|
28
|
-
&& node.init.expressions.length === 0
|
|
29
|
-
&& node.init.quasis.length === 1) {
|
|
30
|
-
selectorValue = node.init.quasis[0].value.cooked
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (selectorValue && isAliasOrDataSelector(selectorValue)) {
|
|
22
|
+
if (isDataNode(node.init, variablesSet)) {
|
|
34
23
|
variablesSet.add(node.id.name)
|
|
35
24
|
}
|
|
36
25
|
}
|
|
@@ -57,7 +46,10 @@ function isDataArgument(node, dataVariables) {
|
|
|
57
46
|
if (node.arguments.length === 0) return false
|
|
58
47
|
|
|
59
48
|
const firstArg = node.arguments[0]
|
|
49
|
+
return isDataNode(firstArg, dataVariables)
|
|
50
|
+
}
|
|
60
51
|
|
|
52
|
+
function isDataNode(firstArg, dataVariables) {
|
|
61
53
|
if (firstArg.type === 'Literal') {
|
|
62
54
|
return isAliasOrDataSelector(String(firstArg.value))
|
|
63
55
|
}
|
|
@@ -70,6 +62,11 @@ function isDataArgument(node, dataVariables) {
|
|
|
70
62
|
return dataVariables.has(firstArg.name)
|
|
71
63
|
}
|
|
72
64
|
|
|
65
|
+
if (firstArg.type === 'ConditionalExpression') {
|
|
66
|
+
return isDataNode(firstArg.consequent, dataVariables)
|
|
67
|
+
&& isDataNode(firstArg.alternate, dataVariables)
|
|
68
|
+
}
|
|
69
|
+
|
|
73
70
|
return false
|
|
74
71
|
}
|
|
75
72
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-cypress",
|
|
3
|
-
"version": "6.1
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "An ESLint plugin for projects using Cypress",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"exports": {
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@eslint/js": "^10.0.1",
|
|
38
|
-
"@stylistic/eslint-plugin": "^5.
|
|
39
|
-
"eslint": "^10.0.
|
|
38
|
+
"@stylistic/eslint-plugin": "^5.9.0",
|
|
39
|
+
"eslint": "^10.0.2",
|
|
40
40
|
"eslint-plugin-eslint-plugin": "^7.3.1",
|
|
41
41
|
"eslint-plugin-mocha": "^11.2.0",
|
|
42
42
|
"husky": "^9.1.7",
|
|
43
43
|
"prettier": "^3.8.1",
|
|
44
44
|
"semantic-release": "^25.0.3",
|
|
45
45
|
"typescript": "^5.9.3",
|
|
46
|
-
"typescript-eslint": "^8.56.
|
|
46
|
+
"typescript-eslint": "^8.56.1",
|
|
47
47
|
"vitest": "^4.0.18"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|