Unverified Commit 9994e74a authored by Colton Ehrman's avatar Colton Ehrman Committed by GitHub

fix(next-lint): update option --report-unused-disable-directives to…

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
https://github.com/vercel/next.js/pull/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 https://github.com/vercel/next.js/issues/64402

---------
Co-authored-by: 's avatarsamcx <sam@vercel.com>
parent d06c5476
...@@ -357,48 +357,46 @@ The output should look like this: ...@@ -357,48 +357,46 @@ The output should look like this:
```bash filename="Terminal" ```bash filename="Terminal"
Usage: next lint [directory] [options] Usage: next lint [directory] [options]
Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` directories. It also
directories. It also provides a guided setup to install any required dependencies if ESLint provides a guided setup to install any required dependencies if ESLint is not already configured in your
is not already configured in your application. application.
Arguments: Arguments:
[directory] A base directory on which to lint the application. [directory] A base directory on which to lint the application.
If no directory is provided, the current If no directory is provided, the current directory
directory will be used. will be used.
Options: Options:
-d, --dir, <dirs...> Include directory, or directories, to run ESLint. -d, --dir, <dirs...> Include directory, or directories, to run ESLint.
--file, <files...> Include file, or files, to run ESLint. --file, <files...> Include file, or files, to run ESLint.
--ext, [exts...] Specify JavaScript file extensions. (default: --ext, [exts...] Specify JavaScript file extensions. (default:
[".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".ts [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"])
x"]) -c, --config, <config> Uses this configuration file, overriding all other
-c, --config, <config> Uses this configuration file, overriding all other configuration options.
configuration options. --resolve-plugins-relative-to, <rprt> Specify a directory where plugins should be resolved
--resolve-plugins-relative-to, <rprt> Specify a directory where plugins should be from.
resolved from. --strict Creates a `.eslintrc.json` file using the Next.js
--strict Creates a `.eslintrc.json` file using the Next.js strict configuration.
strict configuration. --rulesdir, <rulesdir...> Uses additional rules from this directory(s).
--rulesdir, <rulesdir...> Uses additional rules from this directory(s). --fix Automatically fix linting issues.
--fix Automatically fix linting issues. --fix-type <fixType> Specify the types of fixes to apply (e.g., problem,
--fix-type <fixType> Specify the types of fixes to apply (e.g., problem, suggestion, layout).
suggestion, layout). --ignore-path <path> Specify a file to ignore.
--ignore-path <path> Specify a file to ignore. --no-ignore <path> Disables the `--ignore-path` option.
--no-ignore <path> Disables the `--ignore-path` option. --quiet Reports errors only.
--quiet Reports errors only. --max-warnings [maxWarnings] Specify the number of warnings before triggering a
--max-warnings [maxWarnings] Specify the number of warnings before triggering a non-zero exit code. (default: -1)
non-zero exit code. (default: -1) -o, --output-file, <outputFile> Specify a file to write report to.
-o, --output-file, <outputFile> Specify a file to write report to. -f, --format, <format> Uses a specifc output format.
-f, --format, <format> Uses a specifc output format. --no-inline-config Prevents comments from changing config or rules.
--no-inline-config Prevents comments from changing config or rules. --report-unused-disable-directives-severity <level> Specify severity level for unused eslint-disable
--report-unused-disable-directives Adds reprted errors for unused eslint-disable directives. (choices: "error", "off", "warn")
directives. --no-cache Disables caching.
--no-cache Disables caching. --cache-location, <cacheLocation> Specify a location for cache.
--cache-location, <cacheLocation> Specify a location for cache. --cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed files
--cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed in the cache. (default: "metadata")
files in the cache. (default: "metadata") --error-on-unmatched-pattern Reports errors when any file patterns are unmatched.
--error-on-unmatched-pattern Reports errors when any file patterns are -h, --help Displays this message.
unmatched.
-h, --help Displays this message.
``` ```
If you have other directories that you would like to lint, you can specify them using the `--dir` flag: If you have other directories that you would like to lint, you can specify them using the `--dir` flag:
......
...@@ -264,9 +264,11 @@ program ...@@ -264,9 +264,11 @@ program
'--no-inline-config', '--no-inline-config',
'Prevents comments from changing config or rules.' 'Prevents comments from changing config or rules.'
) )
.option( .addOption(
'--report-unused-disable-directives', new Option(
'Adds reported errors for unused eslint-disable directives.' '--report-unused-disable-directives-severity <level>',
'Specify severity level for unused eslint-disable directives.'
).choices(['error', 'off', 'warn'])
) )
.option('--no-cache', 'Disables caching.') .option('--no-cache', 'Disables caching.')
.option('--cache-location, <cacheLocation>', 'Specify a location for cache.') .option('--cache-location, <cacheLocation>', 'Specify a location for cache.')
......
...@@ -34,7 +34,7 @@ type NextLintOptions = { ...@@ -34,7 +34,7 @@ type NextLintOptions = {
maxWarnings: number maxWarnings: number
outputFile?: string outputFile?: string
quiet?: boolean quiet?: boolean
reportUnusedDisableDirectives: string reportUnusedDisableDirectivesSeverity: 'error' | 'off' | 'warn'
resolvePluginsRelativeTo?: string resolvePluginsRelativeTo?: string
rulesdir?: string rulesdir?: string
strict?: boolean strict?: boolean
...@@ -53,7 +53,8 @@ const eslintOptions = ( ...@@ -53,7 +53,8 @@ const eslintOptions = (
ignorePath: options.ignorePath || null, ignorePath: options.ignorePath || null,
ignore: options.ignore, ignore: options.ignore,
allowInlineConfig: options.inlineConfig, allowInlineConfig: options.inlineConfig,
reportUnusedDisableDirectives: options.reportUnusedDisableDirectives || null, reportUnusedDisableDirectives:
options.reportUnusedDisableDirectivesSeverity || null,
cache: options.cache, cache: options.cache,
cacheLocation: options.cacheLocation || defaultCacheLocation, cacheLocation: options.cacheLocation || defaultCacheLocation,
cacheStrategy: options.cacheStrategy, cacheStrategy: options.cacheStrategy,
......
...@@ -4,7 +4,7 @@ import os from 'os' ...@@ -4,7 +4,7 @@ import os from 'os'
import { join } from 'path' import { join } from 'path'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import { File, nextBuild, nextLint } from 'next-test-utils' import { nextLint } from 'next-test-utils'
const dirFirstTimeSetup = join(__dirname, '../first-time-setup') const dirFirstTimeSetup = join(__dirname, '../first-time-setup')
const dirCustomConfig = join(__dirname, '../custom-config') const dirCustomConfig = join(__dirname, '../custom-config')
...@@ -21,17 +21,9 @@ const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds') ...@@ -21,17 +21,9 @@ const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds')
const dirBaseDirectories = join(__dirname, '../base-directories') const dirBaseDirectories = join(__dirname, '../base-directories')
const dirCustomDirectories = join(__dirname, '../custom-directories') const dirCustomDirectories = join(__dirname, '../custom-directories')
const dirConfigInPackageJson = join(__dirname, '../config-in-package-json') const dirConfigInPackageJson = join(__dirname, '../config-in-package-json')
const dirInvalidOlderEslintVersion = join(
__dirname,
'../invalid-eslint-version'
)
const dirMaxWarnings = join(__dirname, '../max-warnings') const dirMaxWarnings = join(__dirname, '../max-warnings')
const dirEmptyDirectory = join(__dirname, '../empty-directory') const dirEmptyDirectory = join(__dirname, '../empty-directory')
const dirEslintIgnore = join(__dirname, '../eslint-ignore')
const dirNoEslintPlugin = join(__dirname, '../no-eslint-plugin')
const dirNoConfig = join(__dirname, '../no-config') const dirNoConfig = join(__dirname, '../no-config')
const dirEslintCache = join(__dirname, '../eslint-cache')
const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir')
const dirFileLinting = join(__dirname, '../file-linting') const dirFileLinting = join(__dirname, '../file-linting')
const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting') const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting')
const dirTypescript = join(__dirname, '../with-typescript') const dirTypescript = join(__dirname, '../with-typescript')
...@@ -211,6 +203,42 @@ describe('Next Lint', () => { ...@@ -211,6 +203,42 @@ describe('Next Lint', () => {
) )
}) })
test('verify options name and type with auto-generated help output', async () => {
const options = [
'-d, --dir, <dirs...>',
'--file, <files...>',
'--ext, [exts...]',
'-c, --config, <config>',
'--resolve-plugins-relative-to, <rprt>',
'--strict',
'--rulesdir, <rulesdir...>',
'--fix',
'--fix-type <fixType>',
'--ignore-path <path>',
'--no-ignore',
'--quiet',
'--max-warnings [maxWarnings]',
'-o, --output-file, <outputFile>',
'-f, --format, <format>',
'--no-inline-config',
'--report-unused-disable-directives-severity <level>',
'--no-cache',
'--cache-location, <cacheLocation>',
'--cache-strategy, [cacheStrategy]',
'--error-on-unmatched-pattern',
]
const { stdout, stderr } = await nextLint(dirNoConfig, ['-h'], {
stdout: true,
stderr: true,
})
const output = stdout + stderr
for (let option of options) {
expect(output).toContain(option)
}
})
test('base directories are linted by default', async () => { test('base directories are linted by default', async () => {
const { stdout, stderr } = await nextLint(dirBaseDirectories, [], { const { stdout, stderr } = await nextLint(dirBaseDirectories, [], {
stdout: true, stdout: true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment