Skip to content

Commit

Permalink
chore(eslint-bulk): add eslint-bulk README
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin-y-ang committed Oct 26, 2023
1 parent 20b7275 commit 8aa2e0f
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 24 deletions.
30 changes: 30 additions & 0 deletions eslint/eslint-bulk/.npmignore
Original file line number Diff line number Diff line change
@@ -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)
34 changes: 34 additions & 0 deletions eslint/eslint-bulk/README.md
Original file line number Diff line number Diff line change
@@ -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.
53 changes: 29 additions & 24 deletions eslint/eslint-bulk/src/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,40 @@ import { whichEslint } from './utils/which-eslint';

export function makeCleanupCommand(): Command {
const cleanup = new Command('cleanup');
cleanup.argument('<files...>').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('<files...>')
.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;
}
3 changes: 3 additions & 0 deletions eslint/eslint-bulk/src/suppress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<files...>')
.option('-R, --rule <rules...>')
.option('-A, --all')
Expand Down

0 comments on commit 8aa2e0f

Please sign in to comment.