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

feat(load): allow specifying helpUrl via config #2180

Merged
merged 1 commit into from Dec 29, 2020
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
6 changes: 6 additions & 0 deletions @commitlint/cli/fixtures/help-url/commitlint.config.js
@@ -0,0 +1,6 @@
module.exports = {
rules: {
'type-enum': [2, 'never', ['foo']]
},
helpUrl: 'https://www.example.com/foo'
};
7 changes: 7 additions & 0 deletions @commitlint/cli/src/cli.test.ts
Expand Up @@ -120,6 +120,13 @@ test('should fail for input from stdin with rule from js', async () => {
expect(actual.exitCode).toBe(1);
});

test('should output help URL defined in config file', async () => {
const cwd = await gitBootstrap('fixtures/help-url');
const actual = await cli([], {cwd})('foo: bar');
expect(actual.stdout).toContain('Get help: https://www.example.com/foo');
expect(actual.exitCode).toBe(1);
});

test('should produce no error output with --quiet flag', async () => {
const cwd = await gitBootstrap('fixtures/simple');
const actual = await cli(['--quiet'], {cwd})('foo: bar');
Expand Down
6 changes: 3 additions & 3 deletions @commitlint/cli/src/cli.ts
Expand Up @@ -229,12 +229,12 @@ async function main(options: CliFlags) {
}
);

const helpUrl = flags['help-url']?.trim() || loaded.helpUrl;

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

if (!flags.quiet && output !== '') {
Expand Down
6 changes: 6 additions & 0 deletions @commitlint/load/src/load.ts
Expand Up @@ -112,6 +112,11 @@ export default async function load(
return registry;
}, {});

const helpUrl =
typeof config.helpUrl === 'string'
? config.helpUrl
: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint';

return {
extends: preset.extends!,
formatter: preset.formatter!,
Expand All @@ -120,5 +125,6 @@ export default async function load(
defaultIgnores: preset.defaultIgnores!,
plugins: preset.plugins!,
rules: qualifiedRules,
helpUrl,
};
}
3 changes: 2 additions & 1 deletion @commitlint/load/src/utils/pick-config.ts
Expand Up @@ -10,5 +10,6 @@ export const pickConfig = (input: unknown): UserConfig =>
'parserPreset',
'formatter',
'ignores',
'defaultIgnores'
'defaultIgnores',
'helpUrl'
);
1 change: 1 addition & 0 deletions @commitlint/types/src/lint.ts
Expand Up @@ -19,6 +19,7 @@ export interface LintOptions {
parserOpts?: ParserOptions;

plugins?: PluginRecords;
helpUrl?: string;
}

export interface LintOutcome {
Expand Down
2 changes: 2 additions & 0 deletions @commitlint/types/src/load.ts
Expand Up @@ -21,6 +21,7 @@ export interface UserConfig {
ignores?: ((commit: string) => boolean)[];
defaultIgnores?: boolean;
plugins?: (string | Plugin)[];
helpUrl?: string;
}

export interface UserPreset {
Expand All @@ -43,6 +44,7 @@ export interface QualifiedConfig {
ignores: ((commit: string) => boolean)[];
defaultIgnores: boolean;
plugins: PluginRecords;
helpUrl: string;
}

export interface ParserPreset {
Expand Down
8 changes: 8 additions & 0 deletions docs/reference-api.md
Expand Up @@ -203,6 +203,10 @@ type Seed = {
* Initial map of rules to check against
*/
rules?: {[ruleName: string]: Rule};
/**
* URL to print as help for reports with problems
*/
helpUrl?: string;
};

type Config = {
Expand All @@ -218,6 +222,10 @@ type Config = {
* Merged map of rules to check against
*/
rules: {[ruleName: string]: Rule};
/**
* URL to print as help for reports with problems
*/
helpUrl?: string;
};

type LoadOptions = {
Expand Down
9 changes: 9 additions & 0 deletions docs/reference-configuration.md
Expand Up @@ -34,6 +34,10 @@ type Config = {
* Whether commitlint uses the default ignore rules.
*/
defaultIgnores?: boolean;
/*
* Custom URL to show upon failure
*/
helpUrl?: string;
};

const Configuration: Config = {
Expand Down Expand Up @@ -66,6 +70,11 @@ const Configuration: Config = {
* Whether commitlint uses the default ignore rules.
*/
defaultIgnores: true,
/*
* Custom URL to show upon failure
*/
helpUrl:
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
};

module.exports = Configuration;
Expand Down