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

fix: avoid excessive help text #606 #637

Merged
merged 7 commits into from
May 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions @commitlint/cli/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ const flags = {
alias: 'v',
type: 'boolean',
description: 'display version information'
},
verbose: {
alias: 'V',
type: 'boolean',
description: 'enable verbose output for reports without problems'
}
};

Expand Down Expand Up @@ -204,9 +209,14 @@ async function main(options) {
}
);

const output = format(report, {color: flags.color});
const output = format(report, {
color: flags.color,
verbose: flags.verbose,
helpUrl:
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
});

if (!flags.quiet) {
if (!flags.quiet && output !== '') {
byCedric marked this conversation as resolved.
Show resolved Hide resolved
console.log(output);
}

Expand Down
33 changes: 29 additions & 4 deletions @commitlint/cli/src/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,45 @@ test('should reprint input from stdin', async t => {
t.true(actual.stdout.includes('foo: bar'));
});

test('should produce no success output with --quiet flag', async t => {
test('should produce success output with --verbose flag', async t => {
const cwd = await git.bootstrap('fixtures/default');
const actual = await cli(['--verbose'], {cwd})('type: bar');
t.true(actual.stdout.includes('0 problems, 0 warnings'));
t.is(actual.stderr, '');
});

test('should produce no output with --quiet flag', async t => {
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 => {
test('should produce no output with -q flag', async t => {
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 produce help for empty config', async t => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope to have zero-config soon, after that this won't be necessary I guess right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's remove this then!

const cwd = await git.bootstrap('fixtures/empty');
const actual = await cli([], {cwd})('foo: bar');
t.true(actual.stdout.includes('Please add rules'));
t.is(actual.code, 1);
});

test('should produce help for problems', async t => {
const cwd = await git.bootstrap('fixtures/default');
const actual = await cli([], {cwd})('foo: bar');
t.true(
actual.stdout.includes(
'Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
)
);
t.is(actual.code, 1);
});

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');
Expand Down Expand Up @@ -259,13 +284,13 @@ test('should print full commit message when input from stdin fails', async t =>
t.is(actual.code, 1);
});

test('should not print full commit message when input succeeds', async t => {
test('should not print commit message fully or partially when input succeeds', async t => {
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));
t.true(actual.stdout.includes(message.split('\n')[0]));
t.false(actual.stdout.includes(message.split('\n')[0]));
t.is(actual.code, 0);
});

Expand Down
1 change: 1 addition & 0 deletions @commitlint/format/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./lib";
1 change: 1 addition & 0 deletions @commitlint/format/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib');
4 changes: 4 additions & 0 deletions @commitlint/format/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
};
40 changes: 10 additions & 30 deletions @commitlint/format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,13 @@
"lib/"
],
"scripts": {
"build": "cross-env NODE_ENV=production babel src --out-dir lib --source-maps",
"build": "tsc",
"clean": "npx rimraf lib",
"deps": "dep-check",
"pkg": "pkg-check --skip-import",
"start": "concurrently \"ava -c 4 --verbose --watch\" \"yarn run watch\"",
"test": "ava -c 4 --verbose",
"watch": "babel src --out-dir lib --watch --source-maps"
},
"ava": {
"files": [
"src/**/*.test.js",
"!lib/**/*"
],
"source": [
"src/**/*.js",
"!lib/**/*"
],
"babel": "inherit",
"require": [
"babel-register"
]
},
"babel": {
"presets": [
"babel-preset-commitlint"
]
"start": "concurrently \"yarn test --watchAll\" \"yarn run watch\"",
"test": "jest",
"watch": "tsc -w"
},
"engines": {
"node": ">=4"
Expand All @@ -59,17 +40,16 @@
"devDependencies": {
"@commitlint/test": "7.5.0",
"@commitlint/utils": "^7.5.0",
"ava": "0.22.0",
"babel-cli": "6.26.0",
"babel-preset-commitlint": "^7.5.0",
"babel-register": "6.26.0",
"@types/jest": "^24.0.12",
"@types/lodash": "^4.14.123",
"concurrently": "3.5.1",
"cross-env": "5.1.1",
"lodash": "4.17.11",
"rimraf": "2.6.1"
"jest": "^24.7.1",
"rimraf": "2.6.1",
"ts-jest": "^24.0.2",
"typescript": "^3.4.5"
},
"dependencies": {
"babel-runtime": "^6.23.0",
"chalk": "^2.0.1"
}
}