eslint-plugin-cypress 6.1.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 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 hierachical use of configuration files.
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
- | Name | Description | 💼 |
58
- | :----------------------------------------------------------------------- | :--------------------------------------------------------- | :- |
59
- | [assertion-before-screenshot](docs/rules/assertion-before-screenshot.md) | require screenshots to be preceded by an assertion | |
60
- | [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls | ✅ |
61
- | [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | |
62
- | [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases | ✅ |
63
- | [no-chained-get](docs/rules/no-chained-get.md) | disallow chain of `cy.get()` calls | |
64
- | [no-debug](docs/rules/no-debug.md) | disallow using `cy.debug()` calls | |
65
- | [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
66
- | [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
67
- | [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ |
68
- | [no-xpath](docs/rules/no-xpath.md) | disallow using `cy.xpath()` calls | |
69
- | [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | |
70
- | [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains | ✅ |
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 -->
@@ -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
- ## Deprecation and Support
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).
@@ -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
@@ -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
- let selectorValue = null
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.1.0",
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.8.0",
39
- "eslint": "^10.0.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.0",
46
+ "typescript-eslint": "^8.56.1",
47
47
  "vitest": "^4.0.18"
48
48
  },
49
49
  "scripts": {