diff --git a/types/markdownlint/index.d.ts b/types/markdownlint/index.d.ts new file mode 100644 index 0000000000..5e66f15185 --- /dev/null +++ b/types/markdownlint/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for markdownlint 0.6 +// Project: https://github.com/DavidAnson/markdownlint +// Definitions by: ark120202 +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare function markdownlint( + options: markdownlint.MarkdownlintOptions, + callback: (err: Error | null, result: markdownlint.MarkdownlintResults) => any, +): void; + +declare namespace markdownlint { + function sync(options: MarkdownlintOptions): MarkdownlintResults; + + function readConfig( + file: string, + callback: (err: Error | null, result: MarkdownlintConfig) => any, + ): void; + function readConfigSync(file: string): MarkdownlintConfig; + + interface MarkdownlintConfig { + [rule: string]: boolean | { [key: string]: any }; + } + + interface MarkdownlintOptions { + files?: ReadonlyArray | string; + strings?: { [identifier: string]: string }; + config?: MarkdownlintConfig; + frontMatter?: RegExp; + noInlineConfig?: boolean; + resultVersion?: number; + } + + interface MarkdownlintResult { + lineNumber: number; + ruleName: string; + ruleAlias: string; + ruleDescription: string; + errorDetail?: string; + errorContext: string; + errorRange?: [number, number]; + } + + interface MarkdownlintResults { + [source: string]: MarkdownlintResult[] | ((useAlias?: boolean) => string); + toString(useAlias?: boolean): string; + } +} + +export = markdownlint; diff --git a/types/markdownlint/markdownlint-tests.ts b/types/markdownlint/markdownlint-tests.ts new file mode 100644 index 0000000000..faca81872d --- /dev/null +++ b/types/markdownlint/markdownlint-tests.ts @@ -0,0 +1,38 @@ +import * as markdownlint from 'markdownlint'; + +const config: markdownlint.MarkdownlintConfig = { + default: true, + MD003: { style: 'atx_closed' }, + MD007: { indent: 4 }, + 'no-hard-tabs': false, + whitespace: false, +}; + +const options: markdownlint.MarkdownlintOptions = { + files: ['README.md'], + strings: { 'file.md': 'Header' }, + config, + noInlineConfig: false, + resultVersion: 1, +}; + +// $ExpectType MarkdownlintResults +const results = markdownlint.sync(options); + +markdownlint(options, (err, results) => { + // $ExpectType Error | null + err; + + // $ExpectType MarkdownlintResults + results; + + const resultString: string = results.toString(); + // $ExpectError + results.toString() as markdownlint.MarkdownlintResult[]; + + const fileErrors: markdownlint.MarkdownlintResult[] = results[ + 'file.md' + ] as markdownlint.MarkdownlintResult[]; + const firstFileError: markdownlint.MarkdownlintResult = fileErrors[0]; + const firstFileErrorRule: string = firstFileError.ruleName; +}); diff --git a/types/markdownlint/tsconfig.json b/types/markdownlint/tsconfig.json new file mode 100644 index 0000000000..53b9ae46aa --- /dev/null +++ b/types/markdownlint/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "markdownlint-tests.ts" + ] +} diff --git a/types/markdownlint/tslint.json b/types/markdownlint/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/markdownlint/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }