From 8aa2e0f2f6b39c1ea019f8adc120d8ff3748848b Mon Sep 17 00:00:00 2001 From: Kevin Yang <61671317+kevin-y-ang@users.noreply.github.com> Date: Thu, 26 Oct 2023 16:43:20 -0700 Subject: [PATCH] chore(eslint-bulk): add eslint-bulk README --- eslint/eslint-bulk/.npmignore | 30 +++++++++++++++++ eslint/eslint-bulk/README.md | 34 +++++++++++++++++++ eslint/eslint-bulk/src/cleanup.ts | 53 ++++++++++++++++-------------- eslint/eslint-bulk/src/suppress.ts | 3 ++ 4 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 eslint/eslint-bulk/.npmignore create mode 100644 eslint/eslint-bulk/README.md diff --git a/eslint/eslint-bulk/.npmignore b/eslint/eslint-bulk/.npmignore new file mode 100644 index 00000000000..0164a20d7a9 --- /dev/null +++ b/eslint/eslint-bulk/.npmignore @@ -0,0 +1,30 @@ +# THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. + +# Ignore all files by default, to avoid accidentally publishing unintended files. +* + +# Use negative patterns to bring back the specific things we want to publish. +!/bin/** +!/lib/** +!/lib-*/** +!/dist/** +!ThirdPartyNotice.txt + +# Ignore certain patterns that should not get published. +/dist/*.stats.* +/lib/**/test/ +/lib-*/**/test/ +*.test.js + +# NOTE: These don't need to be specified, because NPM includes them automatically. +# +# package.json +# README (and its variants) +# CHANGELOG (and its variants) +# LICENSE / LICENCE + +#-------------------------------------------- +# DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE +#-------------------------------------------- + +# (Add your project-specific overrides here) diff --git a/eslint/eslint-bulk/README.md b/eslint/eslint-bulk/README.md new file mode 100644 index 00000000000..597097dbff4 --- /dev/null +++ b/eslint/eslint-bulk/README.md @@ -0,0 +1,34 @@ +# @rushstack/eslint-bulk + +This is a companion package for @rushstack/eslint-patch. + +The **eslint-bulk** package is a set of command line tools to use with the ESLint bulk suppressions +patch. The commands are optional as they are just a thin wrapper over eslint shipped with the correct +environment variables to interface with the patch. + +## eslint-bulk suppress + +Use this command to automatically generate bulk suppressions for the given files and given rules. +Supply the files as the main argument. The "files" argument is a glob pattern thatfollows the same +rules as the "eslint" command. + +```bash + eslint-bulk suppress path/to/file1 path/to/file2 path/to/directory --rule rule1 --rule rule2 +``` + +## eslint-bulk cleanup + +Use this command to automatically delete unused suppression entries for the given files in the +corresponding .eslint-bulk-suppressions.json file(s). Supply the files as the main argument. The +"files" argument is a glob pattern thatfollows the same rules as the "eslint" command. + +```bash + eslint-bulk cleanup path/to/file1 path/to/file2 path/to/directory +``` + +# Links + +- [CHANGELOG.md](https://github.com/microsoft/rushstack/blob/main/eslint/eslint-bulk/CHANGELOG.md) - Find + out what's new in the latest version + +`@rushstack/eslint-bulk` is part of the [Rush Stack](https://rushstack.io/) family of projects. diff --git a/eslint/eslint-bulk/src/cleanup.ts b/eslint/eslint-bulk/src/cleanup.ts index 613f497eaef..204d6138830 100755 --- a/eslint/eslint-bulk/src/cleanup.ts +++ b/eslint/eslint-bulk/src/cleanup.ts @@ -6,35 +6,40 @@ import { whichEslint } from './utils/which-eslint'; export function makeCleanupCommand(): Command { const cleanup = new Command('cleanup'); - cleanup.argument('').action((files: string[]) => { - const eslintCLI = whichEslint(); + cleanup + .description( + 'Delete unused suppression entries for the given file in the corresponding .eslint-bulk-suppressions.json file. The "files" glob pattern argument follows the same rules as the "eslint" command.' + ) + .argument('') + .action((files: string[]) => { + const eslintCLI = whichEslint(); - const env = Object.assign({}, process.env); - Object.assign(env, { CLEANUP_ESLINT_BULK_SUPPRESSIONS: 'true' }); + const env = Object.assign({}, process.env); + Object.assign(env, { CLEANUP_ESLINT_BULK_SUPPRESSIONS: 'true' }); - exec( - `${eslintCLI} ${files.join(' ')}`, - { env }, - (error: ExecException | null, stdout: string, stderr: string) => { - // if errorCount != 0, ESLint will process.exit(1) giving the false impression - // that the exec failed, even though linting errors are to be expected - const eslintOutputWithErrorRegex = /"errorCount":(?!0)\d+/; - const isEslintError = error !== null && error.code === 1 && eslintOutputWithErrorRegex.test(stdout); + exec( + `${eslintCLI} ${files.join(' ')}`, + { env }, + (error: ExecException | null, stdout: string, stderr: string) => { + // if errorCount != 0, ESLint will process.exit(1) giving the false impression + // that the exec failed, even though linting errors are to be expected + const eslintOutputWithErrorRegex = /"errorCount":(?!0)\d+/; + const isEslintError = error !== null && error.code === 1 && eslintOutputWithErrorRegex.test(stdout); - if (error && !isEslintError) { - console.error(`Execution error: ${error.message}`); - process.exit(1); - } + if (error && !isEslintError) { + console.error(`Execution error: ${error.message}`); + process.exit(1); + } - if (stderr) { - console.error(`ESLint errors: ${stderr}`); - process.exit(1); - } + if (stderr) { + console.error(`ESLint errors: ${stderr}`); + process.exit(1); + } - console.log('Successfully cleaned up bulk suppressions'); - } - ); - }); + console.log('Successfully cleaned up bulk suppressions'); + } + ); + }); return cleanup; } diff --git a/eslint/eslint-bulk/src/suppress.ts b/eslint/eslint-bulk/src/suppress.ts index e1d01d78c49..04f0738c00a 100755 --- a/eslint/eslint-bulk/src/suppress.ts +++ b/eslint/eslint-bulk/src/suppress.ts @@ -7,6 +7,9 @@ import { whichEslint } from './utils/which-eslint'; export function makeSuppressCommand(): Command { const suppress = new Command('suppress'); suppress + .description( + 'Generate a new .eslint-bulk-suppressions.json file or add suppression entries to an existing file. The "files" glob pattern argument follows the same rules as the "eslint" command.' + ) .argument('') .option('-R, --rule ') .option('-A, --all')