eslint-plugin-cypress 2.15.2 → 3.0.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/.eslintrc.json CHANGED
@@ -1,8 +1,39 @@
1
1
  {
2
+ "env": {
3
+ "node": true,
4
+ "es6": true
5
+ },
2
6
  "plugins": [
3
- "@cypress/dev"
7
+ "eslint-plugin",
8
+ "n",
9
+ "mocha"
4
10
  ],
5
11
  "extends": [
6
- "plugin:@cypress/dev/general"
7
- ]
12
+ "eslint:recommended",
13
+ "plugin:eslint-plugin/recommended",
14
+ "plugin:n/recommended",
15
+ "plugin:mocha/recommended"
16
+ ],
17
+ "rules": {
18
+ "eslint-plugin/require-meta-docs-url": [
19
+ "error",
20
+ {
21
+ "pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md"
22
+ }
23
+ ],
24
+ "n/no-extraneous-require": [
25
+ "error",
26
+ {
27
+ "allowModules": [
28
+ "jest-config"
29
+ ]
30
+ }
31
+ ],
32
+ "no-redeclare": "off",
33
+ "mocha/no-mocha-arrows": "off",
34
+ "mocha/no-setup-in-describe": "off"
35
+ },
36
+ "parserOptions": {
37
+ "ecmaVersion": 2018
38
+ }
8
39
  }
