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 4.0.0 to 4.0.1

2

dist/ESLintError.js

@@ -12,5 +12,3 @@ "use strict";

}
}
module.exports = ESLintError;

56

dist/getESLint.js

@@ -6,30 +6,21 @@ "use strict";

} = require('os');
const {
Worker: JestWorker
} = require('jest-worker');
const {
getESLintOptions
} = require('./options');
const {
jsonStringifyReplacerSortKeys
} = require('./utils');
/** @type {{[key: string]: any}} */
const cache = {};
const cache = {};
/** @typedef {import('eslint').ESLint} ESLint */
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
/** @typedef {import('./options').Options} Options */
/** @typedef {() => Promise<void>} AsyncTask */
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */

@@ -41,3 +32,2 @@

*/
function loadESLint(options) {

@@ -47,8 +37,7 @@ const {

} = options;
const {
ESLint
} = require(eslintPath || 'eslint'); // Filter out loader options before passing the options to ESLint.
} = require(eslintPath || 'eslint');
// Filter out loader options before passing the options to ESLint.
const eslint = new ESLint(getESLintOptions(options));

@@ -60,8 +49,7 @@ return {

lintFiles: async files => {
const results = await eslint.lintFiles(files); // istanbul ignore else
const results = await eslint.lintFiles(files);
// istanbul ignore else
if (options.fix) {
await ESLint.outputFixes(results);
}
return results;

@@ -73,2 +61,3 @@ },

}
/**

@@ -80,4 +69,2 @@ * @param {string|undefined} key

*/
function loadESLintThreaded(key, poolSize, options) {

@@ -88,5 +75,3 @@ const cacheKey = getCacheKey(key, options);

} = options;
const source = require.resolve('./worker');
const workerOptions = {

@@ -101,17 +86,12 @@ enableWorkerThreads: true,

const local = loadESLint(options);
let worker =
/** @type {Worker?} */
new JestWorker(source, workerOptions);
let worker = /** @type {Worker?} */new JestWorker(source, workerOptions);
/** @type {Linter} */
const context = { ...local,
const context = {
...local,
threads: poolSize,
lintFiles: async files => worker && (await worker.lintFiles(files)) ||
/* istanbul ignore next */
[],
lintFiles: async files => worker && (await worker.lintFiles(files)) || /* istanbul ignore next */[],
cleanup: async () => {
cache[cacheKey] = local;
context.lintFiles = files => local.lintFiles(files);
if (worker) {

@@ -125,2 +105,3 @@ worker.end();

}
/**

@@ -131,4 +112,2 @@ * @param {string|undefined} key

*/
function getESLint(key, {

@@ -138,4 +117,3 @@ threads,

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

@@ -146,9 +124,8 @@ const cacheKey = getCacheKey(key, {

});
if (!cache[cacheKey]) {
cache[cacheKey] = max > 1 ? loadESLintThreaded(key, max, options) : loadESLint(options);
}
return cache[cacheKey];
}
/**

@@ -159,4 +136,2 @@ * @param {string|undefined} key

*/
function getCacheKey(key, options) {

@@ -168,3 +143,2 @@ return JSON.stringify({

}
module.exports = {

@@ -171,0 +145,0 @@ loadESLint,

@@ -7,13 +7,9 @@ "use strict";

} = require('path');
const {
isMatch
} = require('micromatch');
const {
getOptions
} = require('./options');
const linter = require('./linter');
const {

@@ -24,15 +20,11 @@ arrify,

} = require('./utils');
/** @typedef {import('webpack').Compiler} Compiler */
/** @typedef {import('webpack').Module} Module */
/** @typedef {import('webpack').NormalModule} NormalModule */
/** @typedef {import('./options').Options} Options */
const ESLINT_PLUGIN = 'ESLintWebpackPlugin';
const DEFAULT_FOLDER_TO_EXCLUDE = '**/node_modules/**';
let compilerId = 0;
class ESLintWebpackPlugin {

@@ -47,2 +39,3 @@ /**

}
/**

@@ -52,4 +45,2 @@ * @param {Compiler} compiler

*/
apply(compiler) {

@@ -62,3 +53,4 @@ // Generate key for each compilation,

const excludedResourceQueries = resourceQueries.map(item => item instanceof RegExp ? item : new RegExp(item));
const options = { ...this.options,
const options = {
...this.options,
exclude: excludedFiles,

@@ -71,9 +63,9 @@ resourceQueryExclude: excludedResourceQueries,

const exclude = parseFoldersToGlobs(foldersToExclude);
const wanted = parseFoldersToGlobs(options.files, options.extensions); // If `lintDirtyModulesOnly` is disabled,
const wanted = parseFoldersToGlobs(options.files, options.extensions);
// If `lintDirtyModulesOnly` is disabled,
// execute the linter on the build
if (!this.options.lintDirtyModulesOnly) {
compiler.hooks.run.tapPromise(this.key, c => this.run(c, options, wanted, exclude));
}
let hasCompilerRunByDirtyModule = this.options.lintDirtyModulesOnly;

@@ -86,2 +78,3 @@ compiler.hooks.watchRun.tapPromise(this.key, c => {

}
/**

@@ -93,4 +86,2 @@ * @param {Compiler} compiler

*/
async run(compiler, options, wanted, exclude) {

@@ -106,8 +97,5 @@ // @ts-ignore

/** @type {import('./linter').Reporter} */
let report;
/** @type number */
let threads;
try {

@@ -123,19 +111,17 @@ ({

}
/** @type {string[]} */
const files = [];
const files = []; // Add the file to be linted
// Add the file to be linted
compilation.hooks.succeedModule.tap(this.key, addFile);
compilation.hooks.stillValidModule.tap(this.key, addFile);
/**
* @param {Module} module
*/
function addFile(module) {
const {
resource
} =
/** @type {NormalModule} */
module;
} = /** @type {NormalModule} */module;
if (!resource) return;

@@ -150,3 +136,2 @@ const [file, query] = resource.split('?');

const isQueryNotExclude = options.resourceQueryExclude.every(reg => !reg.test(query));
if (isFileNotListed && isFileWanted && isQueryNotExclude) {

@@ -156,11 +141,11 @@ files.push(file);

}
} // Lint all files added
}
// Lint all files added
compilation.hooks.finishModules.tap(this.key, () => {
if (files.length > 0 && threads <= 1) lint(files);
}); // await and interpret results
});
// await and interpret results
compilation.hooks.additionalAssets.tapPromise(this.key, processResults);
async function processResults() {

@@ -172,3 +157,2 @@ const {

} = await report();
if (warnings && !options.failOnWarning) {

@@ -181,3 +165,2 @@ // @ts-ignore

}
if (errors && !options.failOnError) {

@@ -190,3 +173,2 @@ // @ts-ignore

}
if (generateReportAsset) await generateReportAsset(compilation);

@@ -196,2 +178,3 @@ }

}
/**

@@ -202,4 +185,2 @@ *

*/
getContext(compiler) {

@@ -212,5 +193,3 @@ const compilerContext = String(compiler.options.context);

}
}
module.exports = ESLintWebpackPlugin;

@@ -8,40 +8,26 @@ "use strict";

} = require('path');
const ESLintError = require('./ESLintError');
const {
getESLint
} = require('./getESLint');
const {
arrify
} = require('./utils');
/** @typedef {import('eslint').ESLint} ESLint */
/** @typedef {import('eslint').ESLint.Formatter} Formatter */
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
/** @typedef {import('webpack').Compiler} Compiler */
/** @typedef {import('webpack').Compilation} Compilation */
/** @typedef {import('./options').Options} Options */
/** @typedef {import('./options').FormatterFunction} FormatterFunction */
/** @typedef {(compilation: Compilation) => Promise<void>} GenerateReport */
/** @typedef {{errors?: ESLintError, warnings?: ESLintError, generateReportAsset?: GenerateReport}} Report */
/** @typedef {() => Promise<Report>} Reporter */
/** @typedef {(files: string|string[]) => void} Linter */
/** @typedef {{[files: string]: LintResult}} LintResultMap */
/** @type {WeakMap<Compiler, LintResultMap>} */
const resultStorage = new WeakMap();
const resultStorage = new WeakMap();
/**

@@ -53,20 +39,18 @@ * @param {string|undefined} key

*/
function linter(key, options, compilation) {
/** @type {ESLint} */
let eslint;
/** @type {(files: string|string[]) => Promise<LintResult[]>} */
let lintFiles;
let lintFiles;
/** @type {() => Promise<void>} */
let cleanup;
let cleanup;
/** @type number */
let threads;
let threads;
/** @type {Promise<LintResult[]>[]} */
const rawResults = [];
const crossRunResultStorage = getResultStorage(compilation);
try {

@@ -82,3 +66,2 @@ ({

}
return {

@@ -89,6 +72,6 @@ lint,

};
/**
* @param {string | string[]} files
*/
function lint(files) {

@@ -98,3 +81,2 @@ for (const file of arrify(files)) {

}
rawResults.push(lintFiles(files).catch(e => {

@@ -106,19 +88,17 @@ // @ts-ignore

}
async function report() {
// Filter out ignored files.
let results = await removeIgnoredWarnings(eslint, // Get the current results, resetting the rawResults to empty
let results = await removeIgnoredWarnings(eslint,
// Get the current results, resetting the rawResults to empty
await flatten(rawResults.splice(0, rawResults.length)));
await cleanup();
for (const result of results) {
crossRunResultStorage[result.filePath] = result;
}
results = Object.values(crossRunResultStorage);
results = Object.values(crossRunResultStorage); // do not analyze if there are no results or eslint config
// do not analyze if there are no results or eslint config
if (!results || results.length < 1) {
return {};
}
const formatter = await loadFormatter(eslint, options.formatter);

@@ -134,2 +114,3 @@ const {

};
/**

@@ -139,3 +120,2 @@ * @param {Compilation} compilation

*/
async function generateReportAsset({

@@ -151,5 +131,3 @@ compiler

*/
const save = (name, content) =>
/** @type {Promise<void>} */
const save = (name, content) => /** @type {Promise<void>} */
new Promise((finish, bail) => {

@@ -159,5 +137,5 @@ const {

writeFile
} = compiler.outputFileSystem; // ensure directory exists
} = compiler.outputFileSystem;
// ensure directory exists
// @ts-ignore - the types for `outputFileSystem` are missing the 3 arg overload
mkdir(dirname(name), {

@@ -173,7 +151,5 @@ recursive: true

});
if (!outputReport || !outputReport.filePath) {
return;
}
const content = await (outputReport.formatter ? (await loadFormatter(eslint, outputReport.formatter)).format(results) : formatter.format(results));

@@ -183,7 +159,5 @@ let {

} = outputReport;
if (!isAbsolute(filePath)) {
filePath = join(compiler.outputPath, filePath);
}
await save(filePath, content);

@@ -193,2 +167,3 @@ }

}
/**

@@ -199,16 +174,11 @@ * @param {Formatter} formatter

*/
async function formatResults(formatter, results) {
let errors;
let warnings;
if (results.warnings.length > 0) {
warnings = new ESLintError(await formatter.format(results.warnings));
}
if (results.errors.length > 0) {
errors = new ESLintError(await formatter.format(results.errors));
}
return {

@@ -219,2 +189,3 @@ errors,

}
/**

@@ -225,9 +196,7 @@ * @param {Options} options

*/
function parseResults(options, results) {
/** @type {LintResult[]} */
const errors = [];
/** @type {LintResult[]} */
const warnings = [];

@@ -237,5 +206,5 @@ results.forEach(file => {

const messages = file.messages.filter(message => options.emitError && message.severity === 2);
if (messages.length > 0) {
errors.push({ ...file,
errors.push({
...file,
messages

@@ -245,8 +214,7 @@ });

}
if (fileHasWarnings(file)) {
const messages = file.messages.filter(message => options.emitWarning && message.severity === 1);
if (messages.length > 0) {
warnings.push({ ...file,
warnings.push({
...file,
messages

@@ -262,2 +230,3 @@ });

}
/**

@@ -267,7 +236,6 @@ * @param {LintResult} file

*/
function fileHasErrors(file) {
return file.errorCount > 0;
}
/**

@@ -277,7 +245,6 @@ * @param {LintResult} file

*/
function fileHasWarnings(file) {
return file.warningCount > 0;
}
/**

@@ -288,4 +255,2 @@ * @param {ESLint} eslint

*/
async function loadFormatter(eslint, formatter) {

@@ -297,12 +262,12 @@ if (typeof formatter === 'function') {

}
if (typeof formatter === 'string') {
try {
return eslint.loadFormatter(formatter);
} catch (_) {// Load the default formatter.
} catch (_) {
// Load the default formatter.
}
}
return eslint.loadFormatter();
}
/**

@@ -313,4 +278,2 @@ * @param {ESLint} eslint

*/
async function removeIgnoredWarnings(eslint, results) {

@@ -332,6 +295,8 @@ const filterPromises = results.map(async result => {

return ignored ? false : result;
}); // @ts-ignore
});
// @ts-ignore
return (await Promise.all(filterPromises)).filter(Boolean);
}
/**

@@ -341,4 +306,2 @@ * @param {Promise<LintResult[]>[]} results

*/
async function flatten(results) {

@@ -350,5 +313,5 @@ /**

const flat = (acc, list) => [...acc, ...list];
return (await Promise.all(results)).reduce(flat, []);
}
/**

@@ -358,4 +321,2 @@ * @param {Compilation} compilation

*/
function getResultStorage({

@@ -365,10 +326,7 @@ compiler

let storage = resultStorage.get(compiler);
if (!storage) {
resultStorage.set(compiler, storage = {});
}
return storage;
}
module.exports = linter;

@@ -6,8 +6,6 @@ "use strict";

} = require('schema-utils');
const schema = require('./options.json');
const schema = require('./options.json');
/** @typedef {import("eslint").ESLint.Options} ESLintOptions */
/** @typedef {import('eslint').ESLint.LintResult} LintResult */
/** @typedef {import('eslint').ESLint.LintResultData} LintResultData */

@@ -54,6 +52,6 @@

*/
function getOptions(pluginOptions) {
const options = {
cache: true,
cacheLocation: 'node_modules/.cache/eslint-webpack-plugin/.eslintcache',
extensions: 'js',

@@ -69,4 +67,5 @@ emitError: true,

} : {})
}; // @ts-ignore
};
// @ts-ignore
validate(schema, options, {

@@ -78,2 +77,3 @@ name: 'ESLint Webpack Plugin',

}
/**

@@ -83,8 +83,8 @@ * @param {Options} loaderOptions

*/
function getESLintOptions(loaderOptions) {
const eslintOptions = { ...loaderOptions
}; // Keep the fix option because it is common to both the loader and ESLint.
const eslintOptions = {
...loaderOptions
};
// Keep the fix option because it is common to both the loader and ESLint.
const {

@@ -94,5 +94,6 @@ fix,

...eslintOnlyOptions
} = schema.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
for (const option in eslintOnlyOptions) {

@@ -102,6 +103,4 @@ // @ts-ignore

}
return eslintOptions;
}
module.exports = {

@@ -108,0 +107,0 @@ getOptions,

@@ -6,8 +6,7 @@ "use strict";

} = require('path');
const {
statSync
} = require('fs');
const normalizePath = require('normalize-path');
const normalizePath = require('normalize-path');
/**

@@ -28,6 +27,3 @@ * @template T

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

@@ -39,3 +35,2 @@ // eslint-disable-next-line no-undefined

}
if (Array.isArray(value)) {

@@ -45,17 +40,17 @@ // @ts-ignore

}
if (typeof value === 'string') {
// @ts-ignore
return [value];
} // @ts-ignore
}
// @ts-ignore
if (typeof value[Symbol.iterator] === 'function') {
// @ts-ignore
return [...value];
} // @ts-ignore
}
// @ts-ignore
return [value];
}
/**

@@ -66,9 +61,6 @@ * @param {string|string[]} files

*/
function parseFiles(files, context) {
return arrify(files).map((
/** @type {string} */
file) => normalizePath(resolve(context, file)));
return arrify(files).map(( /** @type {string} */file) => normalizePath(resolve(context, file)));
}
/**

@@ -79,13 +71,7 @@ * @param {string|string[]} patterns

*/
function parseFoldersToGlobs(patterns, extensions = []) {
const extensionsList = arrify(extensions);
const [prefix, postfix] = extensionsList.length > 1 ? ['{', '}'] : ['', ''];
const extensionsGlob = extensionsList.map((
/** @type {string} */
extension) => extension.replace(/^\./u, '')).join(',');
return arrify(patterns).map((
/** @type {string} */
pattern) => {
const extensionsGlob = extensionsList.map(( /** @type {string} */extension) => extension.replace(/^\./u, '')).join(',');
return arrify(patterns).map(( /** @type {string} */pattern) => {
try {

@@ -95,12 +81,12 @@ // The patterns are absolute because they are prepended with the context.

/* istanbul ignore else */
if (stats.isDirectory()) {
return pattern.replace(/[/\\]*?$/u, `/**${extensionsGlob ? `/*.${prefix + extensionsGlob + postfix}` : ''}`);
}
} catch (_) {// Return the pattern as is on error.
} catch (_) {
// Return the pattern as is on error.
}
return pattern;
});
}
/**

@@ -110,4 +96,2 @@ * @param {string} _ key, but unused

*/
const jsonStringifyReplacerSortKeys = (_, value) => {

@@ -123,6 +107,4 @@ /**

};
return value instanceof Object && !(value instanceof Array) ? Object.keys(value).sort().reduce(insert, {}) : value;
};
module.exports = {

@@ -129,0 +111,0 @@ arrify,

"use strict";
/** @typedef {import('eslint').ESLint} ESLint */
/** @typedef {import('eslint').ESLint.Options} ESLintOptions */
/** @typedef {import('eslint').ESLint.Options} ESLintOptions */
Object.assign(module.exports, {

@@ -10,11 +10,12 @@ lintFiles,

});
/** @type {{ new (arg0: import("eslint").ESLint.Options): import("eslint").ESLint; outputFixes: (arg0: import("eslint").ESLint.LintResult[]) => any; }} */
let ESLint;
let ESLint;
/** @type {ESLint} */
let eslint;
let eslint;
/** @type {boolean} */
let fix;
let fix;
/**

@@ -27,3 +28,2 @@ * @typedef {object} setupOptions

*/
function setup({

@@ -39,15 +39,13 @@ eslintPath,

}
/**
* @param {string | string[]} files
*/
async function lintFiles(files) {
const result = await eslint.lintFiles(files); // if enabled, use eslint autofixing where possible
const result = await eslint.lintFiles(files);
// if enabled, use eslint autofixing where possible
if (fix) {
await ESLint.outputFixes(result);
}
return result;
}
{
"name": "eslint-webpack-plugin",
"version": "4.0.0",
"version": "4.0.1",
"description": "A ESLint plugin for webpack",

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

"dependencies": {
"@types/eslint": "^8.4.10",
"jest-worker": "^29.4.1",
"@types/eslint": "^8.37.0",
"jest-worker": "^29.5.0",
"micromatch": "^4.0.5",

@@ -58,32 +58,32 @@ "normalize-path": "^3.0.0",

"devDependencies": {
"@babel/cli": "^7.20.7",
"@babel/core": "^7.20.12",
"@babel/preset-env": "^7.20.2",
"@commitlint/cli": "^17.4.2",
"@commitlint/config-conventional": "^17.4.2",
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.4",
"@babel/preset-env": "^7.21.4",
"@commitlint/cli": "^17.5.1",
"@commitlint/config-conventional": "^17.4.4",
"@types/fs-extra": "^9.0.13",
"@types/micromatch": "^4.0.2",
"@types/node": "^18.11.18",
"@types/node": "^18.15.11",
"@types/normalize-path": "^3.0.0",
"@types/webpack": "^5.28.0",
"@types/webpack": "^5.28.1",
"@webpack-contrib/eslint-config-webpack": "^3.0.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^29.4.1",
"babel-jest": "^29.5.0",
"chokidar": "^3.5.3",
"cross-env": "^7.0.3",
"cspell": "^6.19.2",
"cspell": "^6.31.1",
"del": "^6.1.1",
"del-cli": "^4.0.1",
"eslint": "^8.33.0",
"eslint-config-prettier": "^8.6.0",
"eslint": "^8.38.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"fs-extra": "^10.1.0",
"husky": "^8.0.3",
"jest": "^29.4.1",
"lint-staged": "^13.1.0",
"jest": "^29.5.0",
"lint-staged": "^13.2.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.3",
"prettier": "^2.8.7",
"standard-version": "^9.5.0",
"typescript": "^4.9.5",
"webpack": "^5.75.0"
"typescript": "^5.0.4",
"webpack": "^5.78.0"
},

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

@@ -85,2 +85,26 @@ <div align="center">

### `cache`
- Type:
```ts
type cache = boolean;
```
- Default: `true`
The cache is enabled by default to decrease execution time.
### `cacheLocation`
- Type:
```ts
type cacheLocation = string;
```
- Default: `node_modules/.cache/eslint-webpack-plugin/.eslintcache`
Specify the path to the cache location. Can be a file or a directory.
### `context`

@@ -87,0 +111,0 @@

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