UNPKG

2.73 kBTypeScriptView Raw
1// Type definitions for jshint 2.12
2// Project: https://github.com/jshint/jshint
3// Definitions by: Amin Yahyaabadi <https://github.com/aminya>
4// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5
6export interface LintError {
7 id: string;
8 raw: string;
9 code: string;
10 evidence: string;
11 line: number;
12 character: number;
13 scope: string;
14 reason: string;
15 a?: any;
16 b?: any;
17 c?: any;
18 d?: any;
19}
20
21export type LintOptions = Record<string, any>;
22
23export interface LintFunction {
24 name: string;
25 param: any;
26 line: number;
27 character: number;
28 last: number;
29 lastcharacter: number;
30 metrics: {
31 complexity: number;
32 parameters: number;
33 statements: number;
34 };
35}
36
37export interface LintUnused {
38 name: string;
39 line: number;
40 character: number;
41}
42
43export interface LintData {
44 functions?: LintFunction[] | undefined;
45 options?: LintOptions | undefined;
46 errors?: LintError[] | undefined;
47 globals?: string[] | undefined;
48 unused?: LintUnused[] | undefined;
49 member?: any;
50 implieds?: any;
51 /* istanbul ignore next */
52 json?: any;
53}
54
55export type ModuleFunction = (api: ExtensionAPI) => void;
56
57export interface ExtensionAPI {
58 readonly isJSON: boolean;
59 getOption(name: string): unknown | null;
60}
61
62/**
63 * @param source The input JavaScript source code.
64 * Type: string or an array of strings (each element is interpreted as a newline)
65 * @example `JSHINT(["'use strict';", "console.log('hello, world!');"]);`
66 *
67 * @param options The linting options to use when analyzing the source code.
68 * Type: an object whose property names are the desired options to use and whose property values are the configuration values for those properties.
69 * @example `JSHINT(mySource, { undef: true });`
70 *
71 * @param predef variables defined outside of the current file; the behavior of this argument is identical to the globals linting option.
72 * Type: an object whose property names are the global variable identifiers and whose property values control whether each variable should be considered read-only
73 * @example `JSHINT(mySource, myOptions, { jQuery: false });`
74 */
75export function JSHINT(source: string | string[], options?: LintOptions, predef?: Record<string, boolean>): boolean;
76
77export namespace JSHINT {
78 /** An array of warnings and errors generated by the most recent invocation of JSHINT. */
79 const errors: LintError[];
80
81 /** Generate a report containing details about the most recent invocation of JSHINT. */
82 function data(): LintData | null | undefined;
83
84 function addModule(func: ModuleFunction): void;
85
86 // Circular reference from jshint.JSHINT
87 const jshint: typeof JSHINT;
88}