Skip to content

Commit 7ee16de

Browse files
feat: add types
1 parent a3df4f9 commit 7ee16de

23 files changed

+696
-207
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,19 @@ Specify directories, files, or globs. Must be relative to `options.context`.
8585
Directories are traveresed recursively looking for files matching `options.extensions`.
8686
File and glob patterns ignore `options.extensions`.
8787

88+
### `extensions`
89+
90+
- Type: `String|Array[String]`
91+
- Default: `'js'`
92+
93+
Specify extensions that should be checked.
94+
8895
### `fix`
8996

9097
- Type: `Boolean`
9198
- Default: `false`
9299

93-
Will enable [ESLint autofix feature](http://eslint.org/docs/user-guide/command-line-interface#fix).
100+
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-eslint-outputfixes-results).
94101

95102
**Be careful: this option will change source files.**
96103

declarations/DirtyFileWatcher.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default class DirtyFileWatcher {
2+
/**
3+
* @param {string|string[]=} files
4+
* @param {string|string[]=} extensions
5+
*/
6+
constructor(
7+
files?: (string | string[]) | undefined,
8+
extensions?: (string | string[]) | undefined
9+
);
10+
startTime: number;
11+
prevTimestamps: Map<any, any>;
12+
isFirstRun: boolean;
13+
globs: string[];
14+
/**
15+
* @param {Map<string,number>=} fileTimestamps
16+
* @returns {string[]}
17+
*/
18+
getDirtyFiles(fileTimestamps?: Map<string, number> | undefined): string[];
19+
/**
20+
* @param {Map<string,number>} fileTimestamps
21+
* @param {string|string[]} globs
22+
* @returns {string[]}
23+
*/
24+
filterChangedFiles(
25+
fileTimestamps: Map<string, number>,
26+
globs: string | string[]
27+
): string[];
28+
}

declarations/ESLintError.d.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export default class ESLintError extends Error {
2-
constructor(messages: any);
3-
stack: boolean;
2+
/**
3+
* @param {string=} messages
4+
*/
5+
constructor(messages?: string | undefined);
46
}

declarations/LintDirtyModulesPlugin.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

declarations/getCLIEngine.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

declarations/getESLint.d.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/** @typedef {import('eslint').ESLint} ESLint */
2+
/** @typedef {import('./options').Options} Options */
3+
/**
4+
* @param {Options} options
5+
* @returns {{ESLint: ESLint, eslint: ESLint}}
6+
*/
7+
export default function getESLint(
8+
options: Options
9+
): {
10+
ESLint: import('eslint').ESLint;
11+
eslint: import('eslint').ESLint;
12+
};
13+
export type ESLint = import('eslint').ESLint;
14+
export type Options = {
15+
context?: string | undefined;
16+
emitError?: boolean | undefined;
17+
emitWarning?: boolean | undefined;
18+
eslintPath?: string | undefined;
19+
failOnError?: boolean | undefined;
20+
failOnWarning?: boolean | undefined;
21+
files?: string | string[] | undefined;
22+
extensions?: string | string[] | undefined;
23+
fix?: boolean | undefined;
24+
formatter?: string | import('./options').FormatterFunction | undefined;
25+
lintDirtyModulesOnly?: boolean | undefined;
26+
quiet?: boolean | undefined;
27+
outputReport?: import('./options').OutputReport | undefined;
28+
};

declarations/getOptions.d.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

declarations/index.d.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
11
export default ESLintWebpackPlugin;
2+
export type Compiler = import('webpack').Compiler;
3+
export type Options = {
4+
context?: string | undefined;
5+
emitError?: boolean | undefined;
6+
emitWarning?: boolean | undefined;
7+
eslintPath?: string | undefined;
8+
failOnError?: boolean | undefined;
9+
failOnWarning?: boolean | undefined;
10+
files?: string | string[] | undefined;
11+
extensions?: string | string[] | undefined;
12+
fix?: boolean | undefined;
13+
formatter?: string | import('./options').FormatterFunction | undefined;
14+
lintDirtyModulesOnly?: boolean | undefined;
15+
quiet?: boolean | undefined;
16+
outputReport?: import('./options').OutputReport | undefined;
17+
};
18+
/** @typedef {import('webpack').Compiler} Compiler */
19+
/** @typedef {import('./options').Options} Options */
220
declare class ESLintWebpackPlugin {
3-
constructor(options?: {});
4-
options: any;
5-
apply(compiler: any): void;
6-
getContext(compiler: any): any;
21+
/**
22+
* @param {Options} options
23+
*/
24+
constructor(options?: Options);
25+
options: import('./options').Options;
26+
/**
27+
* @param {Compiler} compiler
28+
* @returns {void}
29+
*/
30+
apply(compiler: Compiler): void;
31+
/**
32+
*
33+
* @param {Compiler} compiler
34+
* @returns {string}
35+
*/
36+
getContext(compiler: Compiler): string;
737
}

