Skip to content

Commit 345bcf5

Browse files
authored
refactor: port config-conventional to ts (#3881)
* refactor: port config-conventional to ts * refactor: use enum instead of hardcoding
1 parent f147934 commit 345bcf5

File tree

7 files changed

+37
-24
lines changed

7 files changed

+37
-24
lines changed

@commitlint/cli/src/cli.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ async function main(args: MainArgs): Promise<void> {
286286
message: [
287287
'Please add rules to your `commitlint.config.js`',
288288
' - Getting started guide: https://commitlint.js.org/#/?id=getting-started',
289-
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js',
289+
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts',
290290
].join('\n'),
291291
},
292292
],

@commitlint/config-conventional/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
"name": "@commitlint/config-conventional",
33
"version": "18.6.0",
44
"description": "Shareable commitlint config enforcing conventional commits",
5+
"main": "lib/index.js",
56
"files": [
6-
"index.js"
7+
"lib/"
78
],
89
"scripts": {
910
"deps": "dep-check",
@@ -37,6 +38,7 @@
3738
"@commitlint/utils": "^18.4.4"
3839
},
3940
"dependencies": {
41+
"@commitlint/types": "^18.6.0",
4042
"conventional-changelog-conventionalcommits": "^7.0.2"
4143
},
4244
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"

@commitlint/config-conventional/index.test.js renamed to @commitlint/config-conventional/src/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import lint from '@commitlint/lint';
2-
import {rules, parserPreset} from '.';
2+
import {config} from '.';
33

44
const commitLint = async (message) => {
5-
const preset = await require(parserPreset)();
6-
return lint(message, rules, {...preset});
5+
const preset = await require(config.parserPreset)();
6+
return lint(message, config.rules, {...preset});
77
};
88

99
const messages = {

@commitlint/config-conventional/index.js renamed to @commitlint/config-conventional/src/index.ts

+25-15
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
module.exports = {
1+
import {
2+
RuleConfigCondition,
3+
RuleConfigSeverity,
4+
TargetCaseType,
5+
} from '@commitlint/types';
6+
7+
export const config = {
28
parserPreset: 'conventional-changelog-conventionalcommits',
39
rules: {
4-
'body-leading-blank': [1, 'always'],
5-
'body-max-line-length': [2, 'always', 100],
6-
'footer-leading-blank': [1, 'always'],
7-
'footer-max-line-length': [2, 'always', 100],
8-
'header-max-length': [2, 'always', 100],
9-
'header-trim': [2, 'always'],
10+
'body-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
11+
'body-max-line-length': [RuleConfigSeverity.Error, 'always', 100] as const,
12+
'footer-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
13+
'footer-max-line-length': [
14+
RuleConfigSeverity.Error,
15+
'always',
16+
100,
17+
] as const,
18+
'header-max-length': [RuleConfigSeverity.Error, 'always', 100] as const,
19+
'header-trim': [RuleConfigSeverity.Error, 'always'] as const,
1020
'subject-case': [
11-
2,
21+
RuleConfigSeverity.Error,
1222
'never',
1323
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
14-
],
15-
'subject-empty': [2, 'never'],
16-
'subject-full-stop': [2, 'never', '.'],
17-
'type-case': [2, 'always', 'lower-case'],
18-
'type-empty': [2, 'never'],
24+
] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]],
25+
'subject-empty': [RuleConfigSeverity.Error, 'never'] as const,
26+
'subject-full-stop': [RuleConfigSeverity.Error, 'never', '.'] as const,
27+
'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'] as const,
28+
'type-empty': [RuleConfigSeverity.Error, 'never'] as const,
1929
'type-enum': [
20-
2,
30+
RuleConfigSeverity.Error,
2131
'always',
2232
[
2333
'build',
@@ -32,7 +42,7 @@ module.exports = {
3242
'style',
3343
'test',
3444
],
35-
],
45+
] as [RuleConfigSeverity, RuleConfigCondition, string[]],
3646
},
3747
prompt: {
3848
questions: {

@commitlint/config-conventional/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
"rootDir": "./src",
66
"outDir": "./lib"
77
},
8-
"include": ["./**/*.ts"],
9-
"exclude": ["./**/*.test.ts"]
8+
"include": ["./src"],
9+
"exclude": ["./src/**/*.test.ts", "./lib/**/*"]
1010
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ These can be modified by [your own configuration](#config).
115115
- `commitlint` field in `package.json`
116116
- Packages: [cli](./@commitlint/cli), [core](./@commitlint/core)
117117
- See [Rules](./docs/reference-rules.md) for a complete list of possible rules
118-
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/index.js)
118+
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/src/index.ts)
119119

120120
## Shared configuration
121121

tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
{"path": "@commitlint/cli"},
2424
{"path": "@commitlint/travis-cli"},
2525
{"path": "@commitlint/prompt"},
26-
{"path": "@commitlint/cz-commitlint"}
26+
{"path": "@commitlint/cz-commitlint"},
27+
{"path": "@commitlint/config-conventional"}
2728
]
2829
}

0 commit comments

Comments
 (0)