From d7e2e2b943be383f99f4000b6b6bed0eab03bfcf Mon Sep 17 00:00:00 2001 From: Sibiraj <20282546+sibiraj-s@users.noreply.github.com> Date: Mon, 1 Nov 2021 11:40:00 +0530 Subject: [PATCH] feat: extend helpUrl from shareable config (#2846) * docs: update deprecated npx commands * feat(load): extend helpUrl from shareable config * fix(format): don't print help text without helpUrl * docs: revert line breaks * docs: revert line breaks * docs: update README.md --- @commitlint/format/src/format.test.ts | 21 +++++++++++++++++++ @commitlint/format/src/format.ts | 7 +++++-- .../fixtures/help-url/commitlint.config.js | 3 +++ @commitlint/load/src/load.test.ts | 18 ++++++++++++++++ @commitlint/load/src/load.ts | 4 +++- @commitlint/resolve-extends/src/index.ts | 1 + README.md | 10 ++++----- docs/guides-local-setup.md | 6 +++--- 8 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 @commitlint/load/fixtures/help-url/commitlint.config.js diff --git a/@commitlint/format/src/format.test.ts b/@commitlint/format/src/format.test.ts index 745da36b21..eea046405e 100644 --- a/@commitlint/format/src/format.test.ts +++ b/@commitlint/format/src/format.test.ts @@ -257,3 +257,24 @@ test('format result omits help for empty problems', () => { expect.arrayContaining([expect.stringContaining('Get help:')]) ); }); + +test('format result should not contain `Get help` prefix if helpUrl is not provided', () => { + const actual = formatResult( + { + warnings: [ + { + level: 2, + name: 'warning-name', + message: 'There was a warning', + }, + ], + }, + { + helpUrl: '', + } + ); + + expect(actual).not.toEqual( + expect.arrayContaining([expect.stringContaining('Get help:')]) + ); +}); diff --git a/@commitlint/format/src/format.ts b/@commitlint/format/src/format.ts index bd7101954c..e3fa2dd266 100644 --- a/@commitlint/format/src/format.ts +++ b/@commitlint/format/src/format.ts @@ -89,14 +89,17 @@ export function formatResult( const fmtSummary = enabled && typeof summary === 'string' ? chalk.bold(summary) : summary; - const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined; + const help = + hasProblems && options.helpUrl + ? `ⓘ Get help: ${options.helpUrl}` + : undefined; return [ ...problems, hasProblems ? '' : undefined, fmtSummary, help, - help ? '' : undefined, + hasProblems ? '' : undefined, ].filter((line): line is string => typeof line === 'string'); } diff --git a/@commitlint/load/fixtures/help-url/commitlint.config.js b/@commitlint/load/fixtures/help-url/commitlint.config.js new file mode 100644 index 0000000000..823bde5e9a --- /dev/null +++ b/@commitlint/load/fixtures/help-url/commitlint.config.js @@ -0,0 +1,3 @@ +module.exports = { + helpUrl: 'https://github.com/conventional-changelog/commitlint' +}; diff --git a/@commitlint/load/src/load.test.ts b/@commitlint/load/src/load.test.ts index 024323d468..824c3e130e 100644 --- a/@commitlint/load/src/load.test.ts +++ b/@commitlint/load/src/load.test.ts @@ -453,3 +453,21 @@ test('resolves parser preset from conventional commits without factory support', /^(\w*)(?:\((.*)\))?!?: (.*)$/ ); }); + +test('helpUrl should be loaded from the shareable config', async () => { + const cwd = await gitBootstrap('fixtures/help-url'); + const actual = await load({}, {cwd}); + + expect(actual.helpUrl).toStrictEqual( + 'https://github.com/conventional-changelog/commitlint' + ); +}); + +test('default helpUrl should be loaded if not provided in shareable configs', async () => { + const cwd = await gitBootstrap('fixtures/basic'); + const actual = await load({}, {cwd}); + + expect(actual.helpUrl).toStrictEqual( + 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint' + ); +}); diff --git a/@commitlint/load/src/load.ts b/@commitlint/load/src/load.ts index 4b835a546f..9f54ce20fe 100644 --- a/@commitlint/load/src/load.ts +++ b/@commitlint/load/src/load.ts @@ -111,7 +111,9 @@ export default async function load( }, {}); const helpUrl = - typeof config.helpUrl === 'string' + typeof extended.helpUrl === 'string' + ? extended.helpUrl + : typeof config.helpUrl === 'string' ? config.helpUrl : 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'; diff --git a/@commitlint/resolve-extends/src/index.ts b/@commitlint/resolve-extends/src/index.ts index f8c786c18b..505316f057 100644 --- a/@commitlint/resolve-extends/src/index.ts +++ b/@commitlint/resolve-extends/src/index.ts @@ -15,6 +15,7 @@ export interface ResolvedConfig { export interface ResolveExtendsConfig { parserPreset?: unknown; extends?: string | string[]; + helpUrl?: string; [key: string]: unknown; } diff --git a/README.md b/README.md index c7b2525266..ab2ca5f816 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ npx husky install yarn husky install # Add hook -npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"' +npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"' ``` Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) on how you can automatically have Git hooks enabled after install for different `yarn` versions. @@ -193,7 +193,7 @@ is room and need for improvement. The items on the roadmap should enhance `commi ### Releases -Security patches will be applied to versions which are not yet EOL. +Security patches will be applied to versions which are not yet EOL.\ Features will only be applied to the current main version. | Release | Inital release | End-of-life | @@ -204,7 +204,7 @@ Features will only be applied to the current main version. _Dates are subject to change._ -We're not a sponsored OSS project. Therefor we can't promise that we will release patch versions for older releases in a timley manner. +We're not a sponsored OSS project. Therefor we can't promise that we will release patch versions for older releases in a timley manner.\ If you are stuck on an older version and need a security patch we're happy if you can provide a PR. ## Related projects @@ -242,7 +242,7 @@ For more information on how to contribute please take a look at our [contributio ### Publishing a release Before publishing a release do a `yarn run publish --dry-run` to get the upcoming version and update the version -in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431). +in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431).\ Commit that change before creating the new version without `--dry-run`. ```sh @@ -281,7 +281,7 @@ npx lerna publish --conventional-commits --dist-tag next --otp --tag next --otp ``` diff --git a/docs/guides-local-setup.md b/docs/guides-local-setup.md index cd1a038f1c..03a3c2aa8b 100644 --- a/docs/guides-local-setup.md +++ b/docs/guides-local-setup.md @@ -33,12 +33,12 @@ npx husky install yarn husky install # Add hook -npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1' +npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1' # or yarn husky add .husky/commit-msg 'yarn commitlint --edit $1' ``` -**Please note that currently @commitlint/cli doesn't support yarn v2 Plug'n'Play (using yarn v2 with `nodeLinker: node-modules` in your .yarnrc.yml file may work sometimes)** +**Please note that currently @commitlint/cli doesn't support yarn v2 Plug'n'Play (using yarn v2 with `nodeLinker: node-modules` in your .yarnrc.yml file may work sometimes)**\ Check the [husky documentation](https://typicode.github.io/husky/#/?id=manual) on how you can automatically have Git hooks enabled after install for different `yarn` versions. ## Test @@ -70,7 +70,7 @@ No staged files match any of provided globs. husky > commit-msg hook failed (add --no-verify to bypass) ``` -Since [v8.0.0](https://github.com/conventional-changelog/commitlint/releases/tag/v8.0.0) `commitlint` won't output anything if there is not problem with your commit. +Since [v8.0.0](https://github.com/conventional-changelog/commitlint/releases/tag/v8.0.0) `commitlint` won't output anything if there is not problem with your commit.\ (You can use the `--verbose` flag to get positive output) ```bash