diff --git a/types/tabtab/index.d.ts b/types/tabtab/index.d.ts index 05291613b2..d6b651b60c 100644 --- a/types/tabtab/index.d.ts +++ b/types/tabtab/index.d.ts @@ -1,50 +1,29 @@ -// Type definitions for tabtab 3.0.2 +// Type definitions for tabtab 3.0 // Project: https://github.com/mklabs/node-tabtab // Definitions by: Vojtěch Habarta // Kamontat Chantrachirathumrong +// ExE Boss // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.0 + +/// + +export interface InstallOptions { + /** The program to complete. */ + readonly name: string; + + /** The program that does the completion (can be the same program). */ + readonly completer: string; +} + +export interface UninstallOptions { + /** The program to remove completions for. */ + readonly name: string; +} /** - * Install option - * - * @param name is a name of the cli command - * @param completer Somethings, you want to complete another program that's where the `completer` option might come handy. + * Tabtab auto-completion environment data. */ -export type InstallOption = { - name: string; - completer: string; -}; - -/** - * Uninstall option - * - * @param name is a name of the cli command - */ -export type UninstallOption = { - name: string; -}; - -/** - * This type represent object (Json object) - */ -export type Json = { - [key: string]: string; -}; - -/** - * Tabtab environment data that return from {@link parseEnv} method - * - * @param complete A Boolean indicating whether we act in "plumbing mode" or not - * @param words The Number of words in the completed line - * @param point A Number indicating cursor position - * @param line The String input line - * @param partial The String part of line preceding cursor position - * @param last The last String word of the line - * @param lastPartial The last word String of partial - * @param prev The String word preceding last - */ -export type TabtabEnv = { +export interface TabtabEnv { /** * A Boolean indicating whether we act in "plumbing mode" or not */ @@ -79,65 +58,89 @@ export type TabtabEnv = { * The last word String of partial */ lastPartial: string; + /** * The String word preceding last */ prev: string; -}; +} /** - * this is a item to show when completion enable, - * - * @param name usually is a subcommand name or option name - * @param description this is a optional description of the completion + * A name/description pair for tab auto-complete. */ -export type CompleteItem = { +export interface CompletionItem { + /** + * The sub-command or option name. + */ name: string; - description?: string; -}; -export type CompleteItemOrString = string | CompleteItem; + /** + * The optional description of the completion. + */ + description?: string; +} + +// Legacy aliases: +export { + /** @deprecated */ + CompletionItem as CompleteItem, + /** @deprecated */ + InstallOptions as InstallOption, + /** @deprecated */ + UninstallOptions as UninstallOption, +}; +/** @deprecated */ +export type CompleteItemOrString = string | CompletionItem; /** * Install and enable completion on user system. * - * @param option install option - * + * @param options install options */ -export function install(option: InstallOption): Promise; +export function install(options: InstallOptions): Promise; /** - * Uninstall and remove all completion on user system + * Uninstall and remove completion on user system. * - * @param option uninstall option + * @param options uninstall options */ -export function uninstall(option: UninstallOption): Promise; +export function uninstall(options: UninstallOptions): Promise; /** - * Public: Main utility to extract information from command line arguments and - * Environment variables, namely COMP args in "plumbing" mode. + * Public: Main utility to extract information from command line arguments + * and Environment variables, namely COMP args in "plumbing" mode. * * @param env environment (usually will be process.env) - * @returns env is a object of completion environment + * @returns Tabtab completion information * * @example + * ```js * const env = tabtab.parseEnv(process.env); + * ``` */ -export function parseEnv(env: Json): TabtabEnv; +export function parseEnv(env: NodeJS.ProcessEnv): TabtabEnv; /** - * Helper to normalize String and Objects when logging out. + * Helper to normalize strings and objects when displaying auto-completion possibilities. + * + * @example + * ```js + * completionItem("foo: bar"); + * // => { name: "foo", description: "bar" }; + * + * completionItem({ name: "foo" }); + * // => { name: "foo" }; + * ``` */ -export function completionItem(item: CompleteItemOrString): CompleteItem; +export function completionItem(item: string | CompletionItem): CompletionItem; /** * Main logging utility to pass completion items. - * This is simply an helper to log to stdout with each item separated by a new - * line. + * This is simply an helper to log to stdout with each item separated by a new line. * * Bash needs in addition to filter out the args for the completion to work * (zsh, fish don't need this). * - * @param args Strings or Objects with name and description property. + * @param args strings or objects with name and description property. */ -export function log(args: string[] | CompleteItem[] | CompleteItemOrString[]): void; +export function log(args: Array>): void; diff --git a/types/tabtab/tabtab-tests.ts b/types/tabtab/tabtab-tests.ts index 7f8e5b4b9c..404d8c27b8 100644 --- a/types/tabtab/tabtab-tests.ts +++ b/types/tabtab/tabtab-tests.ts @@ -1,47 +1,54 @@ -/// +import { install, log, TabtabEnv, uninstall, parseEnv, completionItem } from 'tabtab'; +import minimist = require('minimist'); -import { install, log, TabtabEnv, uninstall, parseEnv } from "tabtab"; +// $ExpectType CompletionItem +completionItem({ name: 'foo' }); -const opts = require("minimist")(process.argv.slice(2), { - string: ["foo", "bar"], - boolean: ["help", "version", "loglevel"] +// $ExpectType CompletionItem +completionItem('bar'); + +const opts = minimist(process.argv.slice(2), { + string: ['foo', 'bar'], + boolean: ['help', 'version', 'loglevel'], }); const args = opts._; +// tslint:disable: no-void-expression const completion = (env: TabtabEnv) => { if (!env.complete) return; // Write your completions there - if (env.prev === "foo") { - return log(["is", "this", "the", "real", "life"]); + if (env.prev === 'foo') { + return log(['is', 'this', 'the', 'real', 'life']); } - if (env.prev === "bar") { - return log(["is", "this", "just", "fantasy"]); + if (env.prev === 'bar') { + return log(['is', 'this', 'just', 'fantasy']); } - if (env.prev === "--loglevel") { - return log(["error", "warn", "info", "notice", "verbose"]); + if (env.prev === '--loglevel') { + return log(['error', 'warn', 'info', 'notice', 'verbose']); } return log([ - "--help", - "--version", - "--loglevel", - "foo", - "bar", - "install-completion", - "completion", - "someCommand:someCommand is some kind of command with a description", + '--help', + '--version', + '--loglevel', + 'foo', + 'bar', + 'install-completion', + 'completion', + 'someCommand:someCommand is some kind of command with a description', { - name: "someOtherCommand:hey", - description: 'You must add a description for items with ":" in them' + name: 'someOtherCommand:hey', + description: 'You must add a description for items with ":" in them', }, - "anotherOne" + 'anotherOne', ]); }; +// tslint:enable: no-void-expression const run = (): Promise => { const cmd = args[0]; @@ -51,23 +58,23 @@ const run = (): Promise => { // Here we install for the program `tabtab-test` (this file), with // completer being the same program. Sometimes, you want to complete // another program that's where the `completer` option might come handy. - if (cmd === "install-completion") { + if (cmd === 'install-completion') { return install({ - name: "tabtab-test", - completer: "tabtab-test" + name: 'tabtab-test', + completer: 'tabtab-test', }); } - if (cmd === "uninstall-completion") { + if (cmd === 'uninstall-completion') { // Here we uninstall for the program `tabtab-test` (this file). return uninstall({ - name: "tabtab-test" + name: 'tabtab-test', }); } // The completion command is added automatically by tabtab when the program // is completed. - if (cmd === "completion") { + if (cmd === 'completion') { return new Promise(res => { const env = parseEnv(process.env); completion(env); @@ -78,6 +85,4 @@ const run = (): Promise => { return new Promise((_, rej) => rej()); }; -run().catch(e => { - console.error(e); -}); +run().catch(e => console.error(e)); diff --git a/types/tabtab/tsconfig.json b/types/tabtab/tsconfig.json index b2098e5326..ed69f9c8bc 100644 --- a/types/tabtab/tsconfig.json +++ b/types/tabtab/tsconfig.json @@ -1,23 +1,19 @@ { "compilerOptions": { "module": "commonjs", - "lib": [ - "es6" - ], + "lib": ["es2015"], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", - "typeRoots": [ - "../" - ], + "typeRoots": ["../"], "types": [], "noEmit": true, "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts", - "tabtab-tests.ts" + "tabtab-tests.ts", + "index.d.ts" ] -} \ No newline at end of file +} diff --git a/types/tabtab/tslint.json b/types/tabtab/tslint.json index 3d59f55fda..3db14f85ea 100644 --- a/types/tabtab/tslint.json +++ b/types/tabtab/tslint.json @@ -1,80 +1 @@ -{ - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "npm-naming": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } -} +{ "extends": "dtslint/dt.json" }