diff --git a/@commitlint/cli/fixtures/help-url/commitlint.config.js b/@commitlint/cli/fixtures/help-url/commitlint.config.js new file mode 100644 index 0000000000..ab43d7482a --- /dev/null +++ b/@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' +}; diff --git a/@commitlint/cli/src/cli.test.ts b/@commitlint/cli/src/cli.test.ts index 654ac2721d..4cc3a304ea 100644 --- a/@commitlint/cli/src/cli.test.ts +++ b/@commitlint/cli/src/cli.test.ts @@ -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'); diff --git a/@commitlint/cli/src/cli.ts b/@commitlint/cli/src/cli.ts index 950521817c..b8d4b127a2 100644 --- a/@commitlint/cli/src/cli.ts +++ b/@commitlint/cli/src/cli.ts @@ -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 !== '') { diff --git a/@commitlint/load/src/load.ts b/@commitlint/load/src/load.ts index 93097a81fc..f6b2e7d002 100644 --- a/@commitlint/load/src/load.ts +++ b/@commitlint/load/src/load.ts @@ -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!, @@ -120,5 +125,6 @@ export default async function load( defaultIgnores: preset.defaultIgnores!, plugins: preset.plugins!, rules: qualifiedRules, + helpUrl, }; } diff --git a/@commitlint/load/src/utils/pick-config.ts b/@commitlint/load/src/utils/pick-config.ts index 881db12103..e5e01181c0 100644 --- a/@commitlint/load/src/utils/pick-config.ts +++ b/@commitlint/load/src/utils/pick-config.ts @@ -10,5 +10,6 @@ export const pickConfig = (input: unknown): UserConfig => 'parserPreset', 'formatter', 'ignores', - 'defaultIgnores' + 'defaultIgnores', + 'helpUrl' ); diff --git a/@commitlint/types/src/lint.ts b/@commitlint/types/src/lint.ts index e9f047e9e0..60f0a9456c 100644 --- a/@commitlint/types/src/lint.ts +++ b/@commitlint/types/src/lint.ts @@ -19,6 +19,7 @@ export interface LintOptions { parserOpts?: ParserOptions; plugins?: PluginRecords; + helpUrl?: string; } export interface LintOutcome { diff --git a/@commitlint/types/src/load.ts b/@commitlint/types/src/load.ts index cfcd59acc4..481b477e0f 100644 --- a/@commitlint/types/src/load.ts +++ b/@commitlint/types/src/load.ts @@ -21,6 +21,7 @@ export interface UserConfig { ignores?: ((commit: string) => boolean)[]; defaultIgnores?: boolean; plugins?: (string | Plugin)[]; + helpUrl?: string; } export interface UserPreset { @@ -43,6 +44,7 @@ export interface QualifiedConfig { ignores: ((commit: string) => boolean)[]; defaultIgnores: boolean; plugins: PluginRecords; + helpUrl: string; } export interface ParserPreset { diff --git a/docs/reference-api.md b/docs/reference-api.md index 0ed9d63dc1..95c4d6bd74 100644 --- a/docs/reference-api.md +++ b/docs/reference-api.md @@ -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 = { @@ -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 = { diff --git a/docs/reference-configuration.md b/docs/reference-configuration.md index 926b9df87d..2a1f7582fb 100644 --- a/docs/reference-configuration.md +++ b/docs/reference-configuration.md @@ -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 = { @@ -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;