From 8d4301f28e251bf3fa4f5ffe1349a6ea362f7bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20B=C5=82a=C5=BCejewicz=20=28Peter=20Blazejewicz=29?= Date: Tue, 14 Apr 2020 00:31:23 +0200 Subject: [PATCH] feat(pretty-quick): new type definition (#43867) - definition file - tests https://www.npmjs.com/package/pretty-quick Thanks! --- types/pretty-quick/index.d.ts | 48 ++++++++++++++++++++++++ types/pretty-quick/pretty-quick-tests.ts | 44 ++++++++++++++++++++++ types/pretty-quick/tsconfig.json | 23 ++++++++++++ types/pretty-quick/tslint.json | 1 + 4 files changed, 116 insertions(+) create mode 100644 types/pretty-quick/index.d.ts create mode 100644 types/pretty-quick/pretty-quick-tests.ts create mode 100644 types/pretty-quick/tsconfig.json create mode 100644 types/pretty-quick/tslint.json diff --git a/types/pretty-quick/index.d.ts b/types/pretty-quick/index.d.ts new file mode 100644 index 0000000000..c2a335b2a6 --- /dev/null +++ b/types/pretty-quick/index.d.ts @@ -0,0 +1,48 @@ +// Type definitions for pretty-quick 2.0 +// Project: https://github.com/azz/pretty-quick#readme +// Definitions by: Piotr Błażejewicz +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import { ResolveConfigOptions } from 'prettier'; + +declare namespace prettyQuick { + interface Options { + config?: ResolveConfigOptions; + since?: string; + /** @default false */ + staged?: boolean; + pattern?: string | string[]; + /** @default true */ + restage?: boolean; + /** + * @default 'master' | 'default' + */ + branch?: string; + bail?: boolean; + check?: boolean; + verbose?: boolean; + onFoundSinceRevision?: (name: string, revision: string) => void; + onFoundChangedFiles?: (changedFiles: string[]) => void; + onPartiallyStagedFile?: (file: string) => void; + onExamineFile?: (file: string) => void; + onCheckFile?: (file: string, isFormatted: boolean) => void; + onWriteFile?: (file: string) => void; + // ...args support + [key: string]: any; + } + + interface Results { + readonly success: boolean; + readonly errors: string[]; + } +} + +/** + * Runs Prettier on your changed files. + * Supported source control managers: + * * Git + * * Mercurial + */ +declare function prettyQuick(currentDirectory: string, options?: prettyQuick.Options): prettyQuick.Results; + +export = prettyQuick; diff --git a/types/pretty-quick/pretty-quick-tests.ts b/types/pretty-quick/pretty-quick-tests.ts new file mode 100644 index 0000000000..28dd34365a --- /dev/null +++ b/types/pretty-quick/pretty-quick-tests.ts @@ -0,0 +1,44 @@ +/// +import mri = require('mri'); + +import prettyQuick = require('pretty-quick'); +const args = mri(process.argv.slice(2)); + +const prettyQuickResult = prettyQuick(process.cwd(), { + ...args, + onFoundSinceRevision: (scm, revision) => { + scm; // $ExpectType string + revision; // $ExpectType string + }, + + onFoundChangedFiles: changedFiles => { + changedFiles; // $ExpectType string[] + }, + + onPartiallyStagedFile: file => { + file; // $ExpectType string + }, + + onWriteFile: file => { + file; // $ExpectType string + }, + + onCheckFile: (file, isFormatted) => { + file; // $ExpectType string + isFormatted; // $ExpectedType boolean + }, + + onExamineFile: file => { + file; // $ExpectType string + }, +}); + +prettyQuickResult.success; // $ExpectType boolean +prettyQuickResult.errors; // $ExpectType string[] + +if (prettyQuickResult.success) { + prettyQuickResult.success; // $ExpectType true +} else { + prettyQuickResult.success; // $ExpectType false + process.exit(1); +} diff --git a/types/pretty-quick/tsconfig.json b/types/pretty-quick/tsconfig.json new file mode 100644 index 0000000000..1ab636453c --- /dev/null +++ b/types/pretty-quick/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "pretty-quick-tests.ts" + ] +} diff --git a/types/pretty-quick/tslint.json b/types/pretty-quick/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/pretty-quick/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }