Skip to content

Commit

Permalink
feat: extend helpUrl from shareable config (#2846)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sibiraj-s authored Nov 1, 2021
1 parent e8b6ebf commit d7e2e2b
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 11 deletions.
21 changes: 21 additions & 0 deletions @commitlint/format/src/format.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:')])
);
});
7 changes: 5 additions & 2 deletions @commitlint/format/src/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down
3 changes: 3 additions & 0 deletions @commitlint/load/fixtures/help-url/commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
helpUrl: 'https://github.com/conventional-changelog/commitlint'
};
18 changes: 18 additions & 0 deletions @commitlint/load/src/load.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
4 changes: 3 additions & 1 deletion @commitlint/load/src/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
1 change: 1 addition & 0 deletions @commitlint/resolve-extends/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ResolvedConfig {
export interface ResolveExtendsConfig {
parserPreset?: unknown;
extends?: string | string[];
helpUrl?: string;
[key: string]: unknown;
}

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -281,7 +281,7 @@ npx lerna publish --conventional-commits --dist-tag next --otp <one-time passwor

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

```
```sh
npm publish <package-name> --tag next --otp <one-time password>
```

Expand Down
6 changes: 3 additions & 3 deletions docs/guides-local-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d7e2e2b

Please sign in to comment.