eslint-plugin-cypress 6.0.0 → 6.2.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/README.md +18 -17
- package/docs/rules/no-xpath.md +9 -2
- package/docs/rules/require-data-selectors.md +14 -2
- package/lib/rules/no-xpath.js +10 -2
- package/lib/rules/require-data-selectors.js +4 -12
- package/package.json +4 -4
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,8 +22,13 @@ Examples of **correct** code for this rule:
|
|
|
20
22
|
cy.get('[data-cy="container"]').click()
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
##
|
|
25
|
+
## Migration
|
|
26
|
+
|
|
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.
|
|
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.
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
After migrating away from `cy.xpath()`, the rule can be set to `off` or can be permanently removed from the ESLint configuration.
|
|
31
|
+
|
|
32
|
+
## Further Reading
|
|
26
33
|
|
|
27
34
|
See [the Cypress Best Practices guide](https://docs.cypress.io/app/core-concepts/best-practices.html#Selecting-Elements).
|
|
@@ -21,6 +21,13 @@ cy.get('.btn-.large').click()
|
|
|
21
21
|
|
|
22
22
|
const CLASS_SELECTOR = ".my-class";
|
|
23
23
|
cy.get(CLASS_SELECTOR)
|
|
24
|
+
|
|
25
|
+
const TYPE = 'submit'
|
|
26
|
+
const SUBMIT_TEMPLATE = `.${TYPE}`
|
|
27
|
+
cy.get(SUBMIT_TEMPLATE)
|
|
28
|
+
|
|
29
|
+
const MY_SUBMIT_TEMPLATE = SUBMIT_TEMPLATE;
|
|
30
|
+
cy.get(MY_SUBMIT_TEMPLATE)
|
|
24
31
|
```
|
|
25
32
|
|
|
26
33
|
Examples of **correct** code for this rule:
|
|
@@ -29,11 +36,16 @@ Examples of **correct** code for this rule:
|
|
|
29
36
|
cy.get('[data-cy=submit]').click()
|
|
30
37
|
cy.get('[data-QA=submit]')
|
|
31
38
|
cy.get(`[data-QA=submit]`)
|
|
32
|
-
```
|
|
33
39
|
|
|
34
|
-
```js
|
|
35
40
|
const ASSESSMENT_SUBMIT = "[data-cy=assessment-submit]"
|
|
36
41
|
cy.get(ASSESSMENT_SUBMIT).click()
|
|
42
|
+
|
|
43
|
+
const TYPE = 'submit'
|
|
44
|
+
const SUBMIT_TEMPLATE = `[data-QA=${TYPE}]`
|
|
45
|
+
cy.get(SUBMIT_TEMPLATE)
|
|
46
|
+
|
|
47
|
+
const MY_SUBMIT_TEMPLATE = SUBMIT_TEMPLATE;
|
|
48
|
+
cy.get(MY_SUBMIT_TEMPLATE)
|
|
37
49
|
```
|
|
38
50
|
|
|
39
51
|
## Further Reading
|
package/lib/rules/no-xpath.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module.exports = {
|
|
4
4
|
meta: {
|
|
5
|
-
type: '
|
|
5
|
+
type: 'problem',
|
|
6
6
|
docs: {
|
|
7
7
|
description: 'disallow using `cy.xpath()` calls',
|
|
8
8
|
recommended: false,
|
|
@@ -11,7 +11,15 @@ module.exports = {
|
|
|
11
11
|
fixable: null, // Or `code` or `whitespace`
|
|
12
12
|
schema: [], // Add a schema if the rule has options
|
|
13
13
|
messages: {
|
|
14
|
-
unexpected:
|
|
14
|
+
unexpected:
|
|
15
|
+
'cy.xpath() is deprecated and unsupported. '
|
|
16
|
+
+ 'Consider using cy.get() with appropriate selectors instead.',
|
|
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.',
|
|
15
23
|
},
|
|
16
24
|
},
|
|
17
25
|
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-cypress",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
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": {
|