From ea796eec563efb5bf07f8ee0d8b51c74fcc1b690 Mon Sep 17 00:00:00 2001 From: Martin McWhorter Date: Wed, 26 Feb 2020 19:50:54 +0000 Subject: [PATCH] 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. --- .../commitlint__load-tests.ts | 12 ++++ types/commitlint__load/index.d.ts | 68 +++++++++++++++++++ types/commitlint__load/tsconfig.json | 26 +++++++ types/commitlint__load/tslint.json | 1 + 4 files changed, 107 insertions(+) create mode 100644 types/commitlint__load/commitlint__load-tests.ts create mode 100644 types/commitlint__load/index.d.ts create mode 100644 types/commitlint__load/tsconfig.json create mode 100644 types/commitlint__load/tslint.json diff --git a/types/commitlint__load/commitlint__load-tests.ts b/types/commitlint__load/commitlint__load-tests.ts new file mode 100644 index 0000000000..3219097139 --- /dev/null +++ b/types/commitlint__load/commitlint__load-tests.ts @@ -0,0 +1,12 @@ +import commitlintLoad, { Level } from '@commitlint/load'; + +// $ExpectType Promise +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']; +}); diff --git a/types/commitlint__load/index.d.ts b/types/commitlint__load/index.d.ts new file mode 100644 index 0000000000..9677a6a21a --- /dev/null +++ b/types/commitlint__load/index.d.ts @@ -0,0 +1,68 @@ +// Type definitions for @commitlint/load 8.3 +// Project: https://github.com/conventional-changelog/commitlint +// Definitions by: Martin McWhorter +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export default function commitlintLoad(): Promise; + +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 = [Level | 0 | 1 | 2, Applicability, T]; + +export interface Rules { + 'body-leading-blank'?: Rule; + 'body-max-length'?: Rule; + 'body-max-line-length'?: Rule; + 'body-min-length'?: Rule; + 'footer-leading-blank'?: Rule; + 'footer-max-length'?: Rule; + 'footer-min-length'?: Rule; + 'footer-max-line-length'?: Rule; + 'header-case'?: Rule; + 'header-full-stop'?: Rule; + 'header-max-length'?: Rule; + 'header-min-length'?: Rule; + 'references-empty'?: Rule; + 'scope-enum'?: Rule; + 'scope-case'?: Rule; + 'scope-empty'?: Rule; + 'scope-max-length'?: Rule; + 'scope-min-length'?: Rule; + 'subject-case'?: Rule; + 'subject-empty'?: Rule; + 'subject-full-stop'?: Rule; + 'subject-max-length'?: Rule; + 'subject-min-length'?: Rule; + 'type-enum'?: Rule; + 'type-case'?: Rule; + 'type-empty'?: Rule; + 'type-max-length'?: Rule; + 'type-min-length'?: Rule; + 'signed-off-by'?: Rule; +} + +export interface CommitlintConfig { + extends?: string[]; + rules: Rules; +} + +// tslint:disable-next-line:no-const-enum +export const enum Level { + Disable = 0, + Warn = 1, + Error = 2, +} diff --git a/types/commitlint__load/tsconfig.json b/types/commitlint__load/tsconfig.json new file mode 100644 index 0000000000..b15dc12fab --- /dev/null +++ b/types/commitlint__load/tsconfig.json @@ -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" + ] +} diff --git a/types/commitlint__load/tslint.json b/types/commitlint__load/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/commitlint__load/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }