Skip to content

Commit ef2bb89

Browse files
committed
fix: avoid excessive help text #606 (#637)
This reverts commit 03da46c. BREAKING CHANGE The commitlint default formatter is now silent for reports without warnings or errors. Scripts relying on the success output of commitlint can restore the former output by specifying the --verbose flag.
1 parent 48c364c commit ef2bb89

15 files changed

+2252
-362
lines changed

Diff for: @commitlint/cli/src/cli.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ const flags = {
8989
alias: 'v',
9090
type: 'boolean',
9191
description: 'display version information'
92+
},
93+
verbose: {
94+
alias: 'V',
95+
type: 'boolean',
96+
description: 'enable verbose output for reports without problems'
9297
}
9398
};
9499

@@ -204,9 +209,14 @@ async function main(options) {
204209
}
205210
);
206211

207-
const output = format(report, {color: flags.color});
212+
const output = format(report, {
213+
color: flags.color,
214+
verbose: flags.verbose,
215+
helpUrl:
216+
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
217+
});
208218

209-
if (!flags.quiet) {
219+
if (!flags.quiet && output !== '') {
210220
console.log(output);
211221
}
212222

Diff for: @commitlint/cli/src/cli.test.js

+29-4
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,45 @@ test('should reprint input from stdin', async t => {
3232
t.true(actual.stdout.includes('foo: bar'));
3333
});
3434

35-
test('should produce no success output with --quiet flag', async t => {
35+
test('should produce success output with --verbose flag', async t => {
36+
const cwd = await git.bootstrap('fixtures/default');
37+
const actual = await cli(['--verbose'], {cwd})('type: bar');
38+
t.true(actual.stdout.includes('0 problems, 0 warnings'));
39+
t.is(actual.stderr, '');
40+
});
41+
42+
test('should produce no output with --quiet flag', async t => {
3643
const cwd = await git.bootstrap('fixtures/default');
3744
const actual = await cli(['--quiet'], {cwd})('foo: bar');
3845
t.is(actual.stdout, '');
3946
t.is(actual.stderr, '');
4047
});
4148

42-
test('should produce no success output with -q flag', async t => {
49+
test('should produce no output with -q flag', async t => {
4350
const cwd = await git.bootstrap('fixtures/default');
4451
const actual = await cli(['-q'], {cwd})('foo: bar');
4552
t.is(actual.stdout, '');
4653
t.is(actual.stderr, '');
4754
});
4855

56+
test('should produce help for empty config', async t => {
57+
const cwd = await git.bootstrap('fixtures/empty');
58+
const actual = await cli([], {cwd})('foo: bar');
59+
t.true(actual.stdout.includes('Please add rules'));
60+
t.is(actual.code, 1);
61+
});
62+
63+
test('should produce help for problems', async t => {
64+
const cwd = await git.bootstrap('fixtures/default');
65+
const actual = await cli([], {cwd})('foo: bar');
66+
t.true(
67+
actual.stdout.includes(
68+
'Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
69+
)
70+
);
71+
t.is(actual.code, 1);
72+
});
73+
4974
test('should fail for input from stdin without rules', async t => {
5075
const cwd = await git.bootstrap('fixtures/empty');
5176
const actual = await cli([], {cwd})('foo: bar');
@@ -259,13 +284,13 @@ test('should print full commit message when input from stdin fails', async t =>
259284
t.is(actual.code, 1);
260285
});
261286

262-
test('should not print full commit message when input succeeds', async t => {
287+
test('should not print commit message fully or partially when input succeeds', async t => {
263288
const cwd = await git.bootstrap('fixtures/default');
264289
const message = 'type: bar\n\nFoo bar bizz buzz.\n\nCloses #123.';
265290
const actual = await cli([], {cwd})(message);
266291

267292
t.false(actual.stdout.includes(message));
268-
t.true(actual.stdout.includes(message.split('\n')[0]));
293+
t.false(actual.stdout.includes(message.split('\n')[0]));
269294
t.is(actual.code, 0);
270295
});
271296

Diff for: @commitlint/format/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./lib";

Diff for: @commitlint/format/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib');

Diff for: @commitlint/format/jest.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node'
4+
};

Diff for: @commitlint/format/package.json

+10-29
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,12 @@
77
"lib/"
88
],
99
"scripts": {
10-
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
10+
"build": "tsc",
1111
"deps": "dep-check",
1212
"pkg": "pkg-check --skip-import",
13-
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
14-
"test": "ava -c 4 --verbose",
15-
"watch": "babel src --out-dir lib --watch --source-maps"
16-
},
17-
"ava": {
18-
"files": [
19-
"src/**/*.test.js",
20-
"!lib/**/*"
21-
],
22-
"source": [
23-
"src/**/*.js",
24-
"!lib/**/*"
25-
],
26-
"babel": "inherit",
27-
"require": [
28-
"babel-register"
29-
]
30-
},
31-
"babel": {
32-
"presets": [
33-
"babel-preset-commitlint"
34-
]
13+
"start": "concurrently \"yarn test --watchAll\" \"yarn run watch\"",
14+
"test": "jest",
15+
"watch": "tsc -w"
3516
},
3617
"engines": {
3718
"node": ">=4"
@@ -58,16 +39,16 @@
5839
"devDependencies": {
5940
"@commitlint/test": "^7.6.0",
6041
"@commitlint/utils": "^7.6.0",
61-
"ava": "0.22.0",
62-
"babel-cli": "6.26.0",
63-
"babel-preset-commitlint": "^7.6.0",
64-
"babel-register": "6.26.0",
42+
"@types/jest": "24.0.12",
43+
"@types/lodash": "4.14.123",
6544
"concurrently": "3.5.1",
6645
"cross-env": "5.1.1",
67-
"lodash": "4.17.11"
46+
"jest": "24.7.1",
47+
"rimraf": "2.6.1",
48+
"ts-jest": "24.0.2",
49+
"typescript": "3.4.5"
6850
},
6951
"dependencies": {
70-
"babel-runtime": "^6.23.0",
7152
"chalk": "^2.0.1"
7253
}
7354
}

0 commit comments

Comments
 (0)