package/.node-version CHANGED
@@ -1 +1 @@
1
- 16.15.0
1
+ 20.12.2
package/.nvmrc CHANGED
@@ -1 +1 @@
1
- 16.15.0
1
+ 20.12.2
@@ -0,0 +1,16 @@
1
+ # Contributing to cypress-io/eslint-plugin-cypress
2
+
3
+ Thanks for taking the time to contribute! :smile:
4
+
5
+ To add a new rule:
6
+ * Fork and clone this repository
7
+ * Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
8
+ * Write test scenarios then implement logic
9
+ * Describe the rule in the generated `docs` file
10
+ * Run `npm test` to run [Jest](https://jestjs.io/) or
11
+ * Run `npm start` to run [Jest](https://jestjs.io/) in [watchAll](https://jestjs.io/docs/cli#--watchall) mode where it remains active and reruns when source changes are made
12
+ * Make sure all tests are passing
13
+ * Add the rule to the [README](README.md) file
14
+ * Create a PR
15
+
16
+ Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format
package/README.md CHANGED
@@ -6,6 +6,8 @@ Note: If you installed ESLint globally then you must also install `eslint-plugin
6
6
 
7
7
  ## Installation
8
8
 
9
+ Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v7` or `v8`. ESLint `v9` is **not** supported yet.
10
+
9
11
  ```sh
10
12
  npm install eslint-plugin-cypress --save-dev
11
13
  ```
@@ -115,8 +117,6 @@ These rules enforce some of the [best practices recommended for using Cypress](h
115
117
 
116
118
  Rules with a check mark (✅) are enabled by default while using the `plugin:cypress/recommended` config.
117
119
 
118
- **NOTE**: These rules currently require eslint 5.0 or greater. If you would like support added for eslint 4.x, please 👍 [this issue](https://github.com/cypress-io/eslint-plugin-cypress/issues/14).
119
-
120
120
  | | Rule ID | Description |
121
121
  | :-- | :------------------------------------------------------------------------- | :-------------------------------------------------------------- |
122
122
  | ✅ | [no-assigning-return-values](./docs/rules/no-assigning-return-values.md) | Prevent assigning return values of cy calls |
@@ -128,6 +128,44 @@ Rules with a check mark (✅) are enabled by default while using the `plugin:cyp
128
128
  | | [require-data-selectors](./docs/rules/require-data-selectors.md) | Only allow data-\* attribute selectors (require-data-selectors) |
129
129
  | | [no-pause](./docs/rules/no-pause.md) | Disallow `cy.pause()` parent command |
130
130
 
131
+ ## Mocha and Chai
132
+
133
+ Cypress is built on top of [Mocha](https://on.cypress.io/guides/references/bundled-libraries#Mocha) and [Chai](https://on.cypress.io/guides/references/bundled-libraries#Chai). See the following sections for information on using ESLint plugins [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) and [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) together with `eslint-plugin-cypress`.
134
+
135
+ ## Mocha `.only` and `.skip`
136
+
137
+ During test spec development, [Mocha exclusive tests](https://mochajs.org/#exclusive-tests) `.only` or [Mocha inclusive tests](https://mochajs.org/#inclusive-tests) `.skip` may be used to control which tests are executed, as described in the Cypress documentation [Excluding and Including Tests](https://on.cypress.io/guides/core-concepts/writing-and-organizing-tests#Excluding-and-Including-Tests). To apply corresponding rules, you can install and use [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha). The rule [mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) detects the use of `.only` and the [mocha/no-skipped-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-skipped-tests.md) rule detects the use of `.skip`:
138
+
139
+ ```sh
140
+ npm install --save-dev eslint-plugin-mocha
141
+ ```
142
+
143
+ In your `.eslintrc.json`:
144
+
145
+ ```json
146
+ {
147
+ "plugins": [
148
+ "cypress",
149
+ "mocha"
150
+ ],
151
+ "rules": {
152
+ "mocha/no-exclusive-tests": "warn",
153
+ "mocha/no-skipped-tests": "warn"
154
+ }
155
+ }
156
+ ```
157
+
158
+ Or you can simply use the `cypress/recommended` and `mocha/recommended` configurations together, for example:
159
+
160
+ ```json
161
+ {
162
+ "extends": [
163
+ "plugin:cypress/recommended",
164
+ "plugin:mocha/recommended"
165
+ ]
166
+ }
167
+ ```
168
+
131
169
  ## Chai and `no-unused-expressions`
132
170
 
133
171
  Using an assertion such as `expect(value).to.be.true` can fail the ESLint rule `no-unused-expressions` even though it's not an error in this case. To fix this, you can install and use [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly).
@@ -159,16 +197,6 @@ Or you can simply add its `recommended` config:
159
197
  }
160
198
  ```
161
199
 
162
- ## Contribution Guide
163
-
164
- To add a new rule:
165
- * Fork and clone this repository
166
- * Generate a new rule (a [yeoman generator](https://github.com/eslint/generator-eslint) is available)
167
- * Run `yarn start` or `npm start`
168
- * Write test scenarios then implement logic
169
- * Describe the rule in the generated `docs` file
170
- * Make sure all tests are passing
171
- * Add the rule to this README
172
- * Create a PR
200
+ ## Contributing
173
201
 
174
- Use the following commit message conventions: https://github.com/semantic-release/semantic-release#commit-message-format
202
+ Please see our [Contributing Guideline](./CONTRIBUTING.md) which explains how to contribute rules or other fixes and features to the repo.
package/circle.yml CHANGED
@@ -5,15 +5,13 @@ workflows:
5
5
  main:
6
6
  jobs:
7
7
  - lint
8
- - test-v4
9
- - test-v5
10
- - test-v6
8
+ - test-v7
9
+ - test-v8
11
10
  - release:
12
11
  requires:
13
12
  - lint
14
- - test-v4
15
- - test-v5
16
- - test-v6
13
+ - test-v7
14
+ - test-v8
17
15
  filters:
18
16
  branches:
19
17
  only:
@@ -22,64 +20,61 @@ workflows:
22
20
  jobs:
23
21
  lint:
24
22
  docker:
25
- - image: circleci/node:16
23
+ - image: cimg/node:20.12.2
26
24
  steps:
27
25
  - checkout
28
26
  - run:
29
27
  name: Install dependencies
30
28
  command: npm ci
29
+ - run:
30
+ name: Show ESLint version
31
+ command: npx eslint --version
31
32
  - run:
32
33
  name: Lint code
33
34
  command: npm run lint
34
35
 
35
- test-v4:
36
+ test-v7:
36
37
  docker:
37
- - image: circleci/node:16
38
+ - image: cimg/node:20.12.2
38
39
  steps:
39
40
  - checkout
40
41
  - run:
41
42
  name: Install dependencies
42
43
  command: npm ci
43
44
  - run:
44
- name: Install ESLint 4
45
- command: npm install eslint@4
46
- - run:
47
- name: Test ESLint 4
48
- command: npm test
49
-
50
- test-v5:
51
- docker:
52
- - image: circleci/node:16
53
- steps:
54
- - checkout
45
+ name: Remove unneeded plugins # minimum eslint@8.23.0 required
46
+ command: npm uninstall eslint-plugin-eslint-plugin eslint-plugin-n
55
47
  - run:
56
- name: Install dependencies
57
- command: npm ci
48
+ name: Install ESLint 7
49
+ command: npm install eslint@7
58
50
  - run:
59
- name: Install ESLint 5
60
- command: npm install eslint@5
51
+ name: Show ESLint version
52
+ command: npx eslint --version
61
53
  - run:
62
- name: Test ESLint 5
54
+ name: Test ESLint 7
63
55
  command: npm test
64
56
 
65
- test-v6:
57
+ test-v8:
66
58
  docker:
67
- - image: circleci/node:16
59
+ - image: cimg/node:20.12.2
68
60
  steps:
69
61
  - checkout
70
62
  - run:
71
63
  name: Install dependencies
72
64
  command: npm ci
73
65
  - run:
74
- name: Install ESLint 6
75
- command: npm install eslint@6
66
+ name: Install ESLint 8
67
+ command: npm install eslint@8
68
+ - run:
69
+ name: Show ESLint version
70
+ command: npx eslint --version
76
71
  - run:
77
- name: Test ESLint 6
72
+ name: Test ESLint 8
78
73
  command: npm test
79
74
 
80
75
  release:
81
76
  docker:
82
- - image: circleci/node:16
77
+ - image: cimg/node:20.12.2
83
78
  steps:
84
79
  - checkout
85
80
  - run:
package/index.js CHANGED
@@ -5,6 +5,7 @@ module.exports = {
5
5
  'no-assigning-return-values': require('./lib/rules/no-assigning-return-values'),
6
6
  'unsafe-to-chain-command': require('./lib/rules/unsafe-to-chain-command'),
7
7
  'no-unnecessary-waiting': require('./lib/rules/no-unnecessary-waiting'),
8
+ 'no-async-before': require('./lib/rules/no-async-before'),
8
9
  'no-async-tests': require('./lib/rules/no-async-tests'),
9
10
  'assertion-before-screenshot': require('./lib/rules/assertion-before-screenshot'),
10
11
  'require-data-selectors': require('./lib/rules/require-data-selectors'),
@@ -16,10 +16,12 @@ const assertionCommands = [
16
16
 
17
17
  module.exports = {
18
18
  meta: {
19
+ type: 'problem',
19
20
  docs: {
20
21
  description: 'Assert on the page state before taking a screenshot, so the screenshot is consistent',
21
22
  category: 'Possible Errors',
22
23
  recommended: false,
24
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/assertion-before-screenshot.md',
23
25
  },
24
26
  schema: [],
25
27
  messages: {
@@ -17,11 +17,12 @@ function get (obj, propertyString = '') {
17
17
 
18
18
  module.exports = {
19
19
  meta: {
20
+ type: 'problem',
20
21
  docs: {
21
22
  description: 'Prevent assigning return values of cy calls',
22
23
  category: 'Possible Errors',
23
24
  recommended: true,
24
- url: 'https://on.cypress.io/best-practices#Assigning-Return-Values',
25
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-assigning-return-values.md',
25
26
  },
26
27
  schema: [],
27
28
  messages: {
@@ -2,11 +2,14 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
7
  description: 'Prevent using async/await in Cypress before methods',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-before.md',
9
11
  },
12
+ schema: [],
10
13
  messages: {
11
14
  unexpected: 'Avoid using async functions with Cypress before / beforeEach functions',
12
15
  },
@@ -2,11 +2,14 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
7
  description: 'Prevent using async/await in Cypress test cases',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-async-tests.md',
9
11
  },
12
+ schema: [],
10
13
  messages: {
11
14
  unexpected: 'Avoid using async functions with Cypress tests',
12
15
  },
@@ -6,10 +6,12 @@
6
6
 
7
7
  module.exports = {
8
8
  meta: {
9
+ type: 'suggestion',
9
10
  docs: {
10
11
  description: 'Disallow using of \'force: true\' option for click and type calls',
11
12
  category: 'Possible Errors',
12
13
  recommended: false,
14
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-force.md',
13
15
  },
14
16
  fixable: null, // or "code" or "whitespace"
15
17
  schema: [],
@@ -6,10 +6,12 @@
6
6
 
7
7
  module.exports = {
8
8
  meta: {
9
+ type: 'suggestion',
9
10
  docs: {
10
11
  description: 'Disallow using of \'cy.pause\' calls',
11
12
  category: 'Possible Errors',
12
13
  recommended: false,
14
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-pause.md',
13
15
  },
14
16
  fixable: null, // or "code" or "whitespace"
15
17
  schema: [],
@@ -2,11 +2,12 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'problem',
5
6
  docs: {
6
7
  description: 'Prevent waiting for arbitrary time periods',
7
8
  category: 'Possible Errors',
8
9
  recommended: true,
9
- url: 'https://on.cypress.io/best-practices#Unnecessary-Waiting',
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md',
10
11
  },
11
12
  schema: [],
12
13
  messages: {
@@ -2,11 +2,12 @@
2
2
 
3
3
  module.exports = {
4
4
  meta: {
5
+ type: 'suggestion',
5
6
  docs: {
6
- description: 'Use data-* attributes to provide context to your selectors and insulate them from CSS or JS changes https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements',
7
+ description: 'Use data-* attributes to provide context to your selectors and insulate them from CSS or JS changes',
7
8
  category: 'Possible Errors',
8
9
  recommended: false,
9
- url: 'https://docs.cypress.io/guides/references/best-practices.html#Selecting-Elements',
10
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/require-data-selectors.md',
10
11
  },
11
12
  schema: [],
12
13
  messages: {
@@ -69,11 +69,12 @@ const getDefaultOptions = (context) => {
69
69
  /** @type {import('eslint').Rule.RuleModule} */
70
70
  module.exports = {
71
71
  meta: {
72
+ type: 'problem',
72
73
  docs: {
73
74
  description: DESCRIPTION,
74
75
  category: 'Possible Errors',
75
76
  recommended: true,
76
- url: 'https://docs.cypress.io/guides/core-concepts/retry-ability#Actions-should-be-at-the-end-of-chains-not-the-middle',
77
+ url: 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md',
77
78
  },
78
79
  schema: [schema],
79
80
  messages: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "2.15.2",
3
+ "version": "3.0.1",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "index.js",
6
6
  "author": "Cypress-io",
@@ -19,33 +19,27 @@
19
19
  },
20
20
  "homepage": "https://github.com/cypress-io/eslint-plugin-cypress#readme",
21
21
  "peerDependencies": {
22
- "eslint": ">= 3.2.1"
22
+ "eslint": ">=7 <9"
23
23
  },
24
24
  "dependencies": {
25
25
  "globals": "^13.20.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@cypress/eslint-plugin-dev": "3.2.0",
29
- "@cypress/eslint-plugin-json": "3.2.1",
30
- "eslint": "^5.7.0",
28
+ "eslint": "^8.57.0",
29
+ "eslint-plugin-eslint-plugin": "^6.0.0",
30
+ "eslint-plugin-mocha": "^10.4.3",
31
+ "eslint-plugin-n": "^17.2.1",
31
32
  "husky": "^8.0.3",
32
- "jest": "^24.8.0",
33
+ "jest": "^29.7.0",
33
34
  "semantic-release": "19.0.3"
34
35
  },
35
36
  "scripts": {
36
37
  "lint": "eslint \"*.js\" \"**/**/*.js\"",
37
38
  "lint-fix": "npm run lint -- --fix",
38
39
  "semantic-release": "semantic-release",
39
- "start": "yarn run test-watch",
40
+ "start": "npm run test-watch",
40
41
  "test": "jest",
41
- "test:v4": "npm i eslint@4.x && npm run test",
42
- "test:v6": "npm i eslint@6.x && npm run test",
43
42
  "test-watch": "jest --watchAll",
44
43
  "prepare": "husky install"
45
- },
46
- "jest": {
47
- "testMatch": [
48
- "**/tests/**/*.js"
49
- ]
50
44
  }
51
45
  }
@@ -15,7 +15,7 @@ ruleTester.run('require-data-selectors', rule, {
15
15
  { code: 'cy.clock(5000)', parserOptions },
16
16
  { code: 'cy.scrollTo(0, 10)', parserOptions },
17
17
  { code: 'cy.tick(500)', parserOptions },
18
- { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions },
18
+ { code: 'cy.get(\`[data-cy=${1}]\`)', parserOptions }, // eslint-disable-line no-useless-escape
19
19
  { code: 'cy.get("@my-alias")', parserOptions, errors },
20
20
  { code: 'cy.get(`@my-alias`)', parserOptions, errors },
21
21
  ],
@@ -26,6 +26,6 @@ ruleTester.run('require-data-selectors', rule, {
26
26
  { code: 'cy.get(".btn-large").click()', parserOptions, errors },
27
27
  { code: 'cy.get(".btn-.large").click()', parserOptions, errors },
28
28
  { code: 'cy.get(".a")', parserOptions, errors },
29
- { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors },
29
+ { code: 'cy.get(\`[daedta-cy=${1}]\`)', parserOptions, errors }, // eslint-disable-line no-useless-escape
30
30
  ],
31
31
  })