Skip to content

Commit 4daddf5

Browse files
fix: types (#66)
* fix: types * fix: remove `allowSyntheticDefaultImports` * fix: types * fix: types
1 parent cef4f74 commit 4daddf5

File tree

11 files changed

+40
-50
lines changed

11 files changed

+40
-50
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ You can still force this behavior by using `emitError` **or** `emitWarning` opti
174174
#### `emitError`
175175

176176
- Type: `Boolean`
177-
- Default: `false`
177+
- Default: `true`
178178

179-
Will always return errors, if set to `true`.
179+
The errors found will always be emitted, to disable set to `false`.
180180

181181
#### `emitWarning`
182182

183183
- Type: `Boolean`
184-
- Default: `false`
184+
- Default: `true`
185185

186-
Will always return warnings, if set to `true`.
186+
The warnings found will always be emitted, to disable set to `false`.
187187

188188
#### `failOnError`
189189

declarations/ESLintError.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
export default class ESLintError {
1+
export default class ESLintError extends WebpackError {
22
/**
33
* @param {string=} messages
44
*/
55
constructor(messages?: string | undefined);
6-
name: string;
7-
stack: string;
86
}
7+
import { WebpackError } from 'webpack';

declarations/cjs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
declare const _exports: typeof import('.').ESLintWebpackPlugin;
1+
declare const _exports: typeof import('.').default;
22
export = _exports;

declarations/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
export class ESLintWebpackPlugin {
1+
export default ESLintWebpackPlugin;
2+
export type Compiler = import('webpack').Compiler;
3+
export type Options = import('./options').PluginOptions &
4+
import('eslint').ESLint.Options;
5+
declare class ESLintWebpackPlugin {
26
/**
37
* @param {Options} options
48
*/
@@ -21,7 +25,3 @@ export class ESLintWebpackPlugin {
2125
*/
2226
getContext(compiler: Compiler): string;
2327
}
24-
export default ESLintWebpackPlugin;
25-
export type Compiler = import('webpack').Compiler;
26-
export type Options = import('./options').PluginOptions &
27-
import('eslint').ESLint.Options;

src/getESLint.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os from 'os';
1+
import { cpus } from 'os';
22

33
import JestWorker from 'jest-worker';
44

@@ -96,7 +96,7 @@ export default function getESLint(key, { threads, ...options }) {
9696
const max =
9797
typeof threads !== 'number'
9898
? threads
99-
? os.cpus().length - 1
99+
? cpus().length - 1
100100
: 1
101101
: /* istanbul ignore next */
102102
threads;

src/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { isAbsolute, join } from 'path';
22

3+
// @ts-ignore
34
import arrify from 'arrify';
4-
import micromatch from 'micromatch';
5+
import { isMatch } from 'micromatch';
56

67
import { getOptions } from './options';
78
import linter from './linter';
@@ -13,7 +14,7 @@ import { parseFiles, parseFoldersToGlobs } from './utils';
1314
const ESLINT_PLUGIN = 'ESLintWebpackPlugin';
1415
let counter = 0;
1516

16-
export class ESLintWebpackPlugin {
17+
class ESLintWebpackPlugin {
1718
/**
1819
* @param {Options} options
1920
*/
@@ -99,11 +100,7 @@ export class ESLintWebpackPlugin {
99100
if (module.resource) {
100101
const [file] = module.resource.split('?');
101102

102-
if (
103-
file &&
104-
micromatch.isMatch(file, wanted) &&
105-
!micromatch.isMatch(file, exclude)
106-
) {
103+
if (file && isMatch(file, wanted) && !isMatch(file, exclude)) {
107104
// Queue file for linting.
108105
lint(file);
109106
}

src/linter.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,26 @@ export default function linter(key, options, compilation) {
112112
*/
113113
async function generateReportAsset({ compiler }) {
114114
const { outputReport } = options;
115-
// @ts-ignore
115+
/**
116+
* @param {string} name
117+
* @param {string | Buffer} content
118+
*/
116119
const save = (name, content) =>
117-
new Promise((finish, bail) => {
120+
/** @type {Promise<void>} */ (new Promise((finish, bail) => {
118121
const { mkdir, writeFile } = compiler.outputFileSystem;
119122
// ensure directory exists
120123
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
121124
mkdir(dirname(name), { recursive: true }, (err) => {
122125
/* istanbul ignore if */
123126
if (err) bail(err);
124-
// @ts-ignore
125127
else
126128
writeFile(name, content, (err2) => {
127129
/* istanbul ignore if */
128130
if (err2) bail(err2);
129131
else finish();
130132
});
131133
});
132-
});
134+
}));
133135

134136
if (!outputReport || !outputReport.filePath) {
135137
return;
@@ -185,14 +187,9 @@ function parseResults(options, results) {
185187

186188
results.forEach((file) => {
187189
if (fileHasErrors(file)) {
188-
const messages = file.messages.filter((message) => {
189-
if (options.emitError === undefined) {
190-
return true;
191-
} else if (options.emitError) {
192-
return message.severity === 2;
193-
}
194-
return false;
195-
});
190+
const messages = file.messages.filter(
191+
(message) => options.emitError && message.severity === 2
192+
);
196193

197194
if (messages.length > 0) {
198195
errors.push({
@@ -203,14 +200,9 @@ function parseResults(options, results) {
203200
}
204201

205202
if (fileHasWarnings(file)) {
206-
const messages = file.messages.filter((message) => {
207-
if (options.emitWarning === undefined) {
208-
return true;
209-
} else if (options.emitWarning) {
210-
return message.severity === 1;
211-
}
212-
return false;
213-
});
203+
const messages = file.messages.filter(
204+
(message) => options.emitWarning && message.severity === 1
205+
);
214206

215207
if (messages.length > 0) {
216208
warnings.push({

src/options.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { validate } from 'schema-utils';
22

3+
// @ts-ignore
34
import schema from './options.json';
45

56
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
@@ -47,6 +48,8 @@ import schema from './options.json';
4748
export function getOptions(pluginOptions) {
4849
const options = {
4950
extensions: 'js',
51+
emitError: true,
52+
emitWarning: true,
5053
...pluginOptions,
5154
...(pluginOptions.quiet ? { emitError: true, emitWarning: false } : {}),
5255
};
@@ -77,6 +80,5 @@ export function getESLintOptions(loaderOptions) {
7780
delete eslintOptions[option];
7881
}
7982

80-
// @ts-ignore
8183
return eslintOptions;
8284
}

src/options.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"type": "string"
88
},
99
"emitError": {
10-
"description": "Will always return errors, if set to `true`.",
10+
"description": "The errors found will always be emitted, to disable set to `false`.",
1111
"type": "boolean"
1212
},
1313
"emitWarning": {
14-
"description": "Will always return warnings, if set to `true`.",
14+
"description": "The warnings found will always be emitted, to disable set to `false`.",
1515
"type": "boolean"
1616
},
1717
"eslintPath": {

src/utils.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { statSync } from 'fs';
22

3+
// @ts-ignore
34
import arrify from 'arrify';
45

56
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
@@ -11,7 +12,7 @@ const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
1112
*/
1213
export function parseFiles(files, context) {
1314
return arrify(files).map(
14-
(file) =>
15+
(/** @type {string} */ file) =>
1516
`${replaceBackslashes(context).replace(
1617
UNESCAPED_GLOB_SYMBOLS_RE,
1718
'\\$2'
@@ -36,12 +37,12 @@ export function parseFoldersToGlobs(patterns, extensions = []) {
3637
const extensionsList = arrify(extensions);
3738
const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', ''];
3839
const extensionsGlob = extensionsList
39-
.map((extension) => extension.replace(/^\./u, ''))
40+
.map((/** @type {string} */ extension) => extension.replace(/^\./u, ''))
4041
.join(',');
4142

4243
return arrify(patterns)
43-
.map((pattern) => replaceBackslashes(pattern))
44-
.map((pattern) => {
44+
.map((/** @type {string} */ pattern) => replaceBackslashes(pattern))
45+
.map((/** @type {string} */ pattern) => {
4546
try {
4647
// The patterns are absolute because they are prepended with the context.
4748
const stats = statSync(pattern);

0 commit comments

Comments
 (0)