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 Mar 26, 2024
2 parents 0f8dc8a + dadc5bf commit 6eb0f88
Show file tree
Hide file tree
Showing 27 changed files with 871 additions and 148 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,19 @@
v9.0.0-rc.0 - March 22, 2024

* [`297416d`](https://github.com/eslint/eslint/commit/297416d2b41f5880554d052328aa36cd79ceb051) chore: package.json update for eslint-9.0.0-rc.0 (#18223) (Francesco Trotta)
* [`d363c51`](https://github.com/eslint/eslint/commit/d363c51b177e085b011c7fde1c5a5a09b3db9cdb) chore: package.json update for @eslint/js release (Jenkins)
* [`239a7e2`](https://github.com/eslint/eslint/commit/239a7e27209a6b861d634b3ef245ebbb805793a3) docs: Clarify the description of `sort-imports` options (#18198) (gyeongwoo park)
* [`09bd7fe`](https://github.com/eslint/eslint/commit/09bd7fe09ad255a263286e90accafbe2bf04ccfc) feat!: move AST traversal into SourceCode (#18167) (Nicholas C. Zakas)
* [`b91f9dc`](https://github.com/eslint/eslint/commit/b91f9dc072f17f5ea79803deb86cf002d031b4cf) build: fix TypeError in prism-eslint-hooks.js (#18209) (Francesco Trotta)
* [`4769c86`](https://github.com/eslint/eslint/commit/4769c86cc16e0b54294c0a394a1ec7ed88fc334f) docs: fix incorrect example in `no-lone-blocks` (#18215) (Tanuj Kanti)
* [`1b841bb`](https://github.com/eslint/eslint/commit/1b841bb04ac642c5ee84d1e44be3e53317579526) chore: fix some comments (#18213) (avoidaway)
* [`b8fb572`](https://github.com/eslint/eslint/commit/b8fb57256103b908712302ccd508f464eff1c9dc) feat: add `reportUnusedFallthroughComment` option to no-fallthrough rule (#18188) (Kirk Waiblinger)
* [`ae8103d`](https://github.com/eslint/eslint/commit/ae8103de69c12c6e71644a1de9589644e6767d15) fix: load plugins in the CLI in flat config mode (#18185) (Francesco Trotta)
* [`5251327`](https://github.com/eslint/eslint/commit/5251327711a2d7083e3c629cb8e48d9d1e809add) docs: Update README (GitHub Actions Bot)
* [`29c3595`](https://github.com/eslint/eslint/commit/29c359599c2ddd168084a2c8cbca626c51d0dc13) chore: remove repetitive words (#18193) (cuithon)
* [`1dc8618`](https://github.com/eslint/eslint/commit/1dc861897e8b47280e878d609c13c9e41892f427) docs: Update README (GitHub Actions Bot)
* [`acc2e06`](https://github.com/eslint/eslint/commit/acc2e06edd55eaab58530d891c0a572c1f0ec453) chore: Introduce Knip (#18005) (Lars Kappert)

v9.0.0-beta.2 - March 8, 2024

* [`7509276`](https://github.com/eslint/eslint/commit/75092764db117252067558bd3fbbf0c66ac081b7) chore: upgrade @eslint/js@9.0.0-beta.2 (#18180) (Milos Djermanovic)
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
@@ -1,7 +1,7 @@
{
"name": "docs-eslint",
"private": true,
"version": "9.0.0-beta.2",
"version": "9.0.0-rc.0",
"description": "",
"main": "index.js",
"keywords": [],
Expand Down
1 change: 1 addition & 0 deletions docs/src/extend/custom-formatters.md
Expand Up @@ -98,6 +98,7 @@ Each object in the `results` array is a `result` object. Each `result` object co
* **messages**: An array of [`message`](#the-message-object) objects. See below for more info about messages.
* **errorCount**: The number of errors for the given file.
* **warningCount**: The number of warnings for the given file.
* **stats**: The optional [`stats`](./stats#-stats-type) object that only exists when the `stats` option is used.
* **source**: The source code for the given file. This property is omitted if this file has no errors/warnings or if the `output` property is present.
* **output**: The source code for the given file with as many fixes applied as possible. This property is omitted if no fix is available.

Expand Down
2 changes: 2 additions & 0 deletions docs/src/extend/custom-rules.md
Expand Up @@ -938,3 +938,5 @@ quotes | 18.066 | 100.0%
```

To see a longer list of results (more than 10), set the environment variable to another value such as `TIMING=50` or `TIMING=all`.

For more granular timing information (per file per rule), use the [`stats`](./stats) option instead.
139 changes: 139 additions & 0 deletions docs/src/extend/stats.md
@@ -0,0 +1,139 @@
---
title: Stats Data
eleventyNavigation:
key: stats data
parent: extend eslint
title: Stats Data
order: 6
---

While an analysis of the overall rule performance for an ESLint run can be carried out by setting the [TIMING](./custom-rules#profile-rule-performance) environment variable, it can sometimes be useful to acquire more *granular* timing data (lint time per file per rule) or collect other measures of interest. In particular, when developing new [custom plugins](./plugins) and evaluating/benchmarking new languages or rule sets. For these use cases, you can optionally collect runtime statistics from ESLint.

## Enable stats collection

To enable collection of statistics, you can either:

1. Use the `--stats` CLI option. This will pass the stats data into the formatter used to output results from ESLint. (Note: not all formatters output stats data.)
1. Set `stats: true` as an option on the `ESLint` constructor.

Enabling stats data adds a new `stats` key to each [LintResult](../integrate/nodejs-api#-lintresult-type) object containing data such as parse times, fix times, lint times per rule.

As such, it is not available via stdout but made easily ingestible via a formatter using the CLI or via the Node.js API to cater to your specific needs.

## ◆ Stats type

The `Stats` value is the timing information of each lint run. The `stats` property of the [LintResult](../integrate/nodejs-api#-lintresult-type) type contains it. It has the following properties:

* `fixPasses` (`number`)<br>
The number of times ESLint has applied at least one fix after linting.
* `times` (`{ passes: TimePass[] }`)<br>
The times spent on (parsing, fixing, linting) a file, where the linting refers to the timing information for each rule.
* `TimePass` (`{ parse: ParseTime, rules?: Record<string, RuleTime>, fix: FixTime, total: number }`)<br>
An object containing the times spent on (parsing, fixing, linting)
* `ParseTime` (`{ total: number }`)<br>
The total time that is spent when parsing a file.
* `RuleTime` (`{ total: number }`)<be>
The total time that is spent on a rule.
* `FixTime` (`{ total: number }`)<be>
The total time that is spent on applying fixes to the code.

### CLI usage

Let's consider the following example:

```js [file-to-fix.js]
/*eslint no-regex-spaces: "error", wrap-regex: "error"*/

function a() {
return / foo/.test("bar");
}
```

Run ESLint with `--stats` and output to JSON via the built-in [`json` formatter](../use/formatters/):

```bash
npx eslint file-to-fix.js --fix --stats -f json
```

This yields the following `stats` entry as part of the formatted lint results object:

```json
{
"times": {
"passes": [
{
"parse": {
"total": 3.975959
},
"rules": {
"no-regex-spaces": {
"total": 0.160792
},
"wrap-regex": {
"total": 0.422626
}
},
"fix": {
"total": 0.080208
},
"total": 12.765959
},
{
"parse": {
"total": 0.623542
},
"rules": {
"no-regex-spaces": {
"total": 0.043084
},
"wrap-regex": {
"total": 0.007959
}
},
"fix": {
"total": 0
},
"total": 1.148875
}
]
},
"fixPasses": 1
}
```

Note, that for the simple example above, the sum of all rule times should be directly comparable to the first column of the TIMING output. Running the same command with `TIMING=all`, you can verify this:

```bash
$ TIMING=all npx eslint file-to-fix.js --fix --stats -f json
...
Rule | Time (ms) | Relative
:---------------|----------:|--------:
wrap-regex | 0.431 | 67.9%
no-regex-spaces | 0.204 | 32.1%
```

### API Usage

You can achieve the same thing using the Node.js API by passing`stats: true` as an option to the `ESLint` constructor. For example:

```js
const { ESLint } = require("eslint");

(async function main() {
// 1. Create an instance.
const eslint = new ESLint({ stats: true, fix: true });

// 2. Lint files.
const results = await eslint.lintFiles(["file-to-fix.js"]);

// 3. Format the results.
const formatter = await eslint.loadFormatter("json");
const resultText = formatter.format(results);

// 4. Output it.
console.log(resultText);
})().catch((error) => {
process.exitCode = 1;
console.error(error);
});
```
12 changes: 12 additions & 0 deletions docs/src/integrate/nodejs-api.md
Expand Up @@ -150,6 +150,8 @@ The `ESLint` constructor takes an `options` object. If you omit the `options` ob
Default is `null`. The plugin implementations that ESLint uses for the `plugins` setting of your configuration. This is a map-like object. Those keys are plugin IDs and each value is implementation.
* `options.ruleFilter` (`({ruleId: string, severity: number}) => boolean`)<br>
Default is `() => true`. A predicate function that filters rules to be run. This function is called with an object containing `ruleId` and `severity`, and returns `true` if the rule should be run.
* `options.stats` (`boolean`)<br>
Default is `false`. When set to `true`, additional statistics are added to the lint results (see [Stats type](../extend/stats#-stats-type)).

##### Autofix

Expand Down Expand Up @@ -367,6 +369,8 @@ The `LintResult` value is the information of the linting result of each file. Th
The modified source code text. This property is undefined if any fixable messages didn't exist.
* `source` (`string | undefined`)<br>
The original source code text. This property is undefined if any messages didn't exist or the `output` property exists.
* `stats` (`Stats | undefined`)<br>
The [Stats](../extend/stats#-stats-type) object. This contains the lint performance statistics collected with the `stats` option.
* `usedDeprecatedRules` (`{ ruleId: string; replacedBy: string[] }[]`)<br>
The information about the deprecated rules that were used to check this file.

Expand Down Expand Up @@ -715,6 +719,14 @@ const Linter = require("eslint").Linter;
Linter.version; // => '9.0.0'
```

### Linter#getTimes()

This method is used to get the times spent on (parsing, fixing, linting) a file. See `times` property of the [Stats](../extend/stats#-stats-type) object.

### Linter#getFixPassCount()

This method is used to get the number of autofix passes made. See `fixPasses` property of the [Stats](../extend/stats#-stats-type) object.

---

## RuleTester
Expand Down

0 comments on commit 6eb0f88

Please sign in to comment.