Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: v9.0.0 release post(s) #544

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@ As of ESLint v9,0.0, the [new configuration system](/blog/2023/10/flat-config-ro

## Give it a Try!

[ESLint Config Inspector](https://github.com/eslint/config-inspector) is a CLI command that fires up a local web server to visualize your ESLint configuration file from your local filesystem. You can give it a try by running the following command
in the root directory that contains `eslint.config.js` file:
[ESLint Config Inspector](https://github.com/eslint/config-inspector) is a CLI command that fires up a local web server to visualize your ESLint configuration file from your local filesystem. Give it a try:

```bash
eslint --inspect-config
```

Or you can run the config inspector without ESLint installed by running the following command in the root directory that contains `eslint.config.js` file:

```bash
npx @eslint/config-inspector
Expand Down
147 changes: 143 additions & 4 deletions src/content/blog/2024-04-05-eslint-v9.0.0-released.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ layout: post
title: ESLint v9.0.0 released
teaser: "We just pushed ESLint v9.0.0, which is a major release upgrade of ESLint. This release adds some new features and fixes several bugs found in the previous release. This release also has some breaking changes, so please read the following closely."
image: release-notes-major.png
draft: true
authors:
- eslintbot
- nzakas
categories:
- Release Notes
tags:
Expand All @@ -14,6 +13,148 @@ tags:



## Highlights

This is a summary of the significant changes, both breaking and non-breaking, you need to know about when upgrading from ESLint v8.x to ESLint v9.0.0.

### Installing

Because this is a major release, you may not automatically be upgraded by npm. To ensure you are using this version, run:

```
npm i [email protected] --save-dev
```

### Migration Guide

As there are a lot of changes, we've created a [migration guide](/docs/latest/use/migrate-to-9.0.0) describing the breaking changes in great detail along with the steps you should take to address them. We expect that most users should be able to upgrade without any build changes, but the migration guide should be a useful resource if you encounter problems.

### Node.js < v18.18.0, v19 no longer supported

As of this post, Node.js v20.x is the LTS release, and as such we are [dropping support](https://github.com/eslint/eslint/issues/17595) for all versions of Node.js prior to v18.18.0 as well as v19.x.

### Flat config is now the default and has some changes

Flat config is now the default configuration format for ESLint and eslintrc is officially deprecated. To continue using a eslintrc configuration file, you'll need to set the `ESLINT_USE_FLAT_CONFIG` environment variable to `false`.

This change affects users, plugin developers, and integrators as many aspects of ESLint had to change to make this happen. Please see [our previous blog post](/blog/2023/10/flat-config-rollout-plans/) for more details.

This release also introduces the [config inspector](/blog/2024/04/eslint-config-inspector/), which can be launched on the command line using `--inspect-config`.

### Removed all formatters except `stylish`, `html`, `json`, and `json-with-meta`

The following formatters have been removed:

* `checkstyle`
* `compact`
* `jslint-xml`
* `junit`
* `tap`
* `unix`
* `visualstudio`

If you are using these formatters currently, you'll need to install the [standalone packages](https://github.com/fregante/eslint-formatters) for use with ESLint v9.0.0.

### Removed `valid-jsdoc` and `require-jsdoc` rules

We have removed [`valid-jsdoc` and `require-jsdoc`](https://github.com/eslint/eslint/issues/15820). We recommend using the [`eslint-plugin-jsdoc`](https://github.com/gajus/eslint-plugin-jsdoc) plugin instead.

### Removed deprecated methods on `context` and `SourceCode`

As we [announced in September](https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/), we have removed a lot of deprecated methods from `context` and replaced them with methods on `SourceCode`.

### Updated `eslint:recommended`

The `eslint:recommended` configuration is updated to include new rules that we feel are important, and to remove deprecated and less important rules.

### New rule: `no-useless-assignment`

ESLint v9.0.0 introduces a new rule, [`no-useless-assignment`](https://eslint.org/docs/latest/rules/no-useless-assignment), that is designed to catch situations where you've assigned a value to a variable and that value is never used. For example:

```js
let id = 1234; // 1234 is never used
id = calculateId();
```

### Updates to existing rules

* The [`complexity`](/docs/latest/rules/complexity) rule now also takes into account optional chaining and default values in destructuring patterns and parameters.
* The [`no-fallthrough`](/docs/latest/rules/no-fallthrough) rule has a new option `reportUnusedFallthroughComment`.
* The [`no-inner-declarations`](/docs/latest/rules/no-inner-declarations) rule has a new default behavior. In v8.x, the rule would flag any functions defined inside of blocks as errors because this behavior was undefined in early versions of JavaScript. As of ES 2015, block-scoped function declarations are well-defined and so we changed the default behavior to not warn on block-scoped functions.
* The [`no-misleading-character-class`](/docs/latest/rules/no-misleading-character-class) rule now highlights the offending characters in a regular expression rather than the entire regular expression.
* The [`no-restricted-imports`](/docs/latest/rules/no-restricted-imports) rule changed the behavior of `paths`. In v8.x, if multiple entries in the `paths` array of your configuration for The [`no-restricted-imports`](/docs/latest/rules/no-restricted-imports) rule had the same `name` property, only the last one would apply. In v9.0.0, all entries apply, allowing for specifying different error messages for different imported names.
* The [`no-restricted-imports`](/docs/latest/rules/no-restricted-imports) rule has new options `allowImportNames` and `allowImportNamePattern`.
* The [`no-unused-vars`](/docs/latest/rules/no-unused-vars) rule `varsIgnorePattern` option no longer applies to caught error variables.
* The [`no-unused-vars`](/docs/latest/rules/no-unused-vars) rule has a new default value for the `caughtErrors` option (changed from `"none"` to `"all"`).
* The [`no-unused-vars`](/docs/latest/rules/no-unused-vars) rule has a new option `ignoreClassWithStaticInitBlock`.
* The [`no-useless-computed-key`](/docs/latest/rules/no-useless-computed-key) rule has a new default value for the `enforceForClassMembers` option (changed from `false` to `true`).
This is intended to help avoiding misleading comments that can occur as a result of refactoring.
When this option is set to `true`, the rule will prohibit a fallthrough comment if a case can never fallthrough.

### New API `loadESLint()`

ESLint now exports a new function [`loadESLint()`](/docs/latest/integrate/nodejs-api#loadeslint) from its main entry point. Integrations can use this function to get either the `ESLint` class (former `FlatESLint` class) or the `LegacyESLint` class (former `ESLint` class) and thus easily swap between flat config and eslintrc APIs.

### Stricter `RuleTester` validations

This release adds more checks in `RuleTester`:

* Messages cannot have unsubstituted placeholders.
* Suggestions must change the code.
* Test case `output` must be different from `code`.
* Test error objects must specify `message` or `messageId`.
* Test error object must specify `suggestions` if the actual error provides suggestions.
* Test suggestion objects must specify `desc` or `messageId`.
* Test suggestion objects must specify `output`.
* `filename` and `only` properties of test objects must be of the expected type (`string` and `boolean`, respectively).
* Duplicate tests cause an error.


### The `--output-file` flag now guarantees a file is output

The `--output-file` CLI flag is designed to output the results of the ESLint run to specified file. Prior to this release, no file would be output if linting passed with no errors or warnings. In v9.0.0, an empty file will be output when linting passes without any errors or warnings.

### Better scope analysis

In v9.0.0, we updated the behavior of `eslint-scope` to fix a couple of longstanding bugs:

1. Previously, ESLint would treat `("use strict")` as a strict mode directive even though it is not. We fixed the behavior so only valid strict mode directives are honored.
1. The containing scope of a class `extends` clause was incorrectly set to be the scope containing the class when it should have been the class scope itself. This has been fixed.

## `CodePath#currentSegments` removed

As announced in our [previous post](https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/#codepath%23currentsegments), `CodePath#currentSegments` has been removed from the rules API. Please refer to the post for more details.

### Precalculated Code Paths

ESLint v9.0.0 now precalculates code path information before the traversal used by rules. As a result, the code path information is now complete regardless of where it is accessed inside of a rule.

### Multiple `/* eslint */` comments for the same rule are now disallowed

In ESLint v8.x, if the file being linted contained multiple `/* eslint */` configuration comments for the same rule, the last one would be applied, while the others would be silently ignored.

In ESLint v9.0.0, the first one is applied, while the others are reported as lint errors.

### Changes to how you write rules

We've made multiple changes to help prevent errors in rules:

1. Function-style rules will stop working in v9.0.0. Function-style rules are rules created by exporting a function from a file rather than exporting an object with a `create()` method.
2. When a rule doesn't have `meta.schema` specified, a default schema of `[]` will be applied. This means that rules without a schema will be assumed to have no options, which in turn means that validation will fail if options are provided.
3. `RuleTester` now strictly checks that suggestion messages are unique for the same lint problem and ensures that suggestions generate valid syntax.

### `--quiet` option is more performant

The `--quiet` option hides all warnings in the ESLint console. In v9.0.0, we are making a performance improvement by also not executing any rules set to `"warn"`.

### Running `eslint` with no file arguments

If you are using flat config and you don't pass any file arguments to the CLI, the CLI will [default to linting the current directory](https://github.com/eslint/eslint/issues/14308), which means you can type `npx eslint` and it will just work. (Doing the same with an eslintrc config file will result in an error.)

### Unused disable directives cause warnings by default

ESLint has long been able to flag unused disable directives. In this release, we've enabled warnings for unused disable directives by default. You can modify this value in your config file with `linterOptions.reportUnusedDisableDirectives` or on the command line using `--report-unused-disable-directives-severity`.




Expand Down Expand Up @@ -279,5 +420,3 @@ tags:
* [`595a1f6`](https://github.com/eslint/eslint/commit/595a1f689edb5250d8398af13c3e4bd19d284d92) test: ensure that CLI tests run with FlatESLint ([#17884](https://github.com/eslint/eslint/issues/17884)) (Francesco Trotta)
* [`c7eca43`](https://github.com/eslint/eslint/commit/c7eca43202be98f6ff253b46c9a38602eeb92ea0) chore: update dependency markdownlint-cli to ^0.38.0 ([#17865](https://github.com/eslint/eslint/issues/17865)) (renovate[bot])
* [`cc0c9f7`](https://github.com/eslint/eslint/commit/cc0c9f707aa9da7965b98151868b3c249c7f8f30) ci: bump github/codeql-action from 2 to 3 ([#17873](https://github.com/eslint/eslint/issues/17873)) (dependabot[bot])