diff --git a/docs/02-app/02-api-reference/08-next-cli.mdx b/docs/02-app/02-api-reference/08-next-cli.mdx index 185c91e45396b..e33a96e7648c4 100644 --- a/docs/02-app/02-api-reference/08-next-cli.mdx +++ b/docs/02-app/02-api-reference/08-next-cli.mdx @@ -357,48 +357,46 @@ The output should look like this: ```bash filename="Terminal" Usage: next lint [directory] [options] -Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` -directories. It also provides a guided setup to install any required dependencies if ESLint -is not already configured in your application. +Runs ESLint for all files in the `/src`, `/app`, `/pages`, `/components`, and `/lib` directories. It also +provides a guided setup to install any required dependencies if ESLint is not already configured in your +application. Arguments: - [directory] A base directory on which to lint the application. - If no directory is provided, the current - directory will be used. + [directory] A base directory on which to lint the application. + If no directory is provided, the current directory + will be used. Options: - -d, --dir, Include directory, or directories, to run ESLint. - --file, Include file, or files, to run ESLint. - --ext, [exts...] Specify JavaScript file extensions. (default: - [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".ts -x"]) - -c, --config, Uses this configuration file, overriding all other - configuration options. - --resolve-plugins-relative-to, Specify a directory where plugins should be - resolved from. - --strict Creates a `.eslintrc.json` file using the Next.js - strict configuration. - --rulesdir, Uses additional rules from this directory(s). - --fix Automatically fix linting issues. - --fix-type Specify the types of fixes to apply (e.g., problem, - suggestion, layout). - --ignore-path Specify a file to ignore. - --no-ignore Disables the `--ignore-path` option. - --quiet Reports errors only. - --max-warnings [maxWarnings] Specify the number of warnings before triggering a - non-zero exit code. (default: -1) - -o, --output-file, Specify a file to write report to. - -f, --format, Uses a specifc output format. - --no-inline-config Prevents comments from changing config or rules. - --report-unused-disable-directives Adds reprted errors for unused eslint-disable - directives. - --no-cache Disables caching. - --cache-location, Specify a location for cache. - --cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed - files in the cache. (default: "metadata") - --error-on-unmatched-pattern Reports errors when any file patterns are - unmatched. - -h, --help Displays this message. + -d, --dir, Include directory, or directories, to run ESLint. + --file, Include file, or files, to run ESLint. + --ext, [exts...] Specify JavaScript file extensions. (default: + [".js", ".mjs", ".cjs", ".jsx", ".ts", ".mts", ".cts", ".tsx"]) + -c, --config, Uses this configuration file, overriding all other + configuration options. + --resolve-plugins-relative-to, Specify a directory where plugins should be resolved + from. + --strict Creates a `.eslintrc.json` file using the Next.js + strict configuration. + --rulesdir, Uses additional rules from this directory(s). + --fix Automatically fix linting issues. + --fix-type Specify the types of fixes to apply (e.g., problem, + suggestion, layout). + --ignore-path Specify a file to ignore. + --no-ignore Disables the `--ignore-path` option. + --quiet Reports errors only. + --max-warnings [maxWarnings] Specify the number of warnings before triggering a + non-zero exit code. (default: -1) + -o, --output-file, Specify a file to write report to. + -f, --format, Uses a specifc output format. + --no-inline-config Prevents comments from changing config or rules. + --report-unused-disable-directives-severity Specify severity level for unused eslint-disable + directives. (choices: "error", "off", "warn") + --no-cache Disables caching. + --cache-location, Specify a location for cache. + --cache-strategy, [cacheStrategy] Specify a strategy to use for detecting changed files + in the cache. (default: "metadata") + --error-on-unmatched-pattern Reports errors when any file patterns are 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: diff --git a/packages/next/src/bin/next.ts b/packages/next/src/bin/next.ts index af81e31b5c5ec..98247ffac770e 100755 --- a/packages/next/src/bin/next.ts +++ b/packages/next/src/bin/next.ts @@ -264,9 +264,11 @@ program '--no-inline-config', 'Prevents comments from changing config or rules.' ) - .option( - '--report-unused-disable-directives', - 'Adds reported errors for unused eslint-disable directives.' + .addOption( + new Option( + '--report-unused-disable-directives-severity ', + 'Specify severity level for unused eslint-disable directives.' + ).choices(['error', 'off', 'warn']) ) .option('--no-cache', 'Disables caching.') .option('--cache-location, ', 'Specify a location for cache.') diff --git a/packages/next/src/cli/next-lint.ts b/packages/next/src/cli/next-lint.ts index bd3563679efe1..9fc2090eac530 100755 --- a/packages/next/src/cli/next-lint.ts +++ b/packages/next/src/cli/next-lint.ts @@ -34,7 +34,7 @@ type NextLintOptions = { maxWarnings: number outputFile?: string quiet?: boolean - reportUnusedDisableDirectives: string + reportUnusedDisableDirectivesSeverity: 'error' | 'off' | 'warn' resolvePluginsRelativeTo?: string rulesdir?: string strict?: boolean @@ -53,7 +53,8 @@ const eslintOptions = ( ignorePath: options.ignorePath || null, ignore: options.ignore, allowInlineConfig: options.inlineConfig, - reportUnusedDisableDirectives: options.reportUnusedDisableDirectives || null, + reportUnusedDisableDirectives: + options.reportUnusedDisableDirectivesSeverity || null, cache: options.cache, cacheLocation: options.cacheLocation || defaultCacheLocation, cacheStrategy: options.cacheStrategy, diff --git a/test/integration/eslint/test/next-lint.test.js b/test/integration/eslint/test/next-lint.test.js index acc97e6f93c9e..21bb553008b22 100644 --- a/test/integration/eslint/test/next-lint.test.js +++ b/test/integration/eslint/test/next-lint.test.js @@ -4,7 +4,7 @@ import os from 'os' import { join } from 'path' 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 dirCustomConfig = join(__dirname, '../custom-config') @@ -21,17 +21,9 @@ const dirIgnoreDuringBuilds = join(__dirname, '../ignore-during-builds') const dirBaseDirectories = join(__dirname, '../base-directories') const dirCustomDirectories = join(__dirname, '../custom-directories') const dirConfigInPackageJson = join(__dirname, '../config-in-package-json') -const dirInvalidOlderEslintVersion = join( - __dirname, - '../invalid-eslint-version' -) const dirMaxWarnings = join(__dirname, '../max-warnings') 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 dirEslintCache = join(__dirname, '../eslint-cache') -const dirEslintCacheCustomDir = join(__dirname, '../eslint-cache-custom-dir') const dirFileLinting = join(__dirname, '../file-linting') const mjsCjsLinting = join(__dirname, '../mjs-cjs-linting') const dirTypescript = join(__dirname, '../with-typescript') @@ -211,6 +203,42 @@ describe('Next Lint', () => { ) }) + test('verify options name and type with auto-generated help output', async () => { + const options = [ + '-d, --dir, ', + '--file, ', + '--ext, [exts...]', + '-c, --config, ', + '--resolve-plugins-relative-to, ', + '--strict', + '--rulesdir, ', + '--fix', + '--fix-type ', + '--ignore-path ', + '--no-ignore', + '--quiet', + '--max-warnings [maxWarnings]', + '-o, --output-file, ', + '-f, --format, ', + '--no-inline-config', + '--report-unused-disable-directives-severity ', + '--no-cache', + '--cache-location, ', + '--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 () => { const { stdout, stderr } = await nextLint(dirBaseDirectories, [], { stdout: true,