Skip to content

Commit 8f3c3b1

Browse files
authored
fix: avoid excessive help text #606 (#637)
* fix: avoid excessive help text #606 * fix: avoid summary for success cases * test: adapt test to new report formatting * fix: distribute newlines appropriately * docs: document new flags * style: reexport default directly * fix: remove typo
1 parent 3874735 commit 8f3c3b1

15 files changed

+2234
-352
lines changed

@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

@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

@commitlint/format/index.d.ts

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

@commitlint/format/index.js

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

@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+
};

@commitlint/format/package.json

+10-30
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,13 @@
77
"lib/"
88
],
99
"scripts": {
10-
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
10+
"build": "tsc",
1111
"clean": "npx rimraf lib",
1212
"deps": "dep-check",
1313
"pkg": "pkg-check --skip-import",
14-
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
15-
"test": "ava -c 4 --verbose",
16-
"watch": "babel src --out-dir lib --watch --source-maps"
17-
},
18-
"ava": {
19-
"files": [
20-
"src/**/*.test.js",
21-
"!lib/**/*"
22-
],
23-
"source": [
24-
"src/**/*.js",
25-
"!lib/**/*"
26-
],
27-
"babel": "inherit",
28-
"require": [
29-
"babel-register"
30-
]
31-
},
32-
"babel": {
33-
"presets": [
34-
"babel-preset-commitlint"
35-
]
14+
"start": "concurrently \"yarn test --watchAll\" \"yarn run watch\"",
15+
"test": "jest",
16+
"watch": "tsc -w"
3617
},
3718
"engines": {
3819
"node": ">=4"
@@ -59,17 +40,16 @@
5940
"devDependencies": {
6041
"@commitlint/test": "7.5.0",
6142
"@commitlint/utils": "^7.5.0",
62-
"ava": "0.22.0",
63-
"babel-cli": "6.26.0",
64-
"babel-preset-commitlint": "^7.5.0",
65-
"babel-register": "6.26.0",
43+
"@types/jest": "^24.0.12",
44+
"@types/lodash": "^4.14.123",
6645
"concurrently": "3.5.1",
6746
"cross-env": "5.1.1",
68-
"lodash": "4.17.11",
69-
"rimraf": "2.6.1"
47+
"jest": "^24.7.1",
48+
"rimraf": "2.6.1",
49+
"ts-jest": "^24.0.2",
50+
"typescript": "^3.4.5"
7051
},
7152
"dependencies": {
72-
"babel-runtime": "^6.23.0",
7353
"chalk": "^2.0.1"
7454
}
7555
}

0 commit comments

Comments
 (0)