declarations/linter.d.ts

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,38 @@
1+
/** @typedef {import('eslint').ESLint} ESLint */
2+
/** @typedef {import('eslint').ESLint.Formatter} Formatter */
3+
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
4+
/** @typedef {import('webpack').Compiler} Compiler */
5+
/** @typedef {import('./options').Options} Options */
6+
/** @typedef {import('./options').FormatterFunction} FormatterFunction */
7+
/**
8+
* @param {Options} options
9+
* @param {Compiler} compiler
10+
* @returns {Promise<void>}
11+
*/
112
export default function linter(
2-
options: any,
3-
compiler: any,
4-
callback: any
5-
): void;
13+
options: Options,
14+
compiler: Compiler
15+
): Promise<void>;
16+
export type ESLint = import('eslint').ESLint;
17+
export type Formatter = import('eslint').ESLint.Formatter;
18+
export type LintResult = import('eslint').ESLint.LintResult;
19+
export type Compiler = import('webpack').Compiler;
20+
export type Options = {
21+
context?: string | undefined;
22+
emitError?: boolean | undefined;
23+
emitWarning?: boolean | undefined;
24+
eslintPath?: string | undefined;
25+
failOnError?: boolean | undefined;
26+
failOnWarning?: boolean | undefined;
27+
files?: string | string[] | undefined;
28+
extensions?: string | string[] | undefined;
29+
fix?: boolean | undefined;
30+
formatter?: string | import('./options').FormatterFunction | undefined;
31+
lintDirtyModulesOnly?: boolean | undefined;
32+
quiet?: boolean | undefined;
33+
outputReport?: import('./options').OutputReport | undefined;
34+
};
35+
export type FormatterFunction = (
36+
results: import('eslint').ESLint.LintResult[],
37+
data?: import('eslint').ESLint.LintResultData | undefined
38+
) => string;

declarations/options.d.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
2+
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
3+
/** @typedef {import('eslint').ESLint.LintResultData} LintResultData */
4+
/**
5+
* @callback FormatterFunction
6+
* @param {LintResult[]} results
7+
* @param {LintResultData=} data
8+
* @returns {string}
9+
*/
10+
/**
11+
* @typedef {Object} OutputReport
12+
* @property {string=} filePath
13+
* @property {string|FormatterFunction=} formatter
14+
*/
15+
/**
16+
* @typedef {Object} Options
17+
* @property {string=} context
18+
* @property {boolean=} emitError
19+
* @property {boolean=} emitWarning
20+
* @property {string=} eslintPath
21+
* @property {boolean=} failOnError
22+
* @property {boolean=} failOnWarning
23+
* @property {string|string[]=} files
24+
* @property {string|string[]=} extensions
25+
* @property {boolean=} fix
26+
* @property {string|FormatterFunction=} formatter
27+
* @property {boolean=} lintDirtyModulesOnly
28+
* @property {boolean=} quiet
29+
* @property {OutputReport=} outputReport
30+
*/
31+
/**
32+
* @param {Options} pluginOptions
33+
* @returns {Options}
34+
*/
35+
export function getOptions(pluginOptions: Options): Options;
36+
/**
37+
* @param {Options} loaderOptions
38+
* @returns {ESLintOptions}
39+
*/
40+
export function getESLintOptions(loaderOptions: Options): ESLintOptions;
41+
export type ESLintOptions = import('eslint').ESLint.Options;
42+
export type LintResult = import('eslint').ESLint.LintResult;
43+
export type LintResultData = import('eslint').ESLint.LintResultData;
44+
export type FormatterFunction = (
45+
results: LintResult[],
46+
data?: LintResultData | undefined
47+
) => string;
48+
export type OutputReport = {
49+
filePath?: string | undefined;
50+
formatter?: (string | FormatterFunction) | undefined;
51+
};
52+
export type Options = {
53+
context?: string | undefined;
54+
emitError?: boolean | undefined;
55+
emitWarning?: boolean | undefined;
56+
eslintPath?: string | undefined;
57+
failOnError?: boolean | undefined;
58+
failOnWarning?: boolean | undefined;
59+
files?: (string | string[]) | undefined;
60+
extensions?: (string | string[]) | undefined;
61+
fix?: boolean | undefined;
62+
formatter?: (string | FormatterFunction) | undefined;
63+
lintDirtyModulesOnly?: boolean | undefined;
64+
quiet?: boolean | undefined;
65+
outputReport?: OutputReport | undefined;
66+
};

0 commit comments

Comments
 (0)