Skip to content

Commit

Permalink
fix: types
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogobbosouza committed Jan 25, 2021
1 parent f3850c5 commit 9fca649
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 33 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ module.exports = {
rules: {
'global-require': 'off',
'import/no-dynamic-require': 'off',
'import/no-namespace': 'off',
},
};
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,16 @@ You can still force this behavior by using `emitError` **or** `emitWarning` opti
#### `emitError`

- Type: `Boolean`
- Default: `false`
- Default: `true`

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

#### `emitWarning`

- Type: `Boolean`
- Default: `false`
- Default: `true`

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

#### `failOnError`

Expand Down
3 changes: 2 additions & 1 deletion src/ESLintError.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { WebpackError } from 'webpack';
// @ts-ignore
import WebpackError from 'webpack/lib/WebpackError';

export default class ESLintError extends WebpackError {
/**
Expand Down
11 changes: 4 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { isAbsolute, join } from 'path';

// @ts-ignore
import arrify from 'arrify';
// @ts-ignore
import micromatch from 'micromatch';
import { isMatch } from 'micromatch';

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

if (
file &&
micromatch.isMatch(file, wanted) &&
!micromatch.isMatch(file, exclude)
) {
if (file && isMatch(file, wanted) && !isMatch(file, exclude)) {
// Queue file for linting.
lint(file);
}
Expand All @@ -121,10 +116,12 @@ class ESLintWebpackPlugin {
const { errors, warnings, generateReportAsset } = await report();

if (warnings) {
// @ts-ignore
compilation.warnings.push(warnings);
}

if (errors) {
// @ts-ignore
compilation.errors.push(errors);
}

Expand Down
22 changes: 6 additions & 16 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,9 @@ function parseResults(options, results) {

results.forEach((file) => {
if (fileHasErrors(file)) {
const messages = file.messages.filter((message) => {
if (options.emitError === undefined) {
return true;
} else if (options.emitError) {
return message.severity === 2;
}
return false;
});
const messages = file.messages.filter(
(message) => options.emitError && message.severity === 2
);

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

if (fileHasWarnings(file)) {
const messages = file.messages.filter((message) => {
if (options.emitWarning === undefined) {
return true;
} else if (options.emitWarning) {
return message.severity === 1;
}
return false;
});
const messages = file.messages.filter(
(message) => options.emitWarning && message.severity === 1
);

if (messages.length > 0) {
warnings.push({
Expand Down
5 changes: 4 additions & 1 deletion src/options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { validate } from 'schema-utils';

import * as schema from './options.json';
// @ts-ignore
import schema from './options.json';

/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
Expand Down Expand Up @@ -47,6 +48,8 @@ import * as schema from './options.json';
export function getOptions(pluginOptions) {
const options = {
extensions: 'js',
emitError: true,
emitWarning: true,
...pluginOptions,
...(pluginOptions.quiet ? { emitError: true, emitWarning: false } : {}),
};
Expand Down
4 changes: 2 additions & 2 deletions src/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
"type": "string"
},
"emitError": {
"description": "Will always return errors, if set to `true`.",
"description": "The errors found will always be emitted, to disable set to `false`.",
"type": "boolean"
},
"emitWarning": {
"description": "Will always return warnings, if set to `true`.",
"description": "The warnings found will always be emitted, to disable set to `false`.",
"type": "boolean"
},
"eslintPath": {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { statSync } from 'fs';

// @ts-ignore
import * as arrify from 'arrify';
import arrify from 'arrify';

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

Expand Down

0 comments on commit 9fca649

Please sign in to comment.