Skip to content

Commit 9fca649

Browse files
fix: types
1 parent f3850c5 commit 9fca649

File tree

8 files changed

+23
-33
lines changed

8 files changed

+23
-33
lines changed

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ module.exports = {
44
rules: {
55
'global-require': 'off',
66
'import/no-dynamic-require': 'off',
7-
'import/no-namespace': 'off',
87
},
98
};

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

src/ESLintError.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { WebpackError } from 'webpack';
1+
// @ts-ignore
2+
import WebpackError from 'webpack/lib/WebpackError';
23

34
export default class ESLintError extends WebpackError {
45
/**

src/index.js

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

33
// @ts-ignore
44
import arrify from 'arrify';
5-
// @ts-ignore
6-
import micromatch from 'micromatch';
5+
import { isMatch } from 'micromatch';
76

87
import { getOptions } from './options';
98
import linter from './linter';
@@ -101,11 +100,7 @@ class ESLintWebpackPlugin {
101100
if (module.resource) {
102101
const [file] = module.resource.split('?');
103102

104-
if (
105-
file &&
106-
micromatch.isMatch(file, wanted) &&
107-
!micromatch.isMatch(file, exclude)
108-
) {
103+
if (file && isMatch(file, wanted) && !isMatch(file, exclude)) {
109104
// Queue file for linting.
110105
lint(file);
111106
}
@@ -121,10 +116,12 @@ class ESLintWebpackPlugin {
121116
const { errors, warnings, generateReportAsset } = await report();
122117

123118
if (warnings) {
119+
// @ts-ignore
124120
compilation.warnings.push(warnings);
125121
}
126122

127123
if (errors) {
124+
// @ts-ignore
128125
compilation.errors.push(errors);
129126
}
130127

src/linter.js

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,9 @@ function parseResults(options, results) {
187187

188188
results.forEach((file) => {
189189
if (fileHasErrors(file)) {
190-
const messages = file.messages.filter((message) => {
191-
if (options.emitError === undefined) {
192-
return true;
193-
} else if (options.emitError) {
194-
return message.severity === 2;
195-
}
196-
return false;
197-
});
190+
const messages = file.messages.filter(
191+
(message) => options.emitError && message.severity === 2
192+
);
198193

199194
if (messages.length > 0) {
200195
errors.push({
@@ -205,14 +200,9 @@ function parseResults(options, results) {
205200
}
206201

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

217207
if (messages.length > 0) {
218208
warnings.push({

src/options.js

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

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

56
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
67
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
@@ -47,6 +48,8 @@ import * as 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
};

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { statSync } from 'fs';
22

33
// @ts-ignore
4-
import * as arrify from 'arrify';
4+
import arrify from 'arrify';
55

66
const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
77

0 commit comments

Comments
 (0)