From 00fcc6eca2eaa5ffca41eeec000ff80b349030bf Mon Sep 17 00:00:00 2001 From: Junyoung Choi Date: Tue, 4 Dec 2018 15:23:12 +0900 Subject: [PATCH] Add vfile-message --- types/vfile-message/index.d.ts | 74 ++++++++++++++++++++++ types/vfile-message/tsconfig.json | 22 +++++++ types/vfile-message/tslint.json | 1 + types/vfile-message/vfile-message-tests.ts | 32 ++++++++++ 4 files changed, 129 insertions(+) create mode 100644 types/vfile-message/index.d.ts create mode 100644 types/vfile-message/tsconfig.json create mode 100644 types/vfile-message/tslint.json create mode 100644 types/vfile-message/vfile-message-tests.ts diff --git a/types/vfile-message/index.d.ts b/types/vfile-message/index.d.ts new file mode 100644 index 0000000000..a39d916a34 --- /dev/null +++ b/types/vfile-message/index.d.ts @@ -0,0 +1,74 @@ +// Type definitions for vfile-message 1.0 +// Project: https://github.com/vfile/vfile-message#readme +// Definitions by: Junyoung Choi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +import * as Unist from 'unist'; + +declare namespace vfileMessage { + /** + * Create a virtual message. + */ + interface VFileMessage extends Error { + /** + * Constructor of a message for `reason` at `position` from `origin`. + * When an error is passed in as `reason`, copies the `stack`. + * + * @param reason Reason for message (`string` or `Error`). Uses the stack and message of the error if given. + * @param position Place at which the message occurred in a file (`Node`, `Position`, or `Point`, optional). + * @param origin Place in code the message originates from (`string`, optional). + */ + (reason: string | Error, position?: Unist.Node | Unist.Position | Unist.Point, origin?: string): VFileMessage + /** + * Category of message. + */ + ruleId: string | null; + /** + * Reason for message. + */ + reason: string; + /** + * Starting line of error. + */ + line: number | null; + /** + * Starting column of error. + */ + column: number | null; + /** + * Full range information, when available. + * Has start and end properties, both set to an object with line and column, set to number?. + */ + location: Unist.Position; + /** + * Namespace of warning. + */ + source: string | null; + /** + * If true, marks associated file as no longer processable. + */ + fatal?: boolean | null; + /** + * You may add a file property with a path of a file (used throughout the VFile ecosystem). + */ + file?: string; + /** + * You may add a note property with a long form description of the message (supported by vfile-reporter). + */ + note?: string; + /** + * You may add a url property with a link to documentation for the message. + */ + url?: string; + /** + * It’s OK to store custom data directly on the VMessage, some of those are handled by utilities. + */ + [key: string]: unknown; + } +} + +declare const vfileMessage: vfileMessage.VFileMessage; + +export = vfileMessage; diff --git a/types/vfile-message/tsconfig.json b/types/vfile-message/tsconfig.json new file mode 100644 index 0000000000..e740952e79 --- /dev/null +++ b/types/vfile-message/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "vfile-message-tests.ts" + ] +} diff --git a/types/vfile-message/tslint.json b/types/vfile-message/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/vfile-message/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/vfile-message/vfile-message-tests.ts b/types/vfile-message/vfile-message-tests.ts new file mode 100644 index 0000000000..ed9086631f --- /dev/null +++ b/types/vfile-message/vfile-message-tests.ts @@ -0,0 +1,32 @@ +import vfileMessage = require('vfile-message'); + +const message = vfileMessage('Error!'); +vfileMessage(new Error()); +vfileMessage('Error!', { + type: 'random node' +}); +vfileMessage('Error!', { + start: { + line: 1, + column: 1 + }, + end: { + line: 1, + column: 1 + } +}); +vfileMessage('Error!', { + line: 1, + column: 1 +}); +vfileMessage('Error!', undefined, 'test'); + +message.file = ''; +message.name = ''; +message.reason = ''; +message.message = ''; +message.stack = ''; +message.fatal = null; +message.fatal = true; +message.column = 1; +message.line = 1;