Skip to content

Commit 1b55577

Browse files
coltonehrmansamcx
authored andcommitted
fix(next-lint): update option --report-unused-disable-directives to --report-unused-disable-directives-severity (#64405)
## Why? The Option name and type has been incorrect for `--report-unused-disable-directives` (it's likely that #61877 exposed this. For correctness, we have updated the name to `--report-unsed-disable-directives-severity` → https://eslint.org/docs/v8.x/use/command-line-interface#--report-unused-disable-directives-severity. - Fixes #64402 --------- Co-authored-by: samcx <sam@vercel.com>
1 parent 0c08e5b commit 1b55577

File tree

4 files changed

+81
-52
lines changed

4 files changed

+81
-52
lines changed

docs/02-app/02-api-reference/08-next-cli.mdx

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -357,48 +357,46 @@ The output should look like this:
357357
```bash filename="Terminal"
358358
Usage: next lint [directory] [options]
359359
360-
Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib`
361-
directories. It also provides a guided setup to install any required dependencies if ESLint
362-
is not already configured in your application.
360+
Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` directories. It also
361+
provides a guided setup to install any required dependencies if ESLint is not already configured in your
362+
application.
363363
364364
Arguments:
365-
[directory] A base directory on which to lint the application.
366-
If no directory is provided, the current
367-
directory will be used.
365+
[directory] A base directory on which to lint the application.
366+
If no directory is provided, the current directory
367+
will be used.
368368
369369
Options:
370-
-d, --dir, <dirs...> Include directory, or directories, to run ESLint.
371-
--file, <files...> Include file, or files, to run ESLint.
372-
--ext, [exts...] Specify JavaScript file extensions. (default:
373-
[".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".ts
374-
x"])
375-
-c, --config, <config> Uses this configuration file, overriding all other
376-
configuration options.
377-
--resolve-plugins-relative-to, <rprt> Specify a directory where plugins should be
378-
resolved from.
379-
--strict Creates a `.eslintrc.json` file using the Next.js
380-
strict configuration.
381-
--rulesdir, <rulesdir...> Uses additional rules from this directory(s).
382-
--fix Automatically fix linting issues.
383-
--fix-type <fixType> Specify the types of fixes to apply (e.g., problem,
384-
suggestion, layout).
385-
--ignore-path <path> Specify a file to ignore.
386-
--no-ignore <path> Disables the `--ignore-path` option.
387-
--quiet Reports errors only.
388-
--max-warnings [maxWarnings] Specify the number of warnings before triggering a
389-
non-zero exit code. (default: -1)
390-
-o, --output-file, <outputFile> Specify a file to write report to.
391-
-f, --format, <format> Uses a specifc output format.
392-
--no-inline-config Prevents comments from changing config or rules.
393-
--report-unused-disable-directives Adds reprted errors for unused eslint-disable
394-
directives.
395-
--no-cache Disables caching.
396-
--cache-location, <cacheLocation> Specify a location for cache.
397-
--cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed
398-
files in the cache. (default: "metadata")
399-
--error-on-unmatched-pattern Reports errors when any file patterns are
400-
unmatched.
401-
-h, --help Displays this message.
370+
-d, --dir, <dirs...> Include directory, or directories, to run ESLint.
371+
--file, <files...> Include file, or files, to run ESLint.
372+
--ext, [exts...] Specify JavaScript file extensions. (default:
373+
[".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"])
374+
-c, --config, <config> Uses this configuration file, overriding all other
375+
configuration options.
376+
--resolve-plugins-relative-to, <rprt> Specify a directory where plugins should be resolved
377+
from.
378+
--strict Creates a `.eslintrc.json` file using the Next.js
379+
strict configuration.
380+
--rulesdir, <rulesdir...> Uses additional rules from this directory(s).
381+
--fix Automatically fix linting issues.
382+
--fix-type <fixType> Specify the types of fixes to apply (e.g., problem,
383+
suggestion, layout).
384+
--ignore-path <path> Specify a file to ignore.
385+
--no-ignore <path> Disables the `--ignore-path` option.
386+
--quiet Reports errors only.
387+
--max-warnings [maxWarnings] Specify the number of warnings before triggering a
388+
non-zero exit code. (default: -1)
389+
-o, --output-file, <outputFile> Specify a file to write report to.
390+
-f, --format, <format> Uses a specifc output format.
391+
--no-inline-config Prevents comments from changing config or rules.
392+
--report-unused-disable-directives-severity <level> Specify severity level for unused eslint-disable
393+
directives. (choices: "error", "off", "warn")
394+
--no-cache Disables caching.
395+
--cache-location, <cacheLocation> Specify a location for cache.
396+
--cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed files
397+
in the cache. (default: "metadata")
398+
--error-on-unmatched-pattern Reports errors when any file patterns are unmatched.
399+
-h, --help Displays this message.
402400
```
403401
404402
If you have other directories that you would like to lint, you can specify them using the `--dir` flag:

packages/next/src/bin/next.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ program
264264
'--no-inline-config',
265265
'Prevents comments from changing config or rules.'
266266
)
267-
.option(
268-
'--report-unused-disable-directives',
269-
'Adds reported errors for unused eslint-disable directives.'
267+
.addOption(
268+
new Option(
269+
'--report-unused-disable-directives-severity <level>',
270+
'Specify severity level for unused eslint-disable directives.'
271+
).choices(['error', 'off', 'warn'])
270272
)
271273
.option('--no-cache', 'Disables caching.')
272274
.option('--cache-location, <cacheLocation>', 'Specify a location for cache.')

packages/next/src/cli/next-lint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type NextLintOptions = {
3434
maxWarnings: number
3535
outputFile?: string
3636
quiet?: boolean
37-
reportUnusedDisableDirectives: string
37+
reportUnusedDisableDirectivesSeverity: 'error' | 'off' | 'warn'
3838
resolvePluginsRelativeTo?: string
3939
rulesdir?: string
4040
strict?: boolean
@@ -53,7 +53,8 @@ const eslintOptions = (
5353
ignorePath: options.ignorePath || null,
5454
ignore: options.ignore,
5555
allowInlineConfig: options.inlineConfig,
56-
reportUnusedDisableDirectives: options.reportUnusedDisableDirectives || null,
56+
reportUnusedDisableDirectives:
57+
options.reportUnusedDisableDirectivesSeverity || null,
5758
cache: options.cache,
5859
cacheLocation: options.cacheLocation || defaultCacheLocation,
5960
cacheStrategy: options.cacheStrategy,

test/integration/eslint/test/next-lint.test.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os from 'os'
44
import { join } from 'path'
55

66
import findUp from 'next/dist/compiled/find-up'
7-
import { File, nextBuild, nextLint } from 'next-test-utils'
7+
import { nextLint } from 'next-test-utils'
88

99
const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
1010
const dirCustomConfig = join(__dirname, '../custom-config')
@@ -21,17 +21,9 @@ const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
2121
const dirBaseDirectories = join(__dirname, '../base-directories')
2222
const dirCustomDirectories = join(__dirname, '../custom-directories')
2323
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
24-
const dirInvalidOlderEslintVersion = join(
25-
__dirname,
26-
'../invalid-eslint-version'
27-
)
2824
const dirMaxWarnings = join(__dirname, '../max-warnings')
2925
const dirEmptyDirectory = join(__dirname, '../empty-directory')
30-
const dirEslintIgnore = join(__dirname, '../eslint-ignore')
31-
const dirNoEslintPlugin = join(__dirname, '../no-eslint-plugin')
3226
const dirNoConfig = join(__dirname, '../no-config')
33-
const dirEslintCache = join(__dirname, '../eslint-cache')
34-
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
3527
const dirFileLinting = join(__dirname, '../file-linting')
3628
const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting')
3729
const dirTypescript = join(__dirname, '../with-typescript')
@@ -211,6 +203,42 @@ describe('Next Lint', () => {
211203
)
212204
})
213205

206+
test('verify options name and type with auto-generated help output', async () => {
207+
const options = [
208+
'-d, --dir, <dirs...>',
209+
'--file, <files...>',
210+
'--ext, [exts...]',
211+
'-c, --config, <config>',
212+
'--resolve-plugins-relative-to, <rprt>',
213+
'--strict',
214+
'--rulesdir, <rulesdir...>',
215+
'--fix',
216+
'--fix-type <fixType>',
217+
'--ignore-path <path>',
218+
'--no-ignore',
219+
'--quiet',
220+
'--max-warnings [maxWarnings]',
221+
'-o, --output-file, <outputFile>',
222+
'-f, --format, <format>',
223+
'--no-inline-config',
224+
'--report-unused-disable-directives-severity <level>',
225+
'--no-cache',
226+
'--cache-location, <cacheLocation>',
227+
'--cache-strategy, [cacheStrategy]',
228+
'--error-on-unmatched-pattern',
229+
]
230+
const { stdout, stderr } = await nextLint(dirNoConfig, ['-h'], {
231+
stdout: true,
232+
stderr: true,
233+
})
234+
235+
const output = stdout + stderr
236+
237+
for (let option of options) {
238+
expect(output).toContain(option)
239+
}
240+
})
241+
214242
test('base directories are linted by default', async () => {
215243
const { stdout, stderr } = await nextLint(dirBaseDirectories, [], {
216244
stdout: true,

0 commit comments

Comments
 (0)