Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow empty targets #173

Merged
merged 2 commits into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ $ npmPkgJsonLint . --ignorePath .gitignore
## `--maxWarnings` (alias `-mw`)

Max number of warnings that are allowed before an error is thrown. By default, npm-package-json-lint allows `10000000`.

## `--allowEmptyTargets`

Do not throw an error when a list of targets is empty.
10 changes: 9 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const cli = meow(
--configFile, -c File path of .npmpackagejsonlintrc.json
--ignorePath, -i Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). By default, npm-package-json-lint looks for .npmpackagejsonlintignore in process.cwd().
--maxWarnings, -mw Maximum number of warnings that can be detected before an error is thrown.
--allowEmptyTargets Do not throw an error when a list of targets is empty.

Examples
$ npmPkgJsonLint --version
Expand Down Expand Up @@ -67,6 +68,10 @@ const cli = meow(
type: 'number',
alias: 'mw',
default: 10000000
},
allowEmptyTargets: {
type: 'boolean',
default: false
}
}
}
Expand All @@ -83,7 +88,10 @@ debug(`patterns: ${patterns}`);
if (patterns.length === noPatternsProvided) {
debug(`No lint targets provided`);
console.log(chalk.red.bold('No lint targets provided'));
process.exit(exitCodes.oneMissingTarget);

const exitCode = cli.flags.allowEmptyTargets ? exitCodes.zeroClean : exitCodes.oneMissingTarget;

process.exit(exitCode);
}

try {
Expand Down
10 changes: 10 additions & 0 deletions test/integration/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe('cli Integration Tests', () => {
--configFile, -c File path of .npmpackagejsonlintrc.json
--ignorePath, -i Path to a file containing patterns that describe files to ignore. The path can be absolute or relative to process.cwd(). By default, npm-package-json-lint looks for .npmpackagejsonlintignore in process.cwd().
--maxWarnings, -mw Maximum number of warnings that can be detected before an error is thrown.
--allowEmptyTargets Do not throw an error when a list of targets is empty.

Examples
$ npmPkgJsonLint --version
Expand Down Expand Up @@ -98,6 +99,15 @@ describe('cli Integration Tests', () => {
expect(cli.stderr.toString()).toStrictEqual('');
expect(cli.status).toStrictEqual(oneMissingTargets);
});

test('should exit with zero code when an empty targets is allowed', () => {
const cli = spawnSync(relativePathToCli, ['--allowEmptyTargets'], {env});
const expected = 'No lint targets provided\n';

expect(cli.stdout.toString()).toStrictEqual(expected);
expect(cli.stderr.toString()).toStrictEqual('');
expect(cli.status).toStrictEqual(zeroClean);
});
});

describe('when the cli is run without quiet', () => {
Expand Down