feat: add @commitlint/load (#42616)

* feat: add @commitlint/load

* fix: remove trailing comma in json

* fix: allow optional const enum

This const enum is not required for the definition to be useful.
This commit is contained in:
Martin McWhorter
2020-02-26 19:50:54 +00:00
committed by GitHub
parent 2c629e1f09
commit ea796eec56
4 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
import commitlintLoad, { Level } from '@commitlint/load';
// $ExpectType Promise<CommitlintConfig>
commitlintLoad();
commitlintLoad().then(config => {
config.rules["body-leading-blank"] = [Level.Warn, 'always', undefined];
config.rules["body-max-length"] = [1, 'never', 72];
config.rules["header-case"] = [Level.Disable, 'always', 'camel-case'];
config.rules["type-enum"] = [Level.Error, 'always', ['foo', 'bar', 'baz']];
config.extends = ['foo'];
});

68
types/commitlint__load/index.d.ts vendored Normal file
View File

@@ -0,0 +1,68 @@
// Type definitions for @commitlint/load 8.3
// Project: https://github.com/conventional-changelog/commitlint
// Definitions by: Martin McWhorter <https://github.com/martinmcwhorter>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export default function commitlintLoad(): Promise<CommitlintConfig>;
export type Case =
| 'lower-case'
| 'lowercase'
| 'lowerCase'
| 'upper-case'
| 'uppercase'
| 'camel-case'
| 'kebab-case'
| 'pascal-case'
| 'sentence-case'
| 'sentencecase'
| 'start-case'
| 'snake-case';
export type Applicability = 'always' | 'never';
export type Rule<T> = [Level | 0 | 1 | 2, Applicability, T];
export interface Rules {
'body-leading-blank'?: Rule<undefined>;
'body-max-length'?: Rule<number>;
'body-max-line-length'?: Rule<number>;
'body-min-length'?: Rule<number>;
'footer-leading-blank'?: Rule<undefined>;
'footer-max-length'?: Rule<number>;
'footer-min-length'?: Rule<number>;
'footer-max-line-length'?: Rule<number>;
'header-case'?: Rule<Case>;
'header-full-stop'?: Rule<string>;
'header-max-length'?: Rule<number>;
'header-min-length'?: Rule<number>;
'references-empty'?: Rule<undefined>;
'scope-enum'?: Rule<string[]>;
'scope-case'?: Rule<Case>;
'scope-empty'?: Rule<undefined>;
'scope-max-length'?: Rule<number>;
'scope-min-length'?: Rule<number>;
'subject-case'?: Rule<Case | Case[]>;
'subject-empty'?: Rule<undefined>;
'subject-full-stop'?: Rule<string>;
'subject-max-length'?: Rule<number>;
'subject-min-length'?: Rule<number>;
'type-enum'?: Rule<string[]>;
'type-case'?: Rule<Case>;
'type-empty'?: Rule<undefined>;
'type-max-length'?: Rule<number>;
'type-min-length'?: Rule<number>;
'signed-off-by'?: Rule<string>;
}
export interface CommitlintConfig {
extends?: string[];
rules: Rules;
}
// tslint:disable-next-line:no-const-enum
export const enum Level {
Disable = 0,
Warn = 1,
Error = 2,
}

View File

@@ -0,0 +1,26 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@commitlint/load": ["commitlint__load"]
}
},
"files": [
"index.d.ts",
"commitlint__load-tests.ts"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }