Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/eslint/eslint into eslint.c…
Browse files Browse the repository at this point in the history
…onfig.ts
  • Loading branch information
aryaemami59 committed May 9, 2024
2 parents 2bfe8b5 + 05ef92d commit 10d147e
Show file tree
Hide file tree
Showing 74 changed files with 1,678 additions and 372 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

"use strict";

const path = require("path");
const path = require("node:path");

const INTERNAL_FILES = {
CLI_ENGINE_PATTERN: "lib/cli-engine/**/*",
Expand Down
9 changes: 5 additions & 4 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
documentation:
- any:
- changed-files:
- all-globs-to-all-files: ['docs/**', '!lib/rules/**']
# Skipping this due to https://github.com/actions/labeler/issues/763
#documentation:
#- any:
# - changed-files:
# - all-globs-to-all-files: ['docs/**', '!lib/rules/**']

rule:
- any:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
run: node Makefile wdio
- name: Fuzz Test
run: node Makefile fuzz
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: logs
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
pull-requests: write

steps:
- uses: actions/stale@v8
- uses: actions/stale@v9
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-issue-stale: 30
Expand Down
8 changes: 4 additions & 4 deletions Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

const checker = require("npm-license"),
ReleaseOps = require("eslint-release"),
fs = require("fs"),
fs = require("node:fs"),
glob = require("glob"),
marked = require("marked"),
matter = require("gray-matter"),
os = require("os"),
path = require("path"),
os = require("node:os"),
path = require("node:path"),
semver = require("semver"),
ejs = require("ejs"),
loadPerf = require("load-perf"),
Expand Down Expand Up @@ -885,7 +885,7 @@ target.checkRuleFiles = function() {
};

target.checkRuleExamples = function() {
const { execFileSync } = require("child_process");
const { execFileSync } = require("node:child_process");

// We don't need the stack trace of execFileSync if the command fails.
try {
Expand Down
2 changes: 1 addition & 1 deletion bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function readStdin() {
function getErrorMessage(error) {

// Lazy loading because this is used only if an error happened.
const util = require("util");
const util = require("node:util");

// Foolproof -- third-party module might throw non-object.
if (typeof error !== "object" || error === null) {
Expand Down
2 changes: 1 addition & 1 deletion docs/.eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const pluginTOC = require("eleventy-plugin-nesting-toc");
const markdownItAnchor = require("markdown-it-anchor");
const markdownItContainer = require("markdown-it-container");
const Image = require("@11ty/eleventy-img");
const path = require("path");
const path = require("node:path");
const { slug } = require("github-slugger");
const yaml = require("js-yaml");
const { highlighter, lineNumberPlugin } = require("./src/_plugins/md-syntax-highlighter");
Expand Down
26 changes: 12 additions & 14 deletions docs/src/_data/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -633,13 +633,6 @@
"fixable": false,
"hasSuggestions": false
},
{
"name": "multiline-comment-style",
"description": "Enforce a particular style for multiline comments",
"recommended": false,
"fixable": true,
"hasSuggestions": false
},
{
"name": "new-cap",
"description": "Require constructor names to begin with a capital letter",
Expand Down Expand Up @@ -1384,13 +1377,6 @@
}
],
"layout": [
{
"name": "line-comment-position",
"description": "Enforce position of line comments",
"recommended": false,
"fixable": false,
"hasSuggestions": false
},
{
"name": "unicode-bom",
"description": "Require or disallow Unicode byte order mark (BOM)",
Expand Down Expand Up @@ -1567,6 +1553,12 @@
"fixable": true,
"hasSuggestions": false
},
{
"name": "line-comment-position",
"replacedBy": [],
"fixable": false,
"hasSuggestions": false
},
{
"name": "linebreak-style",
"replacedBy": [],
Expand Down Expand Up @@ -1605,6 +1597,12 @@
"fixable": false,
"hasSuggestions": false
},
{
"name": "multiline-comment-style",
"replacedBy": [],
"fixable": true,
"hasSuggestions": false
},
{
"name": "multiline-ternary",
"replacedBy": [],
Expand Down
4 changes: 4 additions & 0 deletions docs/src/_data/rules_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@
"fixable": "whitespace"
},
"line-comment-position": {
"deprecated": true,
"replacedBy": [],
"type": "layout",
"docs": {
"description": "Enforce position of line comments",
Expand Down Expand Up @@ -669,6 +671,8 @@
}
},
"multiline-comment-style": {
"deprecated": true,
"replacedBy": [],
"type": "suggestion",
"docs": {
"description": "Enforce a particular style for multiline comments",
Expand Down
4 changes: 2 additions & 2 deletions docs/src/_data/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const yaml = require("js-yaml");

//-----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/src/rules/line-comment-position.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: line-comment-position
rule_type: layout
---

This rule was **deprecated** in ESLint v9.3.0. Please use the [corresponding rule](https://eslint.style/rules/js/line-comment-position) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js).

Line comments can be positioned above or beside code. This rule helps teams maintain a consistent style.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/multiline-comment-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: multiline-comment-style
rule_type: suggestion
---


This rule was **deprecated** in ESLint v9.3.0. Please use the [corresponding rule](https://eslint.style/rules/js/multiline-comment-style) in [`@stylistic/eslint-plugin-js`](https://eslint.style/packages/js).

Many style guides require a particular style for comments that span multiple lines. For example, some style guides prefer the use of a single block comment for multiline comments, whereas other style guides prefer consecutive line comments.

Expand Down
57 changes: 41 additions & 16 deletions docs/src/rules/no-extra-boolean-cast.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ title: no-extra-boolean-cast
rule_type: suggestion
---





In contexts such as an `if` statement's test where the result of the expression will already be coerced to a Boolean, casting to a Boolean via double negation (`!!`) or a `Boolean` call is unnecessary. For example, these `if` statements are equivalent:

```js
Expand Down Expand Up @@ -88,16 +84,18 @@ var foo = bar ? !!baz : !!bat;

This rule has an object option:

* `"enforceForLogicalOperands"` when set to `true`, in addition to checking default contexts, checks whether the extra boolean cast is contained within a logical expression. Default is `false`, meaning that this rule by default does not warn about extra booleans cast inside logical expression.
* `"enforceForInnerExpressions"` when set to `true`, in addition to checking default contexts, checks whether extra boolean casts are present in expressions whose result is used in a boolean context. See examples below. Default is `false`, meaning that this rule by default does not warn about extra booleans cast inside inner expressions.

**Deprecated:** The object property `enforceForLogicalOperands` is deprecated ([eslint#18222](https://github.com/eslint/eslint/pull/18222)). Please use `enforceForInnerExpressions` instead.

### enforceForLogicalOperands
### enforceForInnerExpressions

Examples of **incorrect** code for this rule with `"enforceForLogicalOperands"` option set to `true`:
Examples of **incorrect** code for this rule with `"enforceForInnerExpressions"` option set to `true`:

::: incorrect

```js
/*eslint no-extra-boolean-cast: ["error", {"enforceForLogicalOperands": true}]*/
/*eslint no-extra-boolean-cast: ["error", {"enforceForInnerExpressions": true}]*/

if (!!foo || bar) {
//...
Expand All @@ -107,23 +105,38 @@ while (!!foo && bar) {
//...
}

if ((!!foo || bar) && baz) {
if ((!!foo || bar) && !!baz) {
//...
}

foo && Boolean(bar) ? baz : bat
var foo = new Boolean(!!bar || baz);

var foo = new Boolean(!!bar || baz)
foo && Boolean(bar) ? baz : bat;

const ternaryBranches = Boolean(bar ? !!baz : bat);

const nullishCoalescingOperator = Boolean(bar ?? Boolean(baz));

const commaOperator = Boolean((bar, baz, !!bat));

// another comma operator example
for (let i = 0; console.log(i), Boolean(i < 10); i++) {
// ...
}
```
:::
Examples of **correct** code for this rule with `"enforceForLogicalOperands"` option set to `true`:
Examples of **correct** code for this rule with `"enforceForInnerExpressions"` option set to `true`:
::: correct
```js
/*eslint no-extra-boolean-cast: ["error", {"enforceForLogicalOperands": true}]*/
/*eslint no-extra-boolean-cast: ["error", {"enforceForInnerExpressions": true}]*/

// Note that `||` and `&&` alone aren't a boolean context for either operand
// since the resultant value need not be a boolean without casting.
var foo = !!bar || baz;

if (foo || bar) {
//...
Expand All @@ -137,11 +150,23 @@ if ((foo || bar) && baz) {
//...
}

foo && bar ? baz : bat
var foo = new Boolean(bar || baz);

var foo = new Boolean(bar || baz)
foo && bar ? baz : bat;

var foo = !!bar || baz;
const ternaryBranches = Boolean(bar ? baz : bat);

const nullishCoalescingOperator = Boolean(bar ?? baz);

const commaOperator = Boolean((bar, baz, bat));

// another comma operator example
for (let i = 0; console.log(i), i < 10; i++) {
// ...
}

// comma operator in non-final position
Boolean((Boolean(bar), baz, bat));
```
:::
2 changes: 1 addition & 1 deletion docs/src/rules/no-return-await.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ further_reading:
- https://jakearchibald.com/2017/await-vs-return-vs-return-await/
---

This rule was **deprecated** in ESLint v8.46.0 with no replacement. The original intent of this rule no longer applies due to the fact JavaScript now handles native `Promises` differently. It can now be slower to remove `await` rather than keeping it. More technical information can be found in [this V8 blog entry](https://v8.dev/blog/fast-async).
This rule was **deprecated** in ESLint v8.46.0 with no replacement. The original intent of this rule was to discourage the use of `return await`, to avoid an extra microtask. However, due to the fact that JavaScript now handles native `Promise`s differently, there is no longer an extra microtask. More technical information can be found in [this V8 blog entry](https://v8.dev/blog/fast-async).

Using `return await` inside an `async function` keeps the current function in the call stack until the Promise that is being awaited has resolved, at the cost of an extra microtask before resolving the outer Promise. `return await` can also be used in a try/catch statement to catch errors from another function that returns a Promise.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/use/configure/configuration-files.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Each configuration object contains all of the information ESLint needs to execut

* `name` - A name for the configuration object. This is used in error messages and config inspector to help identify which configuration object is being used. ([Naming Convention](#configuration-naming-conventions))
* `files` - An array of glob patterns indicating the files that the configuration object should apply to. If not specified, the configuration object applies to all files matched by any other configuration object.
* `ignores` - An array of glob patterns indicating the files that the configuration object should not apply to. If not specified, the configuration object applies to all files matched by `files`.
* `ignores` - An array of glob patterns indicating the files that the configuration object should not apply to. If not specified, the configuration object applies to all files matched by `files`. If `ignores` is used without any other keys in the configuration object, then the patterns act as [global ignores](#globally-ignoring-files-with-ignores).
* `languageOptions` - An object containing settings related to how JavaScript is configured for linting.
* `ecmaVersion` - The version of ECMAScript to support. May be any year (i.e., `2022`) or version (i.e., `5`). Set to `"latest"` for the most recent supported version. (default: `"latest"`)
* `sourceType` - The type of JavaScript source code. Possible values are `"script"` for traditional script files, `"module"` for ECMAScript modules (ESM), and `"commonjs"` for CommonJS files. (default: `"module"` for `.js` and `.mjs` files; `"commonjs"` for `.cjs` files)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/use/configure/migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For reference information on these configuration formats, refer to the following

## Start Using Flat Config Files

Starting with ESLint v9.0.0, the flat config file format will be the default configuration file format. Once ESLint v9.0.0 is released, you can start using the flat config file format without any additional configuration.
The flat config file format has been the default configuration file format since ESLint v9.0.0. You can start using the flat config file format without any additional configuration.

To use flat config with ESLint v8, place a `eslint.config.js` file in the root of your project **or** set the `ESLINT_USE_FLAT_CONFIG` environment variable to `true`.

Expand Down
2 changes: 1 addition & 1 deletion docs/tools/validate-links.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const path = require("path");
const path = require("node:path");
const TapRender = require("@munter/tap-render");
const spot = require("tap-spot");
const hyperlink = require("hyperlink");
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const path = require("node:path");
const internalPlugin = require("eslint-plugin-internal-rules");
const eslintPluginRulesRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/rules-recommended");
const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/tests-recommended");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const defaultOptions = require("../../conf/default-cli-options");
const pkg = require("../../package.json");

Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/file-enumerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs");
const path = require("path");
const fs = require("node:fs");
const path = require("node:path");
const getGlobParent = require("glob-parent");
const isGlob = require("is-glob");
const escapeRegExp = require("escape-string-regexp");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/lint-result-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// Requirements
//-----------------------------------------------------------------------------

const assert = require("assert");
const fs = require("fs");
const assert = require("node:assert");
const fs = require("node:fs");
const fileEntryCache = require("file-entry-cache");
const stringify = require("json-stable-stringify-without-jsonify");
const pkg = require("../../package.json");
Expand Down
4 changes: 2 additions & 2 deletions lib/cli-engine/load-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
path = require("path");
const fs = require("node:fs"),
path = require("node:path");

const rulesDirCache = {};

Expand Down
6 changes: 3 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// Requirements
//------------------------------------------------------------------------------

const fs = require("fs"),
path = require("path"),
{ promisify } = require("util"),
const fs = require("node:fs"),
path = require("node:path"),
{ promisify } = require("node:util"),
{ LegacyESLint } = require("./eslint"),
{ ESLint, shouldUseFlatConfig, locateConfigFileToUse } = require("./eslint/eslint"),
createCLIOptions = require("./options"),
Expand Down
4 changes: 2 additions & 2 deletions lib/eslint/eslint-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
// Requirements
//-----------------------------------------------------------------------------

const path = require("path");
const fs = require("fs");
const path = require("node:path");
const fs = require("node:fs");
const fsp = fs.promises;
const isGlob = require("is-glob");
const hash = require("../cli-engine/hash");
Expand Down

0 comments on commit 10d147e

Please sign in to comment.