eslint-plugin-cypress 4.1.0 → 4.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/.node-version CHANGED
@@ -1 +1 @@
1
- 20.12.2
1
+ 22.11.0
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 20.12.2
1
+ 22.11.0
package/README.md CHANGED
@@ -54,6 +54,7 @@ These rules enforce some of the [best practices recommended for using Cypress](h
54
54
  | [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
55
55
  | [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
56
56
  | [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ |
57
+ | [no-xpath](docs/rules/no-xpath.md) | disallow using `cy.xpath()` calls | |
57
58
  | [require-data-selectors](docs/rules/require-data-selectors.md) | require `data-*` attribute selectors | |
58
59
  | [unsafe-to-chain-command](docs/rules/unsafe-to-chain-command.md) | disallow actions within chains | ✅ |
59
60
 
@@ -0,0 +1,25 @@
1
+ # Disallow using `cy.xpath()` calls (`cypress/no-xpath`)
2
+
3
+ <!-- end auto-generated rule header -->
4
+
5
+ This rule disallows the usage of `cy.xpath()` for selecting elements.
6
+
7
+ ## Rule Details
8
+
9
+ Examples of **incorrect** code for this rule:
10
+
11
+ ```js
12
+ cy.xpath('//div[@class=\"container\"]').click()
13
+ ```
14
+
15
+ Examples of **correct** code for this rule:
16
+
17
+ ```js
18
+ cy.get('[data-cy="container"]').click();
19
+ ```
20
+
21
+ ## Further Reading
22
+
23
+ Both `@cypress/xpath` and `cypress-xpath` are deprecated.
24
+
25
+ See [the Cypress Best Practices guide](https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements).
package/eslint.config.mjs CHANGED
@@ -1,13 +1,11 @@
1
1
  import globals from 'globals'
2
2
  import pluginJs from '@eslint/js'
3
3
  import eslintPlugin from 'eslint-plugin-eslint-plugin'
4
- import nodePlugin from 'eslint-plugin-n'
5
4
  import mochaPlugin from 'eslint-plugin-mocha'
6
5
 
7
6
  export default [
8
7
  pluginJs.configs.recommended,
9
8
  eslintPlugin.configs['flat/recommended'],
10
- nodePlugin.configs['flat/recommended-script'],
11
9
  mochaPlugin.configs.flat.recommended,
12
10
  {
13
11
  languageOptions: {
@@ -20,8 +18,6 @@ export default [
20
18
  'eslint-plugin/require-meta-docs-description': 'error',
21
19
  'eslint-plugin/meta-property-ordering': 'error',
22
20
  'eslint-plugin/test-case-property-ordering': 'error',
23
- 'n/no-extraneous-require':
24
- ['error', { 'allowModules': ['jest-config'] }],
25
21
  'mocha/no-mocha-arrows': 'off',
26
22
  'mocha/no-setup-in-describe': 'off'
27
23
  }
package/legacy.js CHANGED
@@ -12,6 +12,7 @@ module.exports = {
12
12
  'no-force': require('./lib/rules/no-force'),
13
13
  'no-pause': require('./lib/rules/no-pause'),
14
14
  'no-debug': require('./lib/rules/no-debug'),
15
+ 'no-xpath': require('./lib/rules/no-xpath'),
15
16
  },
16
17
  configs: {
17
18
  recommended: require('./lib/config/recommended'),
package/lib/flat.js CHANGED
@@ -15,6 +15,7 @@ const plugin = {
15
15
  'no-force': require('./rules/no-force'),
16
16
  'no-pause': require('./rules/no-pause'),
17
17
  'no-debug': require('./rules/no-debug'),
18
+ 'no-xpath': require('./rules/no-xpath'),
18
19
  },
19
20
  }
20
21
 
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ module.exports = {
4
+ meta: {
5
+ type: 'suggestion',
6
+ docs: {
7
+ description: 'disallow using `cy.xpath()` calls',
8
+ recommended: false,
9
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-xpath.md'
10
+ },
11
+ fixable: null, // Or `code` or `whitespace`
12
+ schema: [], // Add a schema if the rule has options
13
+ messages: {
14
+ unexpected: 'Avoid using cy.xpath command',
15
+ },
16
+ },
17
+
18
+ create (context) {
19
+ return {
20
+ CallExpression (node) {
21
+ if (isCallingCyXpath(node)) {
22
+ context.report({ node, messageId: 'unexpected' })
23
+ }
24
+ },
25
+ }
26
+ },
27
+ };
28
+
29
+ function isCallingCyXpath (node) {
30
+ return node.callee.type === 'MemberExpression' &&
31
+ node.callee.object.type === 'Identifier' &&
32
+ node.callee.object.name === 'cy' &&
33
+ node.callee.property.type === 'Identifier' &&
34
+ node.callee.property.name === 'xpath'
35
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "legacy.js",
6
6
  "exports": {
@@ -32,7 +32,6 @@
32
32
  "eslint": "^9.13.0",
33
33
  "eslint-plugin-eslint-plugin": "^6.3.1",
34
34
  "eslint-plugin-mocha": "^10.5.0",
35
- "eslint-plugin-n": "^17.11.1",
36
35
  "husky": "^9.1.6",
37
36
  "jest": "^29.7.0",
38
37
  "semantic-release": "24.2.0"
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Requirements
5
+ //------------------------------------------------------------------------------
6
+
7
+ const rule = require("../../../lib/rules/no-xpath"),
8
+ RuleTester = require("eslint").RuleTester;
9
+
10
+ //------------------------------------------------------------------------------
11
+ // Tests
12
+ //------------------------------------------------------------------------------
13
+
14
+ const ruleTester = new RuleTester();
15
+ ruleTester.run("no-xpath", rule, {
16
+ valid: [
17
+ { code: 'cy.get("button").click({force: true})' },
18
+ ],
19
+
20
+ invalid: [
21
+ {
22
+ code: "cy.xpath('//div[@class=\"container\"]/p[1]').click()",
23
+ errors: [{ messageId: "unexpected" }],
24
+ },
25
+ {
26
+ code: "cy.xpath('//p[1]').should('exist')",
27
+ errors: [{ messageId: "unexpected" }]
28
+ }
29
+ ],
30
+ });