Skip to content

Commit

Permalink
refactor: port config-conventional to ts (#3881)
Browse files Browse the repository at this point in the history
* refactor: port config-conventional to ts

* refactor: use enum instead of hardcoding
  • Loading branch information
Mersho authored Jan 30, 2024
1 parent f147934 commit 345bcf5
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
2 changes: 1 addition & 1 deletion @commitlint/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ async function main(args: MainArgs): Promise<void> {
message: [
'Please add rules to your `commitlint.config.js`',
' - Getting started guide: https://commitlint.js.org/#/?id=getting-started',
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/index.js',
' - Example config: https://github.com/conventional-changelog/commitlint/blob/master/%40commitlint/config-conventional/src/index.ts',
].join('\n'),
},
],
Expand Down
4 changes: 3 additions & 1 deletion @commitlint/config-conventional/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"name": "@commitlint/config-conventional",
"version": "18.6.0",
"description": "Shareable commitlint config enforcing conventional commits",
"main": "lib/index.js",
"files": [
"index.js"
"lib/"
],
"scripts": {
"deps": "dep-check",
Expand Down Expand Up @@ -37,6 +38,7 @@
"@commitlint/utils": "^18.4.4"
},
"dependencies": {
"@commitlint/types": "^18.6.0",
"conventional-changelog-conventionalcommits": "^7.0.2"
},
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import lint from '@commitlint/lint';
import {rules, parserPreset} from '.';
import {config} from '.';

const commitLint = async (message) => {
const preset = await require(parserPreset)();
return lint(message, rules, {...preset});
const preset = await require(config.parserPreset)();
return lint(message, config.rules, {...preset});
};

const messages = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,33 @@
module.exports = {
import {
RuleConfigCondition,
RuleConfigSeverity,
TargetCaseType,
} from '@commitlint/types';

export const config = {
parserPreset: 'conventional-changelog-conventionalcommits',
rules: {
'body-leading-blank': [1, 'always'],
'body-max-line-length': [2, 'always', 100],
'footer-leading-blank': [1, 'always'],
'footer-max-line-length': [2, 'always', 100],
'header-max-length': [2, 'always', 100],
'header-trim': [2, 'always'],
'body-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
'body-max-line-length': [RuleConfigSeverity.Error, 'always', 100] as const,
'footer-leading-blank': [RuleConfigSeverity.Warning, 'always'] as const,
'footer-max-line-length': [
RuleConfigSeverity.Error,
'always',
100,
] as const,
'header-max-length': [RuleConfigSeverity.Error, 'always', 100] as const,
'header-trim': [RuleConfigSeverity.Error, 'always'] as const,
'subject-case': [
2,
RuleConfigSeverity.Error,
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
] as [RuleConfigSeverity, RuleConfigCondition, TargetCaseType[]],
'subject-empty': [RuleConfigSeverity.Error, 'never'] as const,
'subject-full-stop': [RuleConfigSeverity.Error, 'never', '.'] as const,
'type-case': [RuleConfigSeverity.Error, 'always', 'lower-case'] as const,
'type-empty': [RuleConfigSeverity.Error, 'never'] as const,
'type-enum': [
2,
RuleConfigSeverity.Error,
'always',
[
'build',
Expand All @@ -32,7 +42,7 @@ module.exports = {
'style',
'test',
],
],
] as [RuleConfigSeverity, RuleConfigCondition, string[]],
},
prompt: {
questions: {
Expand Down
4 changes: 2 additions & 2 deletions @commitlint/config-conventional/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"rootDir": "./src",
"outDir": "./lib"
},
"include": ["./**/*.ts"],
"exclude": ["./**/*.test.ts"]
"include": ["./src"],
"exclude": ["./src/**/*.test.ts", "./lib/**/*"]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ These can be modified by [your own configuration](#config).
- `commitlint` field in `package.json`
- Packages: [cli](./@commitlint/cli), [core](./@commitlint/core)
- See [Rules](./docs/reference-rules.md) for a complete list of possible rules
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/index.js)
- An example configuration can be found at [@commitlint/config-conventional](./@commitlint/config-conventional/src/index.ts)

## Shared configuration

Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{"path": "@commitlint/cli"},
{"path": "@commitlint/travis-cli"},
{"path": "@commitlint/prompt"},
{"path": "@commitlint/cz-commitlint"}
{"path": "@commitlint/cz-commitlint"},
{"path": "@commitlint/config-conventional"}
]
}

0 comments on commit 345bcf5

Please sign in to comment.