Skip to content

Commit cc1926a

Browse files
mrmlnctclindner
authored andcommitted
feat: add "AllowEmptyTargets" option (#173)
1 parent a39ca63 commit cc1926a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

docs/cli.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ $ npmPkgJsonLint . --ignorePath .gitignore
8484
## `--maxWarnings` (alias `-mw`)
8585

8686
Max number of warnings that are allowed before an error is thrown. By default, npm-package-json-lint allows `10000000`.
87+
88+
## `--allowEmptyTargets`
89+
90+
Do not throw an error when a list of targets is empty.

src/cli.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const cli = meow(
2626
--configFile, -c File path of .npmpackagejsonlintrc.json
2727
--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().
2828
--maxWarnings, -mw Maximum number of warnings that can be detected before an error is thrown.
29+
--allowEmptyTargets Do not throw an error when a list of targets is empty.
2930
3031
Examples
3132
$ npmPkgJsonLint --version
@@ -67,6 +68,10 @@ const cli = meow(
6768
type: 'number',
6869
alias: 'mw',
6970
default: 10000000
71+
},
72+
allowEmptyTargets: {
73+
type: 'boolean',
74+
default: false
7075
}
7176
}
7277
}
@@ -83,7 +88,10 @@ debug(`patterns: ${patterns}`);
8388
if (patterns.length === noPatternsProvided) {
8489
debug(`No lint targets provided`);
8590
console.log(chalk.red.bold('No lint targets provided'));
86-
process.exit(exitCodes.oneMissingTarget);
91+
92+
const exitCode = cli.flags.allowEmptyTargets ? exitCodes.zeroClean : exitCodes.oneMissingTarget;
93+
94+
process.exit(exitCode);
8795
}
8896

8997
try {

test/integration/cli.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe('cli Integration Tests', () => {
5252
--configFile, -c File path of .npmpackagejsonlintrc.json
5353
--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().
5454
--maxWarnings, -mw Maximum number of warnings that can be detected before an error is thrown.
55+
--allowEmptyTargets Do not throw an error when a list of targets is empty.
5556
5657
Examples
5758
$ npmPkgJsonLint --version
@@ -98,6 +99,15 @@ describe('cli Integration Tests', () => {
9899
expect(cli.stderr.toString()).toStrictEqual('');
99100
expect(cli.status).toStrictEqual(oneMissingTargets);
100101
});
102+
103+
test('should exit with zero code when an empty targets is allowed', () => {
104+
const cli = spawnSync(relativePathToCli, ['--allowEmptyTargets'], {env});
105+
const expected = 'No lint targets provided\n';
106+
107+
expect(cli.stdout.toString()).toStrictEqual(expected);
108+
expect(cli.stderr.toString()).toStrictEqual('');
109+
expect(cli.status).toStrictEqual(zeroClean);
110+
});
101111
});
102112

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

0 commit comments

Comments
 (0)