Socket
Socket
Sign inDemoInstall

eslint-webpack-plugin

Package Overview
Dependencies
Maintainers
4
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-webpack-plugin - npm Package Compare versions

Comparing version 3.1.1 to 3.2.0

types/ESLintError.d.ts

10

dist/ESLintError.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
class ESLintError extends Error {

@@ -13,3 +8,3 @@ /**

constructor(messages) {
super(messages);
super(`[eslint] ${messages}`);
this.name = 'ESLintError';

@@ -21,3 +16,2 @@ this.stack = '';

var _default = ESLintError;
exports.default = _default;
module.exports = ESLintError;

51

dist/getESLint.js
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = getESLint;
exports.loadESLint = loadESLint;
exports.loadESLintThreaded = loadESLintThreaded;
const {
cpus
} = require('os');
var _os = require("os");
const {
Worker: JestWorker
} = require('jest-worker');
var _jestWorker = require("jest-worker");
const {
getESLintOptions
} = require('./options');
var _options = require("./options");
const {
jsonStringifyReplacerSortKeys
} = require('./utils');
/** @type {{[key: string]: any}} */
var _utils = require("./utils");
/** @type {{[key: string]: any}} */
const cache = {};

@@ -30,6 +32,6 @@ /** @typedef {import('eslint').ESLint} ESLint */

/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
/**

@@ -50,3 +52,3 @@ * @param {Options} options

const eslint = new ESLint((0, _options.getESLintOptions)(options));
const eslint = new ESLint(getESLintOptions(options));
return {

@@ -90,12 +92,9 @@ threads: 1,

eslintPath,
eslintOptions: (0, _options.getESLintOptions)(options)
eslintOptions: getESLintOptions(options)
}]
};
const local = loadESLint(options);
let worker =
/** @type {Worker?} */
// prettier-ignore
let worker =
/** @type {Worker} */
new _jestWorker.Worker(source, workerOptions);
new JestWorker(source, workerOptions);
/** @type {Linter} */

@@ -132,3 +131,3 @@

}) {
const max = typeof threads !== 'number' ? threads ? (0, _os.cpus)().length - 1 : 1 :
const max = typeof threads !== 'number' ? threads ? cpus().length - 1 : 1 :
/* istanbul ignore next */

@@ -158,3 +157,9 @@ threads;

options
}, _utils.jsonStringifyReplacerSortKeys);
}
}, jsonStringifyReplacerSortKeys);
}
module.exports = {
loadESLint,
loadESLintThreaded,
getESLint
};
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
const {
isAbsolute,
join
} = require('path');
var _path = require("path");
const {
isMatch
} = require('micromatch');
var _micromatch = require("micromatch");
const {
getOptions
} = require('./options');
var _options = require("./options");
const linter = require('./linter');
var _linter = _interopRequireDefault(require("./linter"));
const {
arrify,
parseFiles,
parseFoldersToGlobs
} = require('./utils');
/** @typedef {import('webpack').Compiler} Compiler */
var _utils = require("./utils");
/** @typedef {import('./options').Options} Options */
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/** @typedef {import('webpack').Compiler} Compiler */
/** @typedef {import('./options').Options} Options */
const ESLINT_PLUGIN = 'ESLintWebpackPlugin';

@@ -32,3 +37,3 @@ let counter = 0;

this.key = ESLINT_PLUGIN;
this.options = (0, _options.getOptions)(options);
this.options = getOptions(options);
this.run = this.run.bind(this);

@@ -47,8 +52,9 @@ }

