diff --git a/@commitlint/cli/commitlint.config.js b/@commitlint/cli/commitlint.config.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/@commitlint/cli/fixtures/default/commitlint.config.js b/@commitlint/cli/fixtures/default/commitlint.config.js new file mode 100644 index 0000000000..b6775fef5b --- /dev/null +++ b/@commitlint/cli/fixtures/default/commitlint.config.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + 'type-enum': [2, 'never', ['foo']] + } +}; diff --git a/@commitlint/cli/fixtures/husky/integration/commitlint.config.js b/@commitlint/cli/fixtures/husky/integration/commitlint.config.js new file mode 100644 index 0000000000..b6775fef5b --- /dev/null +++ b/@commitlint/cli/fixtures/husky/integration/commitlint.config.js @@ -0,0 +1,5 @@ +module.exports = { + rules: { + 'type-enum': [2, 'never', ['foo']] + } +}; diff --git a/@commitlint/cli/src/cli.js b/@commitlint/cli/src/cli.js index 52ac306a6d..8109af9997 100755 --- a/@commitlint/cli/src/cli.js +++ b/@commitlint/cli/src/cli.js @@ -150,6 +150,26 @@ async function main(options) { messages.map(message => lint(message, loaded.rules, opts)) ); + if (Object.keys(loaded.rules).length === 0) { + results.push({ + valid: false, + errors: [ + { + level: 2, + valid: false, + name: 'empty-rules', + message: [ + 'Please add rules to your `commitlint.config.js`', + ' - Getting started guide: https://git.io/fpUzJ', + ' - Example config: https://git.io/fpUzm' + ].join('\n') + } + ], + warnings: [], + input: '' + }); + } + const report = results.reduce( (info, result) => { info.valid = result.valid ? info.valid : false; @@ -270,7 +290,7 @@ function selectParserOpts(parserPreset) { } function loadFormatter(config, flags) { - const moduleName = flags.format || config.formatter; + const moduleName = flags.format || config.formatter || '@commitlint/format'; const modulePath = resolveFrom.silent(__dirname, moduleName) || resolveFrom.silent(flags.cwd, moduleName) || diff --git a/@commitlint/cli/src/cli.test.js b/@commitlint/cli/src/cli.test.js index 48cce4db14..0f454d9333 100644 --- a/@commitlint/cli/src/cli.test.js +++ b/@commitlint/cli/src/cli.test.js @@ -21,34 +21,40 @@ const cli = (args, options) => { }; test('should throw when called without [input]', async t => { - const cwd = await git.bootstrap('fixtures/empty'); + const cwd = await git.bootstrap('fixtures/default'); const actual = await cli([], {cwd})(); t.is(actual.code, 1); }); test('should reprint input from stdin', async t => { - const cwd = await git.bootstrap('fixtures/empty'); + const cwd = await git.bootstrap('fixtures/default'); const actual = await cli([], {cwd})('foo: bar'); t.true(actual.stdout.includes('foo: bar')); }); test('should produce no success output with --quiet flag', async t => { - const cwd = await git.bootstrap('fixtures/empty'); + const cwd = await git.bootstrap('fixtures/default'); const actual = await cli(['--quiet'], {cwd})('foo: bar'); t.is(actual.stdout, ''); t.is(actual.stderr, ''); }); test('should produce no success output with -q flag', async t => { - const cwd = await git.bootstrap('fixtures/empty'); + const cwd = await git.bootstrap('fixtures/default'); const actual = await cli(['-q'], {cwd})('foo: bar'); t.is(actual.stdout, ''); t.is(actual.stderr, ''); }); -test('should succeed for input from stdin without rules', async t => { +test('should fail for input from stdin without rules', async t => { const cwd = await git.bootstrap('fixtures/empty'); const actual = await cli([], {cwd})('foo: bar'); + t.is(actual.code, 1); +}); + +test('should succeed for input from stdin with rules', async t => { + const cwd = await git.bootstrap('fixtures/default'); + const actual = await cli([], {cwd})('type: bar'); t.is(actual.code, 0); }); @@ -152,7 +158,7 @@ test('should work with husky via commitlint -e %HUSKY_GIT_PARAMS%', async () => }); test('should allow reading of environment variables for edit file, succeeding if valid', async t => { - const cwd = await git.bootstrap(); + const cwd = await git.bootstrap('fixtures/simple'); await sander.writeFile(cwd, 'commit-msg-file', 'foo'); const actual = await cli(['--env', 'variable'], { cwd, @@ -254,8 +260,8 @@ test('should print full commit message when input from stdin fails', async t => }); test('should not print full commit message when input succeeds', async t => { - const cwd = await git.bootstrap('fixtures/empty'); - const message = 'foo: bar\n\nFoo bar bizz buzz.\n\nCloses #123.'; + const cwd = await git.bootstrap('fixtures/default'); + const message = 'type: bar\n\nFoo bar bizz buzz.\n\nCloses #123.'; const actual = await cli([], {cwd})(message); t.false(actual.stdout.includes(message));