Skip to content

Commit 903c2f9

Browse files
committed
Update for ESLint 10
1 parent 6093274 commit 903c2f9

File tree

14 files changed

+2375
-1015
lines changed

14 files changed

+2375
-1015
lines changed

.github/workflows/nodejs.yml

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v5
20-
- uses: actions/setup-node@v5
19+
- uses: actions/checkout@v6
20+
- uses: actions/setup-node@v6
2121
with:
2222
node-version: 24
2323
- run: |
@@ -36,15 +36,35 @@ jobs:
3636
node-version: ['12', '14', '16']
3737

3838
steps:
39-
- uses: actions/checkout@v5
40-
- uses: actions/setup-node@v5
39+
- uses: actions/checkout@v6
40+
- uses: actions/setup-node@v6
4141
with:
4242
node-version: ${{ matrix.node-version }}
4343
- run: |
4444
npm ci
4545
npm install eslint@8
4646
npm test
4747
48+
test-eslint-8-and-9-only:
49+
50+
name: test (Node.js ${{ matrix.node-version }})
51+
52+
runs-on: ubuntu-latest
53+
54+
strategy:
55+
matrix:
56+
node-version: ['18']
57+
58+
steps:
59+
- uses: actions/checkout@v6
60+
- uses: actions/setup-node@v6
61+
with:
62+
node-version: ${{ matrix.node-version }}
63+
- run: |
64+
npm ci
65+
npm install eslint@9
66+
npm test
67+
4868
test:
4969

5070
name: test (Node.js ${{ matrix.node-version }})
@@ -53,13 +73,14 @@ jobs:
5373

5474
strategy:
5575
matrix:
56-
node-version: ['18', '20', '22', '24']
76+
node-version: ['20', '22', '24']
5777

5878
steps:
59-
- uses: actions/checkout@v5
60-
- uses: actions/setup-node@v5
79+
- uses: actions/checkout@v6
80+
- uses: actions/setup-node@v6
6181
with:
6282
node-version: ${{ matrix.node-version }}
6383
- run: |
6484
npm ci
85+
npm install eslint@10
6586
npm test

README.md

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# gulp-eslint-new · [![npm version][npm badge]][npm URL]
22

3-
> A [gulp](https://gulpjs.com/) plugin to lint code with [ESLint](https://eslint.org/) 8 and 9.
3+
> A [gulp](https://gulpjs.com/) plugin to lint code with [ESLint](https://eslint.org/) 8, 9, and 10.
44
55
## Installation
66

77
Make sure that you are using a version of Node.js supported by your version of ESLint.
8-
See prerequisites for [ESLint 8](https://eslint.org/docs/v8.x/use/getting-started#prerequisites) and [ESLint 9](https://eslint.org/docs/v9.x/use/getting-started#prerequisites).
8+
See prerequisites for [ESLint 8](https://eslint.org/docs/v8.x/use/getting-started#prerequisites), [ESLint 9](https://eslint.org/docs/v9.x/use/getting-started#prerequisites), or [ESLint 10](https://eslint.org/docs/v10.x/use/getting-started#prerequisites).
99
For TypeScript support, you need TypeScript 4.8 or later.
1010

1111
To install gulp-eslint-new, [use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm):
@@ -14,24 +14,25 @@ To install gulp-eslint-new, [use](https://docs.npmjs.com/cli/install) [npm](http
1414
npm i -D gulp-eslint-new
1515
```
1616

17-
gulp-eslint-new will also install the latest version of ESLint 9, unless another one is found.
17+
gulp-eslint-new will also install the latest version of ESLint 10, unless another one is found.
1818
To use a particular version of ESLint, install it by yourself.
19-
For example, to use ESLint 8.8.0:
19+
For example, to use ESLint 8.57.1:
2020

2121
```console
22-
npm i -D gulp-eslint-new eslint@8.8.0
22+
npm i -D gulp-eslint-new eslint@8.57.1
2323
```
2424

2525
## Migrating
2626

2727
If you are migrating from [gulp-eslint][gulp-eslint], you probably won't need to make any substantial changes to your gulp task, as the API is widely compatible.
2828
Note though that many options have changed: the current options are documented in the [`gulpESLintNew(options)`](#gulpeslintnewoptions) section.
2929

30-
Also note that gulp-eslint-new is designed to work with ESLint 8 or 9, whereas the latest release of gulp-eslint only supports ESLint 6: you will need to update your project to address breaking changes in ESLint.
30+
Also note that gulp-eslint-new is designed to work with ESLint 8, 9 or 10, whereas the latest release of gulp-eslint only supports ESLint 6: you will need to update your project to address breaking changes in ESLint.
3131
You can follow the links below for more information.
3232
* [Breaking changes for users from ESLint 6 to ESLint 7](https://eslint.org/docs/user-guide/migrating-to-7.0.0#breaking-changes-for-users)
3333
* [Breaking changes for users from ESLint 7 to ESLint 8](https://eslint.org/docs/user-guide/migrate-to-8.0.0#breaking-changes-for-users)
3434
* [Breaking changes for users from ESLint 8 to ESLint 9](https://eslint.org/docs/user-guide/migrate-to-9.0.0#breaking-changes-for-users)
35+
* [Breaking changes for users from ESLint 9 to ESLint 10](https://eslint.org/docs/user-guide/migrate-to-10.0.0#breaking-changes-for-users)
3536

3637

3738
## Usage
@@ -149,15 +150,13 @@ See the linked content for details about each option.
149150

150151
Type: `"eslintrc" | "flat" | null`
151152

152-
ESLint supports two types of configuration: a [new config](https://eslint.org/docs/user-guide/configure/configuration-files) type, aka flat config, based on file `eslint.config.*`, and a [legacy config](https://eslint.org/docs/user-guide/configure/configuration-files-deprecated) type, or eslintrc config, based on file `.eslintrc`.
153+
ESLint supports two configuration formats: a [new config](https://eslint.org/docs/user-guide/configure/configuration-files) type, aka flat config, based on file `eslint.config.*`, and a [legacy config](https://eslint.org/docs/user-guide/configure/configuration-files-deprecated) type, or eslintrc config, based on file `.eslintrc`.
153154

154-
In ESLint 8, the default config type is the legacy config, and the new config is partly supported depending on the version of ESLint used.
155-
To use the the new config with ESLint 8 in gulp-eslint-new, set the option `configType` to `"flat"`.
155+
* **ESLint 8**: Uses the legacy config by default. Flat config is partially supported depending on the version. In gulp-eslint-new, set `configType: "flat"` to enable flat config.
156+
* **ESLint 9**: Uses flat config by default. To use legacy config in gulp-eslint-new, set `configType: "eslintrc"`.
157+
* **ESLint 10**: Only supports flat config. Setting `configType: "eslintrc"` in gulp-eslint-new will result in an error.
156158

157-
ESLint 9 uses the new config type by default.
158-
To use the legacy config with ESLint 9 in gulp-eslint-new, set the option `configType` to `"eslintrc"`.
159-
160-
The new and legacy config types differ significantly in the available options and their usage.
159+
The new and legacy config formats differ significantly in the available options and their usage.
161160
Refer to the respective documentation in ESLint for the specifics of each options.
162161

163162
##### `options.cwd`

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ createConfig
1212
files: ['**/*.js'],
1313
jsVersion: 2020,
1414
languageOptions: { sourceType: 'script' },
15+
rules: { 'object-shorthand': ['error', 'always', { avoidQuotes: true }] },
1516
},
1617
{
1718
files: ['test/*.spec.js'],

lib/eslint.d.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,40 @@
11
import type { ESLint, Linter } from 'eslint';
22

3-
type ESLintrcOptions = ESLint.LegacyOptions;
3+
interface ESLintrcOptions
4+
{
5+
// File enumeration
6+
cwd?: string | undefined;
7+
errorOnUnmatchedPattern?: boolean | undefined;
8+
extensions?: string[] | undefined;
9+
globInputPaths?: boolean | undefined;
10+
ignore?: boolean | undefined;
11+
ignorePath?: string | undefined;
12+
13+
// Linting
14+
allowInlineConfig?: boolean | undefined;
15+
baseConfig?: Linter.LegacyConfig | undefined;
16+
overrideConfig?: Linter.LegacyConfig | undefined;
17+
overrideConfigFile?: string | undefined;
18+
plugins?: Record<string, ESLint.Plugin> | undefined;
19+
reportUnusedDisableDirectives?: Linter.StringSeverity | undefined;
20+
resolvePluginsRelativeTo?: string | undefined;
21+
rulePaths?: string[] | undefined;
22+
useEslintrc?: boolean | undefined;
23+
24+
// Autofix
25+
fix?:
26+
boolean | ((message: Linter.LintMessage) => boolean) | undefined;
27+
fixTypes?: FixType[] | null | undefined;
28+
29+
// Caching
30+
cache?: boolean | undefined;
31+
cacheLocation?: string | undefined;
32+
cacheStrategy?: ESLint.CacheStrategy | undefined;
33+
34+
// Unused
35+
flags?: string[] | undefined;
36+
}
37+
438
type FlatESLintOptions = ESLint.Options;
539
type FormatterFunction = ESLint.FormatterFunction;
640
type LintMessage = Linter.LintMessage;

lib/util.js

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ exports.hasOwn = hasOwn;
259259

260260
exports.isErrorMessage = isErrorMessage;
261261

262+
exports.isEslintrcESLintConstructor = isEslintrcESLintConstructor;
263+
262264
exports.isWarningMessage = isWarningMessage;
263265

264266
const makeNPMLink =
@@ -286,21 +288,35 @@ const FORBIDDEN_OPTIONS =
286288

287289
const requireESLint = eslintPkg => require(eslintPkg).ESLint;
288290

291+
function requireEslintrcESLint(eslintPkg)
292+
{
293+
const { LegacyESLint } = require(`${eslintPkg}/use-at-your-own-risk`);
294+
if (LegacyESLint) return LegacyESLint;
295+
296+
const { satisfies } = require('semver');
297+
const { ESLint } = require(eslintPkg);
298+
if (satisfies(ESLint.version, '8')) return ESLint;
299+
300+
const message =
301+
'The version of ESLint you are using does not support eslintrc config. ' +
302+
'Eslintrc config is not available in ESLint 10.';
303+
throw Error(message);
304+
}
305+
289306
function requireFlatESLint(eslintPkg)
290307
{
291308
const { FlatESLint } = require(`${eslintPkg}/use-at-your-own-risk`);
292-
if (FlatESLint == null)
293-
{
294-
const message =
295-
'The version of ESLint you are using does not support flat config. ' +
296-
'To use flat config, upgrade to ESLint 8.21 or later.';
297-
throw Error(message);
298-
}
299-
return FlatESLint;
300-
}
309+
if (FlatESLint) return FlatESLint;
301310

302-
const requireEslintrcESLint =
303-
eslintPkg => require(`${eslintPkg}/use-at-your-own-risk`).LegacyESLint || require(eslintPkg).ESLint;
311+
const { satisfies } = require('semver');
312+
const { ESLint } = require(eslintPkg);
313+
if (!satisfies(ESLint.version, '8')) return ESLint;
314+
315+
const message =
316+
'The version of ESLint you are using does not support flat config. ' +
317+
'Flat config is available in ESLint 8.21 or later.';
318+
throw Error(message);
319+
}
304320

305321
/**
306322
* Throws an error about invalid options passed to gulp-eslint-new.
@@ -402,15 +418,23 @@ async ({ cwd, eslint }, formatter) =>
402418
if (formatter === undefined)
403419
{
404420
const { format } = await eslint.loadFormatter();
405-
return {
406-
format: results =>
407-
format(results)
408-
.replace
409-
(
410-
/ with the `--fix` option\.(?=(\u001b\[\d+m|\n)+$)/,
411-
` - see ${makeNPMLink('autofix')}`,
412-
),
421+
const formatterObj =
422+
{
423+
format:
424+
results =>
425+
{
426+
const stylishText = format(results);
427+
const text =
428+
stylishText
429+
.replace
430+
(
431+
/ with the `--fix` option\.(?=(\u001b\[\d+m|\n)+$)/,
432+
` - see ${makeNPMLink('autofix')}`,
433+
);
434+
return text;
435+
},
413436
};
437+
return formatterObj;
414438
}
415439
if (isObject(formatter) && typeof formatter.format === 'function')
416440
return formatter;

0 commit comments

Comments
 (0)