You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: designs/2025-bulk-suppressions-api/README.md
+41-28Lines changed: 41 additions & 28 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,28 +23,40 @@ This RFC aims to resolve this discrepancy by adding support for bulk suppression
23
23
24
24
This proposal integrates the existing bulk suppression functionality into the `ESLint` and `LegacyESLint` Node.js API classes by leveraging the internal `SuppressionsService`. A new `suppressionsLocation` option is introduced in the constructors.
25
25
26
-
1. New Constructor Option (`suppressionsLocation`)
27
-
- Both `ESLintOptions` and `LegacyESLintOptions` will accept a new optional property: `suppressionsLocation`.
28
-
-`suppressionsLocation: string | undefined`: Specifies the path to the suppressions file (`eslint-suppressions.json`). This path can be absolute or relative to the `cwd`.
29
-
- If `suppressionsLocation` is provided, ESLint will attempt to load suppressions from that specific file path.
30
-
- If `suppressionsLocation` is not provided (or is `undefined`), ESLint will default to looking for `eslint-suppressions.json` in the `cwd`.
26
+
1. New Constructor Options
27
+
-`suppressionsLocation`
28
+
- Both `ESLintOptions` and `LegacyESLintOptions` will accept a new optional property: `suppressionsLocation`.
29
+
-`suppressionsLocation: string | undefined`: Specifies the path to the suppressions file (`eslint-suppressions.json`). This path can be absolute or relative to the `cwd`.
30
+
- If `suppressionsLocation` is provided, ESLint will attempt to load suppressions from that specific file path.
31
+
- If `suppressionsLocation` is not provided (or is `undefined`), ESLint will default to looking for `eslint-suppressions.json` in the `cwd`.
32
+
-`applySuppressions`
33
+
- Controls whether suppressions are automatically applied to results from `lintText()` and `lintFiles()`.
34
+
- If `true`, suppressions are automatically applied to lint results before returning.
35
+
- If `false`, results are returned as-is without applying suppressions.
36
+
- If not provided (or is `undefined`), defaults to `true`.
31
37
32
38
2. Service Instantiation and Configuration
33
39
- Upon instantiation, the `ESLint` and `LegacyESLint` constructors will create an instance of `SuppressionsService`.
34
-
- A new constructor option, `suppressionsLocation` (string, optional), will be added to both classes.
35
-
- If provided and relative, this path (relative to `cwd`) specifies the suppression file.
36
-
- If provided and absolute, this path (relative to `/`) specifies the suppression file.
37
-
- If not provided, ESLint defaults to searching for `eslint-suppressions.json` in the `cwd`.
38
-
- The constructor will resolve the final absolute path to the suppression file (using `suppressionsLocation` or the default) and pass it to the `SuppressionsService` constructor.
40
+
- 2 new constructor options will be added to both classes.
41
+
-`suppressionsLocation` (string, optional)
42
+
- If provided and relative, this path (relative to `cwd`) specifies the suppression file.
43
+
- If provided and absolute, this path (relative to `/`) specifies the suppression file.
44
+
- If not provided, ESLint defaults to searching for `eslint-suppressions.json` in the `cwd`.
45
+
- The constructor will resolve the final absolute path to the suppression file (using `suppressionsLocation` or the default) and pass it to the `SuppressionsService` constructor.
46
+
-`applySuppressions` (boolean, optional)
47
+
- If `true`, suppressions will be applied automatically in `lintText()` and `lintFiles()`.
48
+
- If `false`, suppressions will not be applied.
49
+
- If not provided, defaults to `true`.
39
50
40
51
3. Applying Suppressions
41
-
- Within the `lintFiles()` and `lintText()` methods of both classes, *after* the initial linting results are obtained, the `applySuppressions` method of the instantiated `SuppressionsService` will be called.
42
-
- This method takes the raw linting results and the loaded suppressions (from the resolved file path) and returns the results with suppressions applied, along with any unused suppressions.
43
-
- The final, suppression-applied results will be returned to the user.
52
+
- When `applySuppressions` is `true` (the default), the `lintFiles()` and `lintText()` methods will automatically apply suppressions to results before returning.
53
+
- Within these methods, *after* the initial linting results are obtained, the `applySuppressions` method of the instantiated `SuppressionsService` will be called.
54
+
- This method takes the raw linting results and the loaded suppressions (from the resolved file path) and returns the results with suppressions applied.
55
+
- When `applySuppressions` is `false`, the raw linting results are returned without applying suppressions, allowing consumers to handle suppressions themselves.
44
56
45
57
4. Changes to ESLint CLI
46
-
-With the integration of suppression handling into the `ESLint`and `LegacyESLint` APIs, the ESLint CLI (`lib/cli.js`) will be updated.
47
-
-Specifically, direct calls to `SuppressionsService` within the CLI will be removed. The CLI will now leverage the updated API methods to handle bulk suppressions, ensuring that the CLI's behavior is consistent with the API's new capabilities. This change simplifies the CLI's implementation by delegating suppression logic to the core API.
58
+
-The CLI will instantiate `ESLint`with `applySuppressions: false` to receive raw linting results.
59
+
- The CLI will continue to call `SuppressionsService` directly to handle suppression-related flags (`--suppress-all`, `--suppress-rule`, `--prune-suppressions`) and to apply suppressions before output.
The documentation updates will reflect that this change aligns the Node.js API behavior with the existing CLI functionality.
152
163
153
164
1. API Documentation (`ESLint`/`LegacyESLint` classes):
154
-
- Add the new `suppressionsLocation` option to the constructor options documentation for both `ESLint` and `LegacyESLint`, explaining its purpose (specifying the suppression file path) and behavior (relative to `cwd`, default lookup).
155
-
- Add a note to the descriptions of `lintText()` and `lintFiles()` methods stating that suppressions are automatically applied based on the resolved suppression file path (either from `suppressionsLocation` or the default `eslint-suppressions.json` in `cwd`). Example: "Applies suppressions from the resolved suppression file (`suppressionsLocation` option or `eslint-suppressions.json` in `cwd`), if found."
165
+
- Add the new `suppressionsLocation` and `applySuppressions` options to the constructor options documentation for both `ESLint` and `LegacyESLint`.
166
+
- Document `suppressionsLocation`: its purpose (specifying the suppression file path) and behavior (relative to `cwd`, default lookup).
167
+
- Document `applySuppressions`: controls whether suppressions are automatically applied (defaults to `true`).
168
+
- Add a note to the descriptions of `lintText()` and `lintFiles()` methods stating that suppressions are automatically applied when `applySuppressions` is `true` (the default), based on the resolved suppression file path.
156
169
157
170
2. Bulk Suppressions User Guide Page:
158
171
- Update the existing user guide page for Bulk Suppressions.
159
172
- Add a section or note clarifying that the feature is now also available when using the `ESLint` and `LegacyESLint` Node.js APIs.
160
173
- Explicitly mention how the suppression file is located when using the API: "Note: When using the Node.js API, ESLint searches for the suppression file specified by the `suppressionsLocation` constructor option. If this option is not provided, it defaults to looking for `eslint-suppressions.json` in the `cwd` (current working directory)."
161
174
162
175
3. Release Notes:
163
-
- Include an entry in the release notes announcing the availability of bulk suppressions in the Node.js API, **highlighting the new `suppressionsLocation`option**.
176
+
- Include an entry in the release notes announcing the availability of bulk suppressions in the Node.js API, **highlighting the new `suppressionsLocation`and `applySuppressions` options**.
164
177
165
178
## Drawbacks
166
179
167
-
- API Complexity: Introduces a new option (`suppressionsLocation`) to the constructor API surface for both `ESLint` and `LegacyESLint`, slightly increasing complexity compared to only supporting the default file location.
180
+
- API Complexity: Introduces two new options (`suppressionsLocation` and `applySuppressions`) to the constructor API surface for both `ESLint` and `LegacyESLint`, slightly increasing complexity.
168
181
- Performance: The overhead of potentially resolving `suppressionsLocation` and then searching for/parsing the suppression file is introduced. However, this aligns the API\'s behavior and capabilities with the CLI.
169
182
- Complexity: Introduces `SuppressionsService` interaction into `ESLint`/`LegacyESLint`, but reuses existing internal logic.
170
183
171
184
## Backwards Compatibility Analysis
172
185
173
186
This change is designed to be backward-compatible.
174
187
175
-
- New Option is Optional: The new `suppressionsLocation`option is optional. Existing code that does not provide this option will continue to work, defaulting to the behavior of looking for `eslint-suppressions.json` in the `cwd`.
188
+
- New Options are Optional: The new `suppressionsLocation`and `applySuppressions` options are optional. Existing code that does not provide these options will continue to work, with `applySuppressions`defaulting to `true` and `suppressionsLocation` defaulting to looking for `eslint-suppressions.json` in the `cwd`.
176
189
- Automatic Application: By integrating bulk suppression handling directly into the existing `lintText()` and `lintFiles()` methods, users who utilize a suppression file (either at the default location or specified via the new option) will automatically benefit simply by updating their ESLint version.
177
190
- Alignment with CLI: This approach aligns the Node.js API behavior *and configuration options* more closely with the established CLI behavior.
178
191
- Non-Breaking: Since the core change only alters behavior when a suppression file is found (based on the new option or default location), it is considered a non-breaking change for existing API consumers.
0 commit comments