const options = { ...this.options,
exclude: (0, _utils.parseFiles)(this.options.exclude || [], this.getContext(compiler)),
extensions: (0, _utils.arrify)(this.options.extensions),
files: (0, _utils.parseFiles)(this.options.files || '', this.getContext(compiler))
exclude: parseFiles(this.options.exclude || [], this.getContext(compiler)),
extensions: arrify(this.options.extensions),
resourceQueryExclude: arrify(this.options.resourceQueryExclude || []).map(item => item instanceof RegExp ? item : new RegExp(item)),
files: parseFiles(this.options.files || '', this.getContext(compiler))
};
const wanted = (0, _utils.parseFoldersToGlobs)(options.files, options.extensions);
const exclude = (0, _utils.parseFoldersToGlobs)(this.options.exclude ? options.exclude : '**/node_modules/**', []); // If `lintDirtyModulesOnly` is disabled,
const wanted = parseFoldersToGlobs(options.files, options.extensions);
const exclude = parseFoldersToGlobs(this.options.exclude ? options.exclude : '**/node_modules/**', []); // If `lintDirtyModulesOnly` is disabled,
// execute the linter on the build

@@ -72,3 +78,3 @@

* @param {Compiler} compiler
* @param {Options} options
* @param {Omit<Options, 'resourceQueryExclude'> & {resourceQueryExclude: RegExp[]}} options
* @param {string[]} wanted

@@ -103,3 +109,3 @@ * @param {string[]} exclude

