eslint-plugin-cypress 3.1.0 → 3.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/FLAT-CONFIG.md ADDED
@@ -0,0 +1,134 @@
1
+ # Cypress ESLint Plugin - Flat Config
2
+
3
+ This document supplements the [README](README.md) document and describes how to use the Cypress ESLint Plugin (`eslint-plugin-cypress`) in an ESLint flat config environment.
4
+
5
+ Usage with ESLint `8.57.0` and ESLint `9.x` is described.
6
+
7
+ ## Introduction
8
+
9
+ [ESLint v9.0.0](https://eslint.org/blog/2024/04/eslint-v9.0.0-released/) was released on April 5, 2024, establishing flat config as the default for this version.
10
+
11
+ Previously, ESLint had announced in their blog post [Flat config rollout plans](https://eslint.org/blog/2023/10/flat-config-rollout-plans/) in October 2023 that flat config was planned to be the default in ESLint `v9.0.0` and that the eslintrc configuration system is planned to be removed in the future ESLint `v10.0.0`.
12
+
13
+ The Cypress ESLint Plugin (`eslint-plugin-cypress`) is currently based on ESLint `8.x` and has not yet been migrated to support Flat Config natively. [ESLint's new config system, Part 2: Introduction to flat config](https://eslint.org/blog/2022/08/new-config-system-part-2/) from August 2022 introduced the [Backwards compatibility utility](https://eslint.org/blog/2022/08/new-config-system-part-2/#backwards-compatibility-utility). This gives the capability to use `eslint-plugin-cypress` in an ESLint flat config environment.
14
+
15
+ The following information details installation and usage examples for `eslint-plugin-cypress` together with related plugins in an ESLint flat config environment.
16
+
17
+ ## Installation
18
+
19
+ It is recommended to use a minimum ESLint `8.x` version [eslint@8.57.0](https://github.com/eslint/eslint/releases/tag/v8.57.0) or ESLint `9.x`.
20
+
21
+ ```shell
22
+ npm install eslint @eslint/eslintrc eslint-plugin-cypress@^3.1.1 --save-dev
23
+ ```
24
+
25
+ or
26
+
27
+ ```shell
28
+ yarn add eslint @eslint/eslintrc eslint-plugin-cypress@^3.1.1 --dev
29
+ ```
30
+
31
+ ## Usage examples
32
+
33
+ Add a flat configuration file `eslint.config.mjs` file to the root directory of your Cypress project. In the following sections, different examples of possible configuration file contents are given, together with some brief explanations. Adapt these examples according to your needs.
34
+
35
+ ### Cypress
36
+
37
+ All rules from `eslint-plugin-cypress` are available through the `FlatCompat` class of [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc).
38
+ - [cypress/unsafe-to-chain-command](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/unsafe-to-chain-command.md) is active and set to `error`
39
+
40
+ ```js
41
+ import { FlatCompat } from '@eslint/eslintrc'
42
+ const compat = new FlatCompat()
43
+ export default [
44
+ ...compat.config(
45
+ {
46
+ plugins: ['cypress'],
47
+ rules: {
48
+ 'cypress/unsafe-to-chain-command': 'error'
49
+ }
50
+ })
51
+ ]
52
+ ```
53
+
54
+ ### Cypress recommended
55
+
56
+ The `eslint-plugin-cypress` [recommended rules](README.md#rules) `plugin:cypress/recommended` are activated, except for
57
+ - [cypress/no-unnecessary-waiting](https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/no-unnecessary-waiting.md) set to `off`
58
+
59
+ ```js
60
+ import { FlatCompat } from '@eslint/eslintrc'
61
+ const compat = new FlatCompat()
62
+ export default [
63
+ ...compat.config(
64
+ {
65
+ extends: ['plugin:cypress/recommended'],
66
+ rules: {
67
+ 'cypress/no-unnecessary-waiting': 'off'
68
+ }
69
+ })
70
+ ]
71
+ ```
72
+
73
+ ### Cypress and Mocha recommended
74
+
75
+ [eslint-plugin-mocha](https://www.npmjs.com/package/eslint-plugin-mocha) is added to the previous example. This plugin offers a flat file recommended option `configs.flat.recommended`.
76
+
77
+ The settings for individual `mocha` rules from the `configs.flat.recommended` option are changed.
78
+ - [mocha/no-exclusive-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-exclusive-tests.md) and [mocha/no-skipped-tests](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-skipped-tests.md) are set to `error` instead of `warn`
79
+ - [mocha/no-mocha-arrows](https://github.com/lo1tuma/eslint-plugin-mocha/blob/main/docs/rules/no-mocha-arrows.md) is set to `off` instead of `error`
80
+
81
+ ```shell
82
+ npm install eslint-plugin-mocha@^10.4.3 --save-dev
83
+ ```
84
+
85
+ ```js
86
+ import { FlatCompat } from '@eslint/eslintrc'
87
+ import mochaPlugin from 'eslint-plugin-mocha'
88
+ const compat = new FlatCompat()
89
+ export default [
90
+ mochaPlugin.configs.flat.recommended, {
91
+ rules: {
92
+ 'mocha/no-exclusive-tests': 'error',
93
+ 'mocha/no-skipped-tests': 'error',
94
+ 'mocha/no-mocha-arrows': 'off'
95
+ }
96
+ },
97
+ ...compat.config(
98
+ {
99
+ extends: ['plugin:cypress/recommended'],
100
+ rules: {
101
+ 'cypress/no-unnecessary-waiting': 'off'
102
+ }
103
+ })
104
+ ]
105
+ ```
106
+
107
+ ### Cypress and Chai recommended
108
+
109
+ [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) is combined with the Cypress plugin `eslint-plugin-cypress`.
110
+
111
+ The [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) plugin does not currently offer flat config options and so the `FlatCompat` class of [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc) enables this plugin to be used too. The recommended rules for both plugins are used: `plugin:cypress/recommended` and `plugin:chai-friendly/recommended`.
112
+
113
+ ```shell
114
+ npm install eslint-plugin-chai-friendly --save-dev
115
+ ```
116
+
117
+ ```js
118
+ import { FlatCompat } from '@eslint/eslintrc'
119
+ const compat = new FlatCompat()
120
+ export default [
121
+ ...compat.config(
122
+ {
123
+ extends: [
124
+ 'plugin:cypress/recommended',
125
+ 'plugin:chai-friendly/recommended'
126
+ ],
127
+ rules: {
128
+ 'cypress/no-unnecessary-waiting': 'off',
129
+ }
130
+ })
131
+ ]
132
+ ```
133
+
134
+ **Pending the resolution of issue https://github.com/ihordiachenko/eslint-plugin-chai-friendly/issues/32 [eslint-plugin-chai-friendly](https://www.npmjs.com/package/eslint-plugin-chai-friendly) cannot be used with ESLint `v9`.**
package/README.md CHANGED
@@ -6,7 +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.
9
+ Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v7`, `v8` or `v9`.
10
+ This plugin supports the use of [Flat config files](https://eslint.org/docs/latest/use/configure/configuration-files) with ESLint `8.57.0` and above through [@eslint/eslintrc](https://www.npmjs.com/package/@eslint/eslintrc).
10
11
 
11
12
  ```sh
12
13
  npm install eslint-plugin-cypress --save-dev
@@ -18,7 +19,9 @@ yarn add eslint-plugin-cypress --dev
18
19
 
19
20
  ## Usage
20
21
 
21
- Add an `.eslintrc.json` file to your `cypress` directory with the following:
22
+ 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).
23
+
24
+ ESLint `v9` uses a [Flat config file](https://eslint.org/docs/latest/use/configure/configuration-files) format with filename `eslint.config.*js` by default. Please refer to [additional Flat config installation and configuration details](FLAT-CONFIG.md). (You may also use this with ESLint `8.57.0`.)
22
25
 
23
26
  ```json
24
27
  {
@@ -0,0 +1,27 @@
1
+ import globals from 'globals'
2
+ import pluginJs from '@eslint/js'
3
+ import eslintPlugin from 'eslint-plugin-eslint-plugin'
4
+ import nodePlugin from 'eslint-plugin-n'
5
+ import mochaPlugin from 'eslint-plugin-mocha'
6
+
7
+ export default [
8
+ pluginJs.configs.recommended,
9
+ eslintPlugin.configs['flat/recommended'],
10
+ nodePlugin.configs['flat/recommended-script'],
11
+ mochaPlugin.configs.flat.recommended,
12
+ {
13
+ languageOptions: {
14
+ globals: globals.node
15
+ },
16
+ rules: {
17
+ 'no-redeclare': 'off',
18
+ 'eslint-plugin/require-meta-docs-url':
19
+ ['error', { 'pattern': 'https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md' }],
20
+ 'eslint-plugin/require-meta-docs-description': 'error',
21
+ 'n/no-extraneous-require':
22
+ ['error', { 'allowModules': ['jest-config'] }],
23
+ 'mocha/no-mocha-arrows': 'off',
24
+ 'mocha/no-setup-in-describe': 'off'
25
+ }
26
+ },
27
+ ]
@@ -19,7 +19,7 @@ const unsafeToChainActions = [
19
19
  'check',
20
20
  'dblclick',
21
21
  'each',
22
- 'focus$',
22
+ 'focus',
23
23
  'rightclick',
24
24
  'screenshot',
25
25
  'scrollIntoView',
@@ -130,7 +130,7 @@ const isRootCypress = (node) => {
130
130
  */
131
131
  const isActionUnsafeToChain = (node, additionalMethods = []) => {
132
132
  const unsafeActionsRegex = new RegExp([
133
- ...unsafeToChainActions,
133
+ ...unsafeToChainActions.map((action) => `^${action}$`),
134
134
  ...additionalMethods.map((method) => method instanceof RegExp ? method.source : method),
135
135
  ].join('|'))
136
136
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-cypress",
3
- "version": "3.1.0",
3
+ "version": "3.2.0",
4
4
  "description": "An ESLint plugin for projects using Cypress",
5
5
  "main": "index.js",
6
6
  "author": "Cypress-io",
@@ -19,16 +19,18 @@
19
19
  },
20
20
  "homepage": "https://github.com/cypress-io/eslint-plugin-cypress#readme",
21
21
  "peerDependencies": {
22
- "eslint": ">=7 <9"
22
+ "eslint": ">=7"
23
23
  },
24
24
  "dependencies": {
25
25
  "globals": "^13.20.0"
26
26
  },
27
27
  "devDependencies": {
28
+ "@eslint/eslintrc": "^3.0.2",
29
+ "@eslint/js": "^9.2.0",
28
30
  "eslint": "^8.57.0",
29
- "eslint-plugin-eslint-plugin": "^6.0.0",
31
+ "eslint-plugin-eslint-plugin": "^6.1.0",
30
32
  "eslint-plugin-mocha": "^10.4.3",
31
- "eslint-plugin-n": "^17.2.1",
33
+ "eslint-plugin-n": "^17.4.0",
32
34
  "husky": "^9.0.11",
33
35
  "jest": "^29.7.0",
34
36
  "semantic-release": "23.0.8"
@@ -18,6 +18,10 @@ ruleTester.run('action-ends-chain', rule, {
18
18
  code: 'cy.focused().should("be.visible");',
19
19
  parserOptions,
20
20
  },
21
+ {
22
+ code: 'cy.submitBtn().click();',
23
+ parserOptions,
24
+ },
21
25
  ],
22
26
 
23
27
  invalid: [
package/.eslintrc.js DELETED
@@ -1,30 +0,0 @@
1
- module.exports = {
2
- "env": {
3
- "node": true,
4
- "es6": true
5
- },
6
- "plugins": [
7
- "eslint-plugin",
8
- "n",
9
- "mocha"
10
- ],
11
- "extends": [
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", { "pattern": "https://github.com/cypress-io/eslint-plugin-cypress/blob/master/docs/rules/{{name}}.md" }],
20
- "eslint-plugin/require-meta-docs-description": "error",
21
- "n/no-extraneous-require":
22
- ["error", { "allowModules": ["jest-config"] }],
23
- "no-redeclare": "off",
24
- "mocha/no-mocha-arrows": "off",
25
- "mocha/no-setup-in-describe": "off"
26
- },
27
- "parserOptions": {
28
- "ecmaVersion": 2020
29
- }
30
- }