Skip to content

Commit d7e2e2b

Browse files
authored
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
1 parent e8b6ebf commit d7e2e2b

File tree

8 files changed

+59
-11
lines changed

8 files changed

+59
-11
lines changed

@commitlint/format/src/format.test.ts

+21
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,24 @@ test('format result omits help for empty problems', () => {
257257
expect.arrayContaining([expect.stringContaining('Get help:')])
258258
);
259259
});
260+
261+
test('format result should not contain `Get help` prefix if helpUrl is not provided', () => {
262+
const actual = formatResult(
263+
{
264+
warnings: [
265+
{
266+
level: 2,
267+
name: 'warning-name',
268+
message: 'There was a warning',
269+
},
270+
],
271+
},
272+
{
273+
helpUrl: '',
274+
}
275+
);
276+
277+
expect(actual).not.toEqual(
278+
expect.arrayContaining([expect.stringContaining('Get help:')])
279+
);
280+
});

@commitlint/format/src/format.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,17 @@ export function formatResult(
8989
const fmtSummary =
9090
enabled && typeof summary === 'string' ? chalk.bold(summary) : summary;
9191

92-
const help = hasProblems ? `ⓘ Get help: ${options.helpUrl}` : undefined;
92+
const help =
93+
hasProblems && options.helpUrl
94+
? `ⓘ Get help: ${options.helpUrl}`
95+
: undefined;
9396

9497
return [
9598
...problems,
9699
hasProblems ? '' : undefined,
97100
fmtSummary,
98101
help,
99-
help ? '' : undefined,
102+
hasProblems ? '' : undefined,
100103
].filter((line): line is string => typeof line === 'string');
101104
}
102105

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
helpUrl: 'https://github.com/conventional-changelog/commitlint'
3+
};

@commitlint/load/src/load.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -453,3 +453,21 @@ test('resolves parser preset from conventional commits without factory support',
453453
/^(\w*)(?:\((.*)\))?!?: (.*)$/
454454
);
455455
});
456+
457+
test('helpUrl should be loaded from the shareable config', async () => {
458+
const cwd = await gitBootstrap('fixtures/help-url');
459+
const actual = await load({}, {cwd});
460+
461+
expect(actual.helpUrl).toStrictEqual(
462+
'https://github.com/conventional-changelog/commitlint'
463+
);
464+
});
465+
466+
test('default helpUrl should be loaded if not provided in shareable configs', async () => {
467+
const cwd = await gitBootstrap('fixtures/basic');
468+
const actual = await load({}, {cwd});
469+
470+
expect(actual.helpUrl).toStrictEqual(
471+
'https://github.com/conventional-changelog/commitlint/#what-is-commitlint'
472+
);
473+
});

@commitlint/load/src/load.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ export default async function load(
111111
}, {});
112112

113113
const helpUrl =
114-
typeof config.helpUrl === 'string'
114+
typeof extended.helpUrl === 'string'
115+
? extended.helpUrl
116+
: typeof config.helpUrl === 'string'
115117
? config.helpUrl
116118
: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint';
117119

@commitlint/resolve-extends/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface ResolvedConfig {
1515
export interface ResolveExtendsConfig {
1616
parserPreset?: unknown;
1717
extends?: string | string[];
18+
helpUrl?: string;
1819
[key: string]: unknown;
1920
}
2021

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ npx husky install
106106
yarn husky install
107107

108108
# Add hook
109-
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit "$1"'
109+
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
110110
```
111111

112112
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
193193

194194
### Releases
195195

196-
Security patches will be applied to versions which are not yet EOL.
196+
Security patches will be applied to versions which are not yet EOL.\
197197
Features will only be applied to the current main version.
198198

199199
| Release | Inital release | End-of-life |
@@ -204,7 +204,7 @@ Features will only be applied to the current main version.
204204

205205
_Dates are subject to change._
206206

207-
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.
207+
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.\
208208
If you are stuck on an older version and need a security patch we're happy if you can provide a PR.
209209

210210
## Related projects
@@ -242,7 +242,7 @@ For more information on how to contribute please take a look at our [contributio
242242
### Publishing a release
243243

244244
Before publishing a release do a `yarn run publish --dry-run` to get the upcoming version and update the version
245-
in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431).
245+
in the [`should print help` test](https://github.com/conventional-changelog/commitlint/blob/master/@commitlint/cli/src/cli.test.ts#L431).\
246246
Commit that change before creating the new version without `--dry-run`.
247247

248248
```sh
@@ -281,7 +281,7 @@ npx lerna publish --conventional-commits --dist-tag next --otp <one-time passwor
281281

282282
If for some reason this stops in between, you can manually publish missing packages like this:
283283

284-
```
284+
```sh
285285
npm publish <package-name> --tag next --otp <one-time password>
286286
```
287287

docs/guides-local-setup.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ npx husky install
3333
yarn husky install
3434

3535
# Add hook
36-
npx husky add .husky/commit-msg 'npx --no-install commitlint --edit $1'
36+
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'
3737
# or
3838
yarn husky add .husky/commit-msg 'yarn commitlint --edit $1'
3939
```
4040

41-
**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)**
41+
**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)**\
4242
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.
4343

4444
## Test
@@ -70,7 +70,7 @@ No staged files match any of provided globs.
7070
husky > commit-msg hook failed (add --no-verify to bypass)
7171
```
7272

73-
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.
73+
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.\
7474
(You can use the `--verbose` flag to get positive output)
7575

7676
```bash

0 commit comments

Comments
 (0)