threads
} = (0, _linter.default)(this.key, options, compilation));
} = linter(this.key, options, compilation));
} catch (e) {

@@ -119,9 +125,9 @@ compilation.errors.push(e);

if (resource) {
const [file] = resource.split('?');
const [file, query] = resource.split('?');
if (file && !files.includes(file) && (0, _micromatch.isMatch)(file, wanted, {
if (file && !files.includes(file) && isMatch(file, wanted, {
dot: true
}) && !(0, _micromatch.isMatch)(file, exclude, {
}) && !isMatch(file, exclude, {
dot: true
})) {
}) && options.resourceQueryExclude.every(reg => !reg.test(query))) {
files.push(file);

@@ -185,4 +191,4 @@

if (!(0, _path.isAbsolute)(this.options.context)) {
return (0, _path.join)(String(compiler.options.context), this.options.context);
if (!isAbsolute(this.options.context)) {
return join(String(compiler.options.context), this.options.context);
}

@@ -195,3 +201,2 @@

var _default = ESLintWebpackPlugin;
exports.default = _default;
module.exports = ESLintWebpackPlugin;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = linter;
const {
dirname,
isAbsolute,
join
} = require('path');
var _path = require("path");
const ESLintError = require('./ESLintError');
var _ESLintError = _interopRequireDefault(require("./ESLintError"));
var _getESLint = _interopRequireDefault(require("./getESLint"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const {
getESLint
} = require('./getESLint');
/** @typedef {import('eslint').ESLint} ESLint */

@@ -41,2 +39,4 @@

/** @type {WeakMap<Compiler, LintResultMap>} */
const resultStorage = new WeakMap();

@@ -73,5 +73,5 @@ /**

threads
} = (0, _getESLint.default)(key, options));
} = getESLint(key, options));
} catch (e) {
throw new _ESLintError.default(e.message);
throw new ESLintError(e.message);
}

@@ -94,3 +94,4 @@

rawResults.push(lintFiles(files).catch(e => {
compilation.errors.push(e);
// @ts-ignore
compilation.errors.push(new ESLintError(e.message));
return [];

@@ -120,3 +121,3 @@ }));

warnings
} = formatResults(formatter, parseResults(options, results));
} = await formatResults(formatter, parseResults(options, results));
return {

@@ -152,3 +153,3 @@ errors,

mkdir((0, _path.dirname)(name), {
mkdir(dirname(name), {
recursive: true

@@ -168,3 +169,3 @@ }, err => {

const content = outputReport.formatter ? (await loadFormatter(eslint, outputReport.formatter)).format(results) : formatter.format(results);
const content = await (outputReport.formatter ? (await loadFormatter(eslint, outputReport.formatter)).format(results) : formatter.format(results));
let {

@@ -174,4 +175,4 @@ filePath

if (!(0, _path.isAbsolute)(filePath)) {
filePath = (0, _path.join)(compiler.outputPath, filePath);
if (!isAbsolute(filePath)) {
filePath = join(compiler.outputPath, filePath);
}

@@ -186,7 +187,7 @@

* @param {{ errors: LintResult[]; warnings: LintResult[]; }} results
* @returns {{errors?: ESLintError, warnings?: ESLintError}}
* @returns {Promise<{errors?: ESLintError, warnings?: ESLintError}>}
*/
function formatResults(formatter, results) {
async function formatResults(formatter, results) {
let errors;

@@ -196,7 +197,7 @@ let warnings;

if (results.warnings.length > 0) {
warnings = new _ESLintError.default(formatter.format(results.warnings));
warnings = new ESLintError(await formatter.format(results.warnings));
}
if (results.errors.length > 0) {
errors = new _ESLintError.default(formatter.format(results.errors));
errors = new ESLintError(await formatter.format(results.errors));
}

@@ -348,2 +349,4 @@

return Array.isArray(x) ? x : [x];
}
}
module.exports = linter;
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getESLintOptions = getESLintOptions;
exports.getOptions = getOptions;
const {
validate
} = require('schema-utils');
var _schemaUtils = require("schema-utils");
var _options = _interopRequireDefault(require("./options.json"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// @ts-ignore
const schema = require('./options.json');
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */

@@ -53,2 +44,3 @@

* @property {number|boolean=} threads
* @property {RegExp|RegExp[]=} resourceQueryExclude
*/

@@ -62,2 +54,4 @@

*/
function getOptions(pluginOptions) {

@@ -69,2 +63,3 @@ const options = {

failOnError: true,
resourceQueryExclude: [],
...pluginOptions,

@@ -77,3 +72,3 @@ ...(pluginOptions.quiet ? {

(0, _schemaUtils.validate)(_options.default, options, {
validate(schema, options, {
name: 'ESLint Webpack Plugin',

@@ -98,3 +93,3 @@ baseDataPath: 'options'

...eslintOnlyOptions
} = _options.default.properties; // No need to guard the for-in because schema.properties has hardcoded keys.
} = schema.properties; // No need to guard the for-in because schema.properties has hardcoded keys.
// eslint-disable-next-line guard-for-in

@@ -108,2 +103,7 @@

return eslintOptions;
}
}
module.exports = {
getOptions,
getESLintOptions
};

@@ -25,2 +25,6 @@ {

},
"resourceQueryExclude": {
"description": "Specify the resource query to exclude.",
"anyOf": [{ "instanceof": "RegExp" }, { "type": "array" }]
},
"failOnError": {

@@ -27,0 +31,0 @@ "description": "Will cause the module build to fail if there are any errors, to disable set to `false`.",

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.arrify = arrify;
exports.jsonStringifyReplacerSortKeys = void 0;
exports.parseFiles = parseFiles;
exports.parseFoldersToGlobs = parseFoldersToGlobs;
const {
resolve
} = require('path');
var _path = require("path");
const {
statSync
} = require('fs');
var _fs = require("fs");
var _normalizePath = _interopRequireDefault(require("normalize-path"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// @ts-ignore
const normalizePath = require('normalize-path');
/**

@@ -38,2 +29,4 @@ * @template T

/* istanbul ignore next */
function arrify(value) {

@@ -75,3 +68,3 @@ // eslint-disable-next-line no-undefined

/** @type {string} */
file) => (0, _normalizePath.default)((0, _path.resolve)(context, file)));
file) => normalizePath(resolve(context, file)));
}

@@ -96,3 +89,3 @@ /**

// The patterns are absolute because they are prepended with the context.
const stats = (0, _fs.statSync)(pattern);
const stats = statSync(pattern);
/* istanbul ignore else */

@@ -129,2 +122,7 @@

exports.jsonStringifyReplacerSortKeys = jsonStringifyReplacerSortKeys;
module.exports = {
arrify,
parseFiles,
parseFoldersToGlobs,
jsonStringifyReplacerSortKeys
};
{
"name": "eslint-webpack-plugin",
"version": "3.1.1",
"version": "3.2.0",
"description": "A ESLint plugin for webpack",

@@ -14,4 +14,4 @@ "license": "MIT",

},
"main": "dist/cjs.js",
"types": "declarations/index.d.ts",
"main": "dist/index.js",
"types": "types/index.d.ts",
"engines": {

@@ -22,5 +22,5 @@ "node": ">= 12.13.0"

"start": "npm run build -- -w",
"clean": "del-cli dist declarations",
"clean": "del-cli dist types",
"prebuild": "npm run clean",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir declarations && prettier \"declarations/**/*.ts\" --write",
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types && prettier \"types/**/*.ts\" --write",
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",

@@ -44,3 +44,3 @@ "build": "npm-run-all -p \"build:**\"",

"dist",
"declarations"
"types"
],

@@ -52,14 +52,14 @@ "peerDependencies": {

"dependencies": {
"@types/eslint": "^7.28.2",
"jest-worker": "^27.3.1",
"micromatch": "^4.0.4",
"@types/eslint": "^7.29.0 || ^8.4.1",
"jest-worker": "^28.0.2",
"micromatch": "^4.0.5",
"normalize-path": "^3.0.0",
"schema-utils": "^3.1.1"
"schema-utils": "^4.0.0"
},
"devDependencies": {
"@babel/cli": "^7.15.7",
"@babel/core": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@commitlint/cli": "^13.2.1",
"@commitlint/config-conventional": "^13.2.0",
"@babel/cli": "^7.17.10",
"@babel/core": "^7.17.10",
"@babel/preset-env": "^7.17.10",
"@commitlint/cli": "^16.2.4",
"@commitlint/config-conventional": "^16.2.4",
"@types/fs-extra": "^9.0.13",

@@ -71,19 +71,19 @@ "@types/micromatch": "^4.0.2",

"babel-eslint": "^10.1.0",
"babel-jest": "^27.3.1",
"chokidar": "^3.5.2",
"babel-jest": "^28.0.3",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"del": "^6.0.0",
"del-cli": "^4.0.1",
"eslint": "^8.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.2",
"fs-extra": "^10.0.0",
"eslint": "^8.14.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"fs-extra": "^10.1.0",
"husky": "^7.0.4",
"jest": "^27.3.1",
"lint-staged": "^11.2.5",
"jest": "^28.0.3",
"lint-staged": "^12.4.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"prettier": "^2.6.2",
"standard-version": "^9.3.2",
"typescript": "^4.4.4",
"webpack": "^5.60.0"
"typescript": "^4.6.4",
"webpack": "^5.72.0"
},

@@ -90,0 +90,0 @@ "keywords": [

@@ -8,3 +8,2 @@ <div align="center">

[![node][node]][node-url]
[![deps][deps]][deps-url]
[![tests][tests]][tests-url]

@@ -17,2 +16,4 @@ [![coverage][cover]][cover-url]

> This is eslint-webpack-plugin 3.0 which works only with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/eslint-webpack-plugin/tree/2.x).
This plugin uses [`eslint`](https://eslint.org/) to find and fix problems in your JavaScript code

@@ -24,12 +25,38 @@

```bash
```console
npm install eslint-webpack-plugin --save-dev
```
**Note**: You also need to install `eslint >= 7` from npm, if you haven't already:
or
```bash
```console
yarn add -D eslint-webpack-plugin
```
or
```console
pnpm add -D eslint-webpack-plugin
```
> **Note**
>
> You also need to install `eslint >= 7` from npm, if you haven't already:
```console
npm install eslint --save-dev
```
or
```console
yarn add -D eslint
```
or
```console
pnpm add -D eslint
```
Then add the plugin to your webpack config. For example:

@@ -49,13 +76,22 @@

You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options).
You can pass [eslint options](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions).
Note that the config option you provide will be passed to the `ESLint` class.
This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-new-eslint-options) for more details.
> **Note**
>
> The config option you provide will be passed to the `ESLint` class.
> This is a different set of options than what you'd specify in `package.json` or `.eslintrc`.
> See the [eslint docs](https://eslint.org/docs/developer-guide/nodejs-api#-new-eslintoptions) for more details.
**Warning**: In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
> **Warning**:
>
> In eslint-webpack-plugin version 1 the options were passed to the now deprecated [CLIEngine](https://eslint.org/docs/developer-guide/nodejs-api#cliengine).
### `context`
- Type: `String`
- Type:
```ts
type context = string;
```
- Default: `compiler.context`

@@ -67,10 +103,20 @@

- Type: `String`
- Type:
```ts
type eslintPath = string;
```
- Default: `eslint`
Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you dont have to install `eslint`.
Path to `eslint` instance that will be used for linting. If the `eslintPath` is a folder like a official eslint, or specify a `formatter` option. now you don't have to install `eslint`.
### `extensions`
- Type: `String|Array[String]`
- Type:
```ts
type extensions = string | Array<string>;
```
- Default: `'js'`

@@ -82,3 +128,8 @@

- Type: `String|Array[String]`
- Type:
```ts
type exclude = string | Array<string>;
```
- Default: `'node_modules'`

@@ -88,9 +139,26 @@

### `resourceQueryExclude`
- Type:
```ts
type resourceQueryExclude = RegExp | Array<RegExp>;
```
- Default: `[]`
Specify the resource query to exclude.
### `files`
- Type: `String|Array[String]`
- Type:
```ts
type files = string | Array<string>;
```
- Default: `null`
Specify directories, files, or globs. Must be relative to `options.context`.
Directories are traveresed recursively looking for files matching `options.extensions`.
Directories are traversed recursively looking for files matching `options.extensions`.
File and glob patterns ignore `options.extensions`.

@@ -100,6 +168,11 @@

- Type: `Boolean`
- Type:
```ts
type fix = boolean;
```
- Default: `false`
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#%E2%97%86-eslint-outputfixes-results).
Will enable [ESLint autofix feature](https://eslint.org/docs/developer-guide/nodejs-api#-eslintoutputfixesresults).

@@ -110,3 +183,11 @@ **Be careful: this option will change source files.**

- Type: `String|Function`
- Type:
```ts
type formatter = string| (
results: Array<import('eslint').ESLint.LintResult>,
data?: import('eslint').ESLint.LintResultData | undefined
) => string
```
- Default: `'stylish'`

@@ -118,3 +199,8 @@

- Type: `Boolean`
- Type:
```ts
type lintDirtyModulesOnly = boolean;
```
- Default: `false`

@@ -126,3 +212,8 @@

- Type: `Boolean | Number`
- Type:
```ts
type threads = boolean | number;
```
- Default: `false`

@@ -139,3 +230,8 @@

- Type: `Boolean`
- Type:
```ts
type emitError = boolean;
```
- Default: `true`

@@ -147,3 +243,8 @@

- Type: `Boolean`
- Type:
```ts
type emitWarning = boolean;
```
- Default: `true`

@@ -155,3 +256,8 @@

- Type: `Boolean`
- Type:
```ts
type failOnError = boolean;
```
- Default: `true`

@@ -163,3 +269,8 @@

- Type: `Boolean`
- Type:
```ts
type failOnWarning = boolean;
```
- Default: `false`

@@ -171,3 +282,8 @@

- Type: `Boolean`
- Type:
```ts
type quiet = boolean;
```
- Default: `false`

@@ -179,3 +295,21 @@

- Type: `Boolean|Object`
- Type:
```ts
type outputReport =
| boolean
| {
filePath?: string | undefined;
formatter?:
| (
| string
| ((
results: Array<import('eslint').ESLint.LintResult>,
data?: import('eslint').ESLint.LintResultData | undefined
) => string)
)
| undefined;
};
```
- Default: `false`

@@ -201,4 +335,2 @@

[node-url]: https://nodejs.org
[deps]: https://david-dm.org/webpack-contrib/eslint-webpack-plugin.svg
[deps-url]: https://david-dm.org/webpack-contrib/eslint-webpack-plugin
[tests]: https://github.com/webpack-contrib/eslint-webpack-plugin/workflows/eslint-webpack-plugin/badge.svg

@@ -205,0 +337,0 @@ [tests-url]: https://github.com/webpack-contrib/eslint-webpack-plugin/actions

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc