Skip to content

Commit

Permalink
Support ESLint 9
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Mar 30, 2024
1 parent f681f70 commit 2937f02
Show file tree
Hide file tree
Showing 24 changed files with 1,496 additions and 238 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# gulp-eslint-new · [![npm version][npm badge]][npm URL]

> A [gulp](https://gulpjs.com/) plugin to lint code with [ESLint](https://eslint.org/) 8
> A [gulp](https://gulpjs.com/) plugin to lint code with [ESLint](https://eslint.org/) 8 and 9.
## Installation

Make sure that you are using a version of Node.js [supported by ESLint 8](https://eslint.org/docs/user-guide/getting-started#prerequisites).
Make sure that you are using a version of Node.js supported by your version of ESLint.
See prerequisites for [ESLint 8](https://eslint.org/docs/latest/use/getting-started#prerequisites) and [ESLint 9](https://eslint.org/docs/next/use/getting-started#prerequisites).
For TypeScript support, you need TypeScript 4.6 or later.

To install gulp-eslint-new, [use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm):
Expand All @@ -13,8 +14,8 @@ To install gulp-eslint-new, [use](https://docs.npmjs.com/cli/install) [npm](http
npm i -D gulp-eslint-new
```

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

```console
Expand All @@ -23,12 +24,15 @@ npm i -D gulp-eslint-new eslint@8.8.0

## Migrating

If you are migrating from [gulp-eslint][gulp-eslint], you probably won't need to make any substantial changes to your gulp task. Note though that some options have changed: the current options are documented in the [`gulpESLintNew(options)`](#gulpeslintnewoptions) section.
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.
Note though that many options have changed: the current options are documented in the [`gulpESLintNew(options)`](#gulpeslintnewoptions) section.

Also, since gulp-eslint-new uses ESLint 8 while gulp-eslint sticks to ESLint 6, you may need to update your project to address incompatibilities between the versions of ESLint.
You can find more information at the links below.
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.
You can follow the links below for more information.
* [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)
* [Breaking changes for users from ESLint 7 to ESLint 8](https://eslint.org/docs/user-guide/migrating-to-8.0.0#breaking-changes-for-users)
* [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)
* [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)


## Usage

Expand Down Expand Up @@ -120,12 +124,16 @@ See the linked content for details about each option.

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

Newer versions of ESLint introduce a [new type of configuration](https://eslint.org/docs/user-guide/configuring/configuration-files-new) based on file `eslint.config.js`.
Starting with gulp-eslint-new 1.7 it is possible to use the new configuration by setting the option `configType` to `"flat"`.
ESLint supports two types of configuration: a [new config](https://eslint.org/docs/next/use/configure/configuration-files) type, aka flat config, based on file `eslint.config.*`, and a [legacy config](https://eslint.org/docs/next/use/configure/configuration-files-deprecated) type, or eslintrc config, based on file `.eslintrc`.

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.
To use the the new config with ESLint 8 in gulp-eslint-new, set the option `configType` to `"flat"`.

ESLint 9 uses the new config type by default.
To use the legacy config with ESLint 9 in gulp-eslint-new, set the option `configType` to `"eslintrc"`.

When using the new configuration, the options `ignorePath`, `reportUnusedDisableDirectives`, `resolvePluginsRelativeTo`, `rulePaths` and `useEslintrc` are no longer supported.
Also, `ignorePatterns` is supported as a new top-level option, while other options like `baseConfig`, `overrideConfig` and `overrideConfigFile` accept different values.
Refer to [the official documentation](https://eslint.org/docs/user-guide/configuring/configuration-files-new) for a description of all differences from the standard configuration.
The new and legacy config types differ significantly in the available options and their usage.
Refer to the respective documentation in ESLint for the specifics of each options.

##### `options.cwd`

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions example/config.js → example/eslint-8-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function loadConfig()
(
{
// Load a specific ESLint config.
overrideConfigFile: 'eslint-custom-config.json',
overrideConfigFile: 'custom-config/eslintrc-config.json',
},
),
)
Expand All @@ -103,7 +103,7 @@ function loadConfigShorthand()
{
return src('demo/**/*.js')
// Load a specific ESLint config
.pipe(gulpESLintNew('eslint-custom-config.json'))
.pipe(gulpESLintNew('custom-config/eslintrc-config.json'))
.pipe(gulpESLintNew.format());
}

Expand Down
19 changes: 11 additions & 8 deletions example/flat-config.js → example/eslint-8-flat-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

// npm install -D @eslint/eslintrc@2 @eslint/js@8 eslint@8 globals gulp gulp-eslint-new

const globals = require('globals');
const { series, src } = require('gulp');
const gulpESLintNew = require('gulp-eslint-new');
const { join } = require('path');
const { readFileSync } = require('fs');
const globals = require('globals');
const { series, src } = require('gulp');
const gulpESLintNew = require('gulp-eslint-new');
const { join } = require('path');

/**
* Simple example of using ESLint and a formatter.
Expand All @@ -24,7 +25,8 @@ function basic()
(
{
configType: 'flat',
cwd: join(__dirname, 'demo'), // Directory containing "eslint.config.js".
// Directory containing "eslint.config.js".
cwd: join(__dirname, 'demo'),
},
),
)
Expand Down Expand Up @@ -103,9 +105,10 @@ function loadConfig()
(
{
configType: 'flat',
cwd: join(__dirname, 'demo'), // Directory containing "eslint.config.js".
// Directory containing "eslint.config.js".
cwd: join(__dirname, 'demo'),
// Load a specific eslintrc config.
overrideConfig: compat.config(require('./eslint-custom-config.json')),
overrideConfig: compat.config(require('./custom-config/eslintrc-config.json')),
},
),
)
Expand All @@ -127,7 +130,7 @@ function loadFlatConfig()
{
configType: 'flat',
// Load a specific flat config.
overrideConfigFile: 'eslint-custom-flat-config.js',
overrideConfigFile: 'custom-config/flat-config.js',
},
),
)
Expand Down
171 changes: 171 additions & 0 deletions example/eslint-9-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
'use strict';

// npm install -D @eslint/eslintrc @eslint/js globals gulp gulp-eslint-new

const globals = require('globals');
const { series, src } = require('gulp');
const gulpESLintNew = require('gulp-eslint-new');
const { join } = require('path');

/**
* Simple example of using ESLint and a formatter.
* Note: ESLint does not write to the console itself.
* Use `format` or `formatEach` to print ESLint results.
*
* @returns {NodeJS.ReadWriteStream} gulp file stream.
*/
function basic()
{
return src('demo/**/*.js')
// Default: use local linting config.
.pipe
(
gulpESLintNew
(
{
// Directory containing "eslint.config.js".
cwd: join(__dirname, 'demo'),
},
),
)
// Format ESLint results and print them to the console.
.pipe(gulpESLintNew.format());
}

/**
* Inline ESLint configuration.
*
* @returns {NodeJS.ReadWriteStream} gulp file stream.
*/
function inlineConfig()
{
return src('demo/**/*.js')
.pipe
(
gulpESLintNew
(
{
overrideConfig:
{
rules:
{
'no-alert': 0,
'no-bitwise': 0,
'camelcase': 1,
'curly': 1,
'eqeqeq': 0,
'no-eq-null': 0,
'guard-for-in': 1,
'no-empty': 1,
'no-use-before-define': 0,
'no-obj-calls': 2,
'no-unused-vars': 0,
'new-cap': 1,
'no-shadow': 0,
'strict': 2,
'no-invalid-regexp': 2,
'comma-dangle': 2,
'no-undef': 1,
'no-new': 1,
'no-extra-semi': 1,
'no-debugger': 2,
'no-caller': 1,
'semi': 1,
'quotes': 0,
'no-unreachable': 2,
},
languageOptions: { globals: { $: 'readonly', ...globals.node } },
},
overrideConfigFile: 'demo/eslint.config.js',
warnIgnored: true,
},
),
)
.pipe(gulpESLintNew.format());
}

/**
* Load eslintrc configuration file.
*
* @returns {NodeJS.ReadWriteStream} gulp file stream.
*/
function loadEslintrcConfig()
{
const { FlatCompat } = require('@eslint/eslintrc');
const js = require('@eslint/js');
const compat =
new FlatCompat({ baseDirectory: __dirname, recommendedConfig: js.configs.recommended });
return src('demo/**/*.js')
.pipe
(
gulpESLintNew
(
{
// Directory containing "eslint.config.js".
cwd: join(__dirname, 'demo'),
// Load a specific eslintrc config.
overrideConfig: compat.config(require('./custom-config/eslintrc-config.json')),
},
),
)
.pipe(gulpESLintNew.format());
}

/**
* Load flat configuration file.
*
* @returns {NodeJS.ReadWriteStream} gulp file stream.
*/
function loadConfig()
{
return src('demo/**/*.js')
.pipe
(
gulpESLintNew
(
{
// Load a specific flat config.
overrideConfigFile: 'custom-config/flat-config.js',
},
),
)
.pipe(gulpESLintNew.format());
}

/**
* Shorthand way to load a configuration file.
*
* @returns {NodeJS.ReadWriteStream} gulp file stream.
*/
function loadConfigShorthand()
{
return src('demo/**/*.js')
// Load a specific ESLint config
.pipe(gulpESLintNew('custom-config/flat-config.js'))
.pipe(gulpESLintNew.format());
}

/**
* The default task will run all above tasks.
*/
module.exports =
{
'default':
series
(
basic,
inlineConfig,
loadEslintrcConfig,
loadConfig,
loadConfigShorthand,
async () => // eslint-disable-line require-await
{
console.log('All tasks completed successfully.');
},
),
'basic': basic,
'inline-config': inlineConfig,
'load-eslintrc-config': loadEslintrcConfig,
'load-config': loadConfig,
'load-config-shorthand': loadConfigShorthand,
};

0 comments on commit 2937f02

Please sign in to comment.