Skip to content

Commit

Permalink
Merge pull request #234 from MikeMcC399/v9-only
Browse files Browse the repository at this point in the history
feat: minimum version eslint v9
  • Loading branch information
jennifer-shehane authored Oct 11, 2024
2 parents ce12040 + 061366e commit 47dc58f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 112 deletions.
14 changes: 6 additions & 8 deletions FLAT-CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@

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.

Usage with ESLint `8.57.0` and ESLint `9.x` is described.
Usage with ESLint `9.x` is described.

## Introduction

[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.

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`.

Cypress ESLint Plugin (`eslint-plugin-cypress`) in release [3.2.0](https://github.com/cypress-io/eslint-plugin-cypress/releases/tag/v3.2.0) offered the first support of ESLint `9.x` flat config files using the [Backwards compatibility utility](https://eslint.org/blog/2022/08/new-config-system-part-2/#backwards-compatibility-utility). Current releases have removed the dependency on this utility and the examples in this document have been updated correspondingly.

The following information details installation and usage examples for `eslint-plugin-cypress` together with related plugins in an ESLint flat config environment.

## Installation

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`.
Use a minimum ESLint `9.x`.

```shell
npm install eslint eslint-plugin-cypress --save-dev
Expand All @@ -38,10 +36,10 @@ import pluginCypress from 'eslint-plugin-cypress/flat'

There are two specific flat configurations available:

| Configuration | Content |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `configs.globals` | defines globals `cy`, `Cypress`, `expect`, `assert` and `chai` used in Cypress test specs as well as `globals.browser` and `globals.mocha` from [globals](https://www.npmjs.com/package/globals). Additionally, `languageOptions` of `ecmaVersion: 2019` and `sourceType: 'module'` for backwards compatibility with earlier versions of this plugin are defined. There are no default rules enabled in this configuration. |
| `configs.recommended` | enables [recommended Rules](README.md#rules). It includes also `configs.global` (see above) |
| Configuration | Content |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `configs.globals` | defines globals `cy`, `Cypress`, `expect`, `assert` and `chai` used in Cypress test specs as well as `globals.browser` and `globals.mocha` from [globals](https://www.npmjs.com/package/globals). This version no longer specifies `languageOptions` for `ecmaVersion` and `sourceType` - see ESLint [JavaScript languageOptions](https://eslint.org/docs/latest/use/configure/language-options#specifying-javascript-options). There are no default rules enabled in this configuration. |
| `configs.recommended` | enables [recommended Rules](README.md#rules). It includes also `configs.global` (see above) |

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.

Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Note: If you installed ESLint globally then you must also install `eslint-plugin

## Installation

Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v7`, `v8` or `v9`.
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.
Prerequisites: [ESLint](https://www.npmjs.com/package/eslint) `v9`. Lower versions are no longer supported.
This plugin supports the use of [Flat config files](https://eslint.org/docs/latest/use/configure/configuration-files) with ESLint `9.0.0` and above.

```sh
npm install eslint-plugin-cypress --save-dev
Expand All @@ -17,15 +17,11 @@ or
yarn add eslint-plugin-cypress --dev
```

## Deprecations

The use of ESLint `v7` and `v8` 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 ESLint `v8` reached end-of-life on Oct 5, 2024. Users are encouraged to migrate to ESLint `v9`. See [ESLint Version Support](https://eslint.org/version-support/) for ESLint's current release lines.

## Usage

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)).
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 [Flat config installation and configuration details](FLAT-CONFIG.md).

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`.)
You can continue to use a deprecated configuration `.eslintrc.json` 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)).

```json
{
Expand Down
23 changes: 0 additions & 23 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ workflows:
main:
jobs:
- lint
- test-v7
- test-v8
- test-v9
- release:
requires:
- lint
- test-v7
- test-v8
- test-v9
filters:
Expand All @@ -35,27 +33,6 @@ jobs:
name: Lint code
command: npm run lint

test-v7:
docker:
- image: cimg/node:20.12.2
steps:
- checkout
- run:
name: Install dependencies
command: npm ci
- run:
name: Remove unneeded plugins # minimum eslint@8.23.0 required
command: npm uninstall eslint-plugin-eslint-plugin eslint-plugin-n
- run:
name: Install ESLint 7
command: npm install eslint@7
- run:
name: Show ESLint version
command: npx eslint --version
- run:
name: Test ESLint 7
command: npm run test:legacy

test-v8:
docker:
- image: cimg/node:20.12.2
Expand Down
7 changes: 0 additions & 7 deletions lib/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ const commonGlobals =
chai: false,
}, globals.browser, globals.mocha)

const commonLanguageOptions = {
ecmaVersion: 2019,
sourceType: 'module'
}

Object.assign(plugin.configs, {
globals: {
name: 'cypress/globals',
Expand All @@ -41,7 +36,6 @@ Object.assign(plugin.configs, {
languageOptions: {
globals:
commonGlobals,
...commonLanguageOptions
}
}
})
Expand All @@ -61,7 +55,6 @@ Object.assign(plugin.configs, {
languageOptions: {
globals:
commonGlobals,
...commonLanguageOptions
}
}
})
Expand Down
124 changes: 63 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@
},
"homepage": "https://github.com/cypress-io/eslint-plugin-cypress#readme",
"peerDependencies": {
"eslint": ">=7"
"eslint": ">=9"
},
"dependencies": {
"globals": "^13.20.0"
"globals": "^15.11.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3.1.0",
"@eslint/js": "^9.11.1",
"eslint": "^9.12.0",
"eslint-plugin-eslint-plugin": "^6.2.0",
"eslint-plugin-mocha": "^10.5.0",
"eslint-plugin-n": "^17.10.3",
"eslint-plugin-n": "^17.11.1",
"husky": "^9.1.6",
"jest": "^29.7.0",
"semantic-release": "24.1.2"
Expand Down

0 comments on commit 47dc58f

Please sign in to comment.