eslint-plugin-cypress 3.3.0 → 3.5.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
@@ -17,6 +17,10 @@ or
17
17
  yarn add eslint-plugin-cypress --dev
18
18
  ```
19
19
 
20
+ ## Deprecations
21
+
22
+ The use of ESLint `v7` with `eslint-plugin-cypress` is deprecated and support will be removed in a future version of this plugin. ESLint `v7` reached end-of-life on Apr 9, 2022 and users are encouraged to migrate to ESLint `v9`. See [ESLint Version Support](https://eslint.org/version-support/) for ESLint's current release lines.
23
+
20
24
  ## Usage
21
25
 
22
26
  If you are using ESLint `v7` or `v8`, then add an `.eslintrc.json` file to the root directory of your Cypress project with the contents shown below. You can continue to use this format with ESLint `v9` if you set the `ESLINT_USE_FLAT_CONFIG` environment variable to `false` (see [ESLint v9 > Configuration Files (Deprecated)](https://eslint.org/docs/latest/use/configure/configuration-files-deprecated).
@@ -42,7 +46,8 @@ You can add rules:
42
46
  "cypress/no-force": "warn",
43
47
  "cypress/no-async-tests": "error",
44
48
  "cypress/no-async-before": "error",
45
- "cypress/no-pause": "error"
49
+ "cypress/no-pause": "error",
50
+ "cypress/no-debug": "error"
46
51
  }
47
52
  }
48
53
  ```
@@ -129,6 +134,7 @@ These rules enforce some of the [best practices recommended for using Cypress](h
129
134
  | [no-assigning-return-values](docs/rules/no-assigning-return-values.md) | disallow assigning return values of `cy` calls | ✅ |
130
135
  | [no-async-before](docs/rules/no-async-before.md) | disallow using `async`/`await` in Cypress `before` methods | |
131
136
  | [no-async-tests](docs/rules/no-async-tests.md) | disallow using `async`/`await` in Cypress test cases | ✅ |
137
+ | [no-debug](docs/rules/no-debug.md) | disallow using `cy.debug()` calls | |
132
138
  | [no-force](docs/rules/no-force.md) | disallow using `force: true` with action commands | |
133
139
  | [no-pause](docs/rules/no-pause.md) | disallow using `cy.pause()` calls | |
134
140
  | [no-unnecessary-waiting](docs/rules/no-unnecessary-waiting.md) | disallow waiting for arbitrary time periods | ✅ |
@@ -0,0 +1,19 @@
1
+ # Disallow using `cy.debug()` calls (`cypress/no-debug`)
2
+
3
+ <!-- end auto-generated rule header -->
4
+ It is recommended to remove any [cy.debug](https://on.cypress.io/debug) commands before committing specs to avoid other developers getting unexpected results.
5
+
6
+ ## Rule Details
7
+
8
+ Examples of **incorrect** code for this rule:
9
+
10
+ ```js
11
+ cy.debug();
12
+ cy.get('selector').debug();
13
+ ```
14
+
15
+ Examples of **correct** code for this rule:
16
+
17
+ ```js
18
+ cy.get('selector')
19
+ ```
package/legacy.js CHANGED
@@ -11,6 +11,7 @@ module.exports = {
11
11
  'require-data-selectors': require('./lib/rules/require-data-selectors'),
12
12
  'no-force': require('./lib/rules/no-force'),
13
13
  'no-pause': require('./lib/rules/no-pause'),
14
+ 'no-debug': require('./lib/rules/no-debug'),
14
15
  },
15
16
  configs: {
16
17
  recommended: require('./lib/config/recommended'),
package/lib/flat.js CHANGED
@@ -14,6 +14,7 @@ const plugin = {
14
14
  'require-data-selectors': require('./rules/require-data-selectors'),
15
15
  'no-force': require('./rules/no-force'),
16
16
  'no-pause': require('./rules/no-pause'),
17
+ 'no-debug': require('./rules/no-debug'),
17
18
  },
18
19
  }
19
20
 
@@ -33,6 +34,7 @@ const commonLanguageOptions = {
33
34
 
34
35
  Object.assign(plugin.configs, {
35
36
  globals: {
37
+ name: 'cypress/globals',
36
38
  plugins: {
37
39
  cypress: plugin
38
40
  },
@@ -46,6 +48,7 @@ Object.assign(plugin.configs, {
46
48
 
47
49
  Object.assign(plugin.configs, {
48
50
  recommended: {
51
+ name: 'cypress/recommended',
49
52
  plugins: {
50
53
  cypress: plugin
51
54
  },
@@ -0,0 +1,61 @@
1
+ 'use strict'
2
+
3
+ //------------------------------------------------------------------------------
4
+ // Rule Definition
5
+ //------------------------------------------------------------------------------
6
+
7
+ module.exports = {
8
+ meta: {
9
+ type: 'suggestion',
10
+ docs: {
11
+ description: 'disallow using `cy.debug()` calls',
12
+ category: 'Possible Errors',
13
+ recommended: false,
14
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-debug.md',
15
+ },
16
+ fixable: null, // or "code" or "whitespace"
17
+ schema: [],
18
+ messages: {
19
+ unexpected: 'Do not use cy.debug command',
20
+ },
21
+ },
22
+
23
+ create (context) {
24
+
25
+ // variables should be defined here
26
+
27
+ //----------------------------------------------------------------------
28
+ // Helpers
29
+ //----------------------------------------------------------------------
30
+ function isCallingDebug (node) {
31
+ return node.callee &&
32
+ node.callee.property &&
33
+ node.callee.property.type === 'Identifier' &&
34
+ node.callee.property.name === 'debug'
35
+ }
36
+
37
+ function isCypressCall (node) {
38
+ if (!node.callee || node.callee.type !== 'MemberExpression') {
39
+ return false;
40
+ }
41
+ if (node.callee.object.type === 'Identifier' && node.callee.object.name === 'cy') {
42
+ return true;
43
+ }
44
+ return isCypressCall(node.callee.object);
45
+ }
46
+
47
+ //----------------------------------------------------------------------
48
+ // Public
49
+ //----------------------------------------------------------------------
50
+
51
+ return {
52
+
53
+ CallExpression (node) {
54
+ if (isCypressCall(node) && isCallingDebug(node)) {
55
+ context.report({ node, messageId: 'unexpected' })
56
+ }
57
+ },
58
+
59
+ }
60
+ },
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "3.3.0",
3
+ "version": "3.5.0",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "legacy.js",
6
6
  "exports": {
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const rule = require('../../../lib/rules/no-debug')
4
+ const RuleTester = require('eslint').RuleTester
5
+
6
+ const ruleTester = new RuleTester()
7
+
8
+ const errors = [{ messageId: 'unexpected' }]
9
+
10
+ ruleTester.run('no-debug', rule, {
11
+
12
+ valid: [
13
+ { code: `debug()` },
14
+ { code: `cy.get('button').dblclick()` },
15
+ ],
16
+
17
+ invalid: [
18
+ { code: `cy.debug()`, errors },
19
+ { code: `cy.debug({ log: false })`, errors },
20
+ { code: `cy.get('button').debug()`, errors },
21
+ { code: `cy.get('a').should('have.attr', 'href').and('match', /dashboard/).debug()`, errors }
22
+ ],
23
+ })