Skip to content

Commit 40f8c67

Browse files
authored
Merge branch 'master' into refactor/prompt2
2 parents 3ab85e2 + a1ddfcf commit 40f8c67

File tree

10 files changed

+170
-61
lines changed

10 files changed

+170
-61
lines changed

@commitlint/config-patternplate/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Additionally these rules apply:
1919

2020
### Problems
2121

22-
The following rules are considered problems for `@commitlint/config-patterplate` and will yield a non-zero exit code when not met.
22+
The following rules are considered problems for `@commitlint/config-patternplate` and will yield a non-zero exit code when not met.
2323

2424
#### scope-enum
2525

@commitlint/format/src/format.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function formatResult(
6666
const problems = [...errors, ...warnings].map((problem) => {
6767
const sign = signs[problem.level] || '';
6868
const color: ChalkColor = colors[problem.level] || ('white' as const);
69-
const decoration = enabled ? ((chalk as any)[color] as any)(sign) : sign;
69+
const decoration = enabled ? chalk[color](sign) : sign;
7070
const name = enabled
7171
? chalk.grey(`[${problem.name}]`)
7272
: `[${problem.name}]`;
@@ -76,7 +76,7 @@ export function formatResult(
7676
const sign = selectSign(result);
7777
const color = selectColor(result);
7878

79-
const deco = enabled ? (chalk[color] as any)(sign) : sign;
79+
const deco = enabled ? chalk[color](sign) : sign;
8080
const el = errors.length;
8181
const wl = warnings.length;
8282
const hasProblems = problems.length > 0;
@@ -109,7 +109,7 @@ function selectSign(result: FormattableResult): string {
109109
return (result.warnings || []).length ? '⚠' : '✔';
110110
}
111111

112-
function selectColor(result: FormattableResult): keyof typeof chalk {
112+
function selectColor(result: FormattableResult): ChalkColor {
113113
if ((result.errors || []).length > 0) {
114114
return 'red';
115115
}

@commitlint/load/src/utils/load-plugin.test.ts

+49
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import loadPlugin from './load-plugin';
2+
import {AsyncRule, Plugin, Rule, SyncRule} from '@commitlint/types';
23

34
jest.mock('commitlint-plugin-example', () => ({example: true}), {
45
virtual: true,
@@ -8,6 +9,39 @@ jest.mock('@scope/commitlint-plugin-example', () => ({scope: true}), {
89
virtual: true,
910
});
1011

12+
jest.mock(
13+
'commitlint-plugin-rule',
14+
(): Plugin => {
15+
const rule: Rule<number> = (_parsed, when, _value) => {
16+
return [when === 'never'];
17+
};
18+
return {rules: {rule}};
19+
},
20+
{virtual: true}
21+
);
22+
23+
jest.mock(
24+
'commitlint-plugin-sync-rule',
25+
(): Plugin => {
26+
const syncRule: SyncRule<number> = (_parsed, when, _value) => {
27+
return [when === 'never'];
28+
};
29+
return {rules: {syncRule}};
30+
},
31+
{virtual: true}
32+
);
33+
34+
jest.mock(
35+
'commitlint-plugin-async-rule',
36+
(): Plugin => {
37+
const asyncRule: AsyncRule<number> = (_parsed, when, _value) => {
38+
return new Promise(() => [when === 'never']);
39+
};
40+
return {rules: {asyncRule}};
41+
},
42+
{virtual: true}
43+
);
44+
1145
test('should load a plugin when referenced by short name', () => {
1246
const plugins = loadPlugin({}, 'example');
1347
expect(plugins['example']).toBe(require('commitlint-plugin-example'));
@@ -18,6 +52,21 @@ test('should load a plugin when referenced by long name', () => {
1852
expect(plugins['example']).toBe(require('commitlint-plugin-example'));
1953
});
2054

55+
test('should load a plugin with a rule', () => {
56+
const plugins = loadPlugin({}, 'commitlint-plugin-rule');
57+
expect(plugins['rule']).toBe(require('commitlint-plugin-rule'));
58+
});
59+
60+
test('should load a plugin with a sync rule', () => {
61+
const plugins = loadPlugin({}, 'commitlint-plugin-sync-rule');
62+
expect(plugins['sync-rule']).toBe(require('commitlint-plugin-sync-rule'));
63+
});
64+
65+
test('should load a plugin with an async rule', () => {
66+
const plugins = loadPlugin({}, 'commitlint-plugin-async-rule');
67+
expect(plugins['async-rule']).toBe(require('commitlint-plugin-async-rule'));
68+
});
69+
2170
test('should throw an error when a plugin has whitespace', () => {
2271
expect(() => loadPlugin({}, 'whitespace ')).toThrow(
2372
"Whitespace found in plugin name 'whitespace '"

@commitlint/rules/src/index.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from 'path';
2+
import fs from 'fs';
23
import globby from 'globby';
34
import rules from '.';
45

@@ -13,6 +14,19 @@ test('rules export functions', () => {
1314
expect(actual.every((rule) => typeof rule === 'function')).toBe(true);
1415
});
1516

17+
test('all rules are present in documentation', () => {
18+
const file = fs.readFileSync(
19+
path.join(__dirname, '../../../docs/reference-rules.md'),
20+
'utf-8'
21+
);
22+
const results = file
23+
.split(/(\n|\r)/)
24+
.filter((s) => s.startsWith('####') && !s.includes('`deprecated`'))
25+
.map((s) => s.replace('#### ', ''));
26+
27+
expect(Object.keys(rules)).toEqual(expect.arrayContaining(results));
28+
});
29+
1630
async function glob(pattern: string | string[]) {
1731
const files = await globby(pattern, {
1832
ignore: ['**/index.ts', '**/*.test.ts'],

@commitlint/types/src/format.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export interface FormattableReport {
2626
results?: (FormattableResult & WithInput)[];
2727
}
2828

29-
export type ChalkColor = keyof typeof chalk;
29+
export type ChalkColor = typeof chalk.Color | typeof chalk.Modifiers;
3030

3131
export interface FormatOptions {
3232
color?: boolean;

@commitlint/types/src/load.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
import {Rule, RulesConfig, RuleConfigQuality} from './rules';
1+
import {
2+
Rule,
3+
RulesConfig,
4+
RuleConfigQuality,
5+
AsyncRule,
6+
SyncRule,
7+
} from './rules';
28

39
export type PluginRecords = Record<string, Plugin>;
410

511
export interface Plugin {
612
rules: {
7-
[ruleName: string]: Rule<unknown>;
13+
[ruleName: string]: Rule | AsyncRule | SyncRule;
814
};
915
}
1016

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fix(server): send cors headers
6060
feat(blog): add comment section
6161
```
6262

63-
Common types according to [commitlint-config-conventional (based on the the Angular convention)](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum) can be:
63+
Common types according to [commitlint-config-conventional (based on the Angular convention)](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum) can be:
6464

6565
- build
6666
- ci

docs/reference-rules.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ Rule configurations are either of type `array` residing on a key with the rule's
5757
- **condition**: `body` begins with blank line
5858
- **rule**: `always`
5959

60+
#### body-empty
61+
62+
- **condition**: `body` is empty
63+
- **rule**: `never`
64+
6065
#### body-max-length
6166

6267
- **condition**: `body` has `value` or less characters
@@ -87,11 +92,41 @@ Infinity
8792
0
8893
```
8994

95+
#### body-case
96+
97+
- **condition**: `header` is in case `value`
98+
- **rule**: `always`
99+
- **value**
100+
101+
```
102+
'lower-case'
103+
```
104+
105+
- **possible values**
106+
107+
```
108+
[
109+
'lower-case', // default
110+
'upper-case', // UPPERCASE
111+
'camel-case', // camelCase
112+
'kebab-case', // kebab-case
113+
'pascal-case', // PascalCase
114+
'sentence-case', // Sentence case
115+
'snake-case', // snake_case
116+
'start-case' // Start Case
117+
]
118+
```
119+
90120
#### footer-leading-blank
91121

92122
- **condition**: `footer` begins with blank line
93123
- **rule**: `always`
94124

125+
#### footer-empty
126+
127+
- **condition**: `footer` is empty
128+
- **rule**: `never`
129+
95130
#### footer-max-length
96131

97132
- **condition**: `footer` has `value` or less characters
@@ -129,7 +164,7 @@ Infinity
129164
- **value**
130165

131166
```
132-
'lowerCase'
167+
'lower-case'
133168
```
134169

135170
- **possible values**
@@ -198,7 +233,7 @@ Infinity
198233
- **value**
199234

200235
```
201-
'lowerCase'
236+
'lower-case'
202237
```
203238

204239
- **possible values**
@@ -248,7 +283,7 @@ Infinity
248283
- **value**
249284

250285
```
251-
'lowerCase'
286+
'lower-case'
252287
```
253288

254289
- **possible values**

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
"@babel/preset-env": "^7.12.11",
8282
"@lerna/project": "3.21.0",
8383
"@types/jest": "26.0.20",
84-
"@types/node": "12.19.14",
84+
"@types/node": "12.19.15",
8585
"@typescript-eslint/eslint-plugin": "^4.1.0",
8686
"@typescript-eslint/parser": "^4.1.0",
8787
"docsify-cli": "^4.4.0",

0 commit comments

Comments
 (0)