eslint-webpack-plugin
Advanced tools
Comparing version 3.2.0 to 4.0.0
@@ -25,2 +25,6 @@ "use strict"; | ||
/** @typedef {import('webpack').Module} Module */ | ||
/** @typedef {import('webpack').NormalModule} NormalModule */ | ||
/** @typedef {import('./options').Options} Options */ | ||
@@ -30,3 +34,4 @@ | ||
const ESLINT_PLUGIN = 'ESLintWebpackPlugin'; | ||
let counter = 0; | ||
const DEFAULT_FOLDER_TO_EXCLUDE = '**/node_modules/**'; | ||
let compilerId = 0; | ||
@@ -51,11 +56,15 @@ class ESLintWebpackPlugin { | ||
// this differentiates one from the other when being cached. | ||
this.key = compiler.name || `${this.key}_${counter += 1}`; | ||
this.key = compiler.name || `${this.key}_${compilerId += 1}`; | ||
const excludedFiles = parseFiles(this.options.exclude || [], this.getContext(compiler)); | ||
const resourceQueries = arrify(this.options.resourceQueryExclude || []); | ||
const excludedResourceQueries = resourceQueries.map(item => item instanceof RegExp ? item : new RegExp(item)); | ||
const options = { ...this.options, | ||
exclude: parseFiles(this.options.exclude || [], this.getContext(compiler)), | ||
exclude: excludedFiles, | ||
resourceQueryExclude: excludedResourceQueries, | ||
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 = parseFoldersToGlobs(options.files, options.extensions); | ||
const exclude = parseFoldersToGlobs(this.options.exclude ? options.exclude : '**/node_modules/**', []); // If `lintDirtyModulesOnly` is disabled, | ||
const foldersToExclude = this.options.exclude ? options.exclude : DEFAULT_FOLDER_TO_EXCLUDE; | ||
const exclude = parseFoldersToGlobs(foldersToExclude); | ||
const wanted = parseFoldersToGlobs(options.files, options.extensions); // If `lintDirtyModulesOnly` is disabled, | ||
// execute the linter on the build | ||
@@ -67,10 +76,7 @@ | ||
let isFirstRun = this.options.lintDirtyModulesOnly; | ||
let hasCompilerRunByDirtyModule = this.options.lintDirtyModulesOnly; | ||
compiler.hooks.watchRun.tapPromise(this.key, c => { | ||
if (isFirstRun) { | ||
isFirstRun = false; | ||
return Promise.resolve(); | ||
} | ||
return this.run(c, options, wanted, exclude); | ||
if (!hasCompilerRunByDirtyModule) return this.run(c, options, wanted, exclude); | ||
hasCompilerRunByDirtyModule = false; | ||
return Promise.resolve(); | ||
}); | ||
@@ -87,10 +93,7 @@ } | ||
async run(compiler, options, wanted, exclude) { | ||
// Do not re-hook | ||
if ( // @ts-ignore | ||
compiler.hooks.compilation.taps.find(({ | ||
// @ts-ignore | ||
const isCompilerHooked = compiler.hooks.compilation.taps.find(({ | ||
name | ||
}) => name === this.key)) { | ||
return; | ||
} | ||
}) => name === this.key); | ||
if (isCompilerHooked) return; | ||
compiler.hooks.compilation.tap(this.key, compilation => { | ||
@@ -119,29 +122,35 @@ /** @type {import('./linter').Linter} */ | ||
const files = []; // @ts-ignore | ||
// Add the file to be linted | ||
const files = []; // Add the file to be linted | ||
compilation.hooks.succeedModule.tap(this.key, ({ | ||
resource | ||
}) => { | ||
if (resource) { | ||
const [file, query] = resource.split('?'); | ||
compilation.hooks.succeedModule.tap(this.key, addFile); | ||
compilation.hooks.stillValidModule.tap(this.key, addFile); | ||
/** | ||
* @param {Module} module | ||
*/ | ||
if (file && !files.includes(file) && isMatch(file, wanted, { | ||
dot: true | ||
}) && !isMatch(file, exclude, { | ||
dot: true | ||
}) && options.resourceQueryExclude.every(reg => !reg.test(query))) { | ||
files.push(file); | ||
function addFile(module) { | ||
const { | ||
resource | ||
} = | ||
/** @type {NormalModule} */ | ||
module; | ||
if (!resource) return; | ||
const [file, query] = resource.split('?'); | ||
const isFileNotListed = file && !files.includes(file); | ||
const isFileWanted = isMatch(file, wanted, { | ||
dot: true | ||
}) && !isMatch(file, exclude, { | ||
dot: true | ||
}); | ||
const isQueryNotExclude = options.resourceQueryExclude.every(reg => !reg.test(query)); | ||
if (threads > 1) { | ||
lint(file); | ||
} | ||
} | ||
if (isFileNotListed && isFileWanted && isQueryNotExclude) { | ||
files.push(file); | ||
if (threads > 1) lint(file); | ||
} | ||
}); // Lint all files added | ||
} // Lint all files added | ||
compilation.hooks.finishModules.tap(this.key, () => { | ||
if (files.length > 0 && threads <= 1) { | ||
lint(files); | ||
} | ||
if (files.length > 0 && threads <= 1) lint(files); | ||
}); // await and interpret results | ||
@@ -161,3 +170,3 @@ | ||
compilation.warnings.push(warnings); | ||
} else if (warnings && options.failOnWarning) { | ||
} else if (warnings) { | ||
// @ts-ignore | ||
@@ -167,13 +176,11 @@ compilation.errors.push(warnings); | ||
if (errors && options.failOnError) { | ||
if (errors && !options.failOnError) { | ||
// @ts-ignore | ||
compilation.warnings.push(errors); | ||
} else if (errors) { | ||
// @ts-ignore | ||
compilation.errors.push(errors); | ||
} else if (errors && !options.failOnError) { | ||
// @ts-ignore | ||
compilation.warnings.push(errors); | ||
} | ||
if (generateReportAsset) { | ||
await generateReportAsset(compilation); | ||
} | ||
if (generateReportAsset) await generateReportAsset(compilation); | ||
} | ||
@@ -190,11 +197,7 @@ }); | ||
getContext(compiler) { | ||
if (!this.options.context) { | ||
return String(compiler.options.context); | ||
} | ||
if (!isAbsolute(this.options.context)) { | ||
return join(String(compiler.options.context), this.options.context); | ||
} | ||
return this.options.context; | ||
const compilerContext = String(compiler.options.context); | ||
const optionContext = this.options.context; | ||
if (!optionContext) return compilerContext; | ||
if (isAbsolute(optionContext)) return optionContext; | ||
return join(compilerContext, optionContext); | ||
} | ||
@@ -201,0 +204,0 @@ |
@@ -14,2 +14,6 @@ "use strict"; | ||
} = require('./getESLint'); | ||
const { | ||
arrify | ||
} = require('./utils'); | ||
/** @typedef {import('eslint').ESLint} ESLint */ | ||
@@ -88,3 +92,3 @@ | ||
function lint(files) { | ||
for (const file of asList(files)) { | ||
for (const file of arrify(files)) { | ||
delete crossRunResultStorage[file]; | ||
@@ -296,7 +300,15 @@ } | ||
// line is unset for warnings not involving file contents. | ||
const ignored = result.messages.length === 0 || result.warningCount === 1 && result.errorCount === 0 && !result.messages[0].fatal && !result.messages[0].ruleId && !result.messages[0].line && (await eslint.isPathIgnored(result.filePath)); | ||
const { | ||
messages, | ||
warningCount, | ||
errorCount, | ||
filePath | ||
} = result; | ||
const [firstMessage] = messages; | ||
const hasWarning = warningCount === 1 && errorCount === 0; | ||
const ignored = messages.length === 0 || hasWarning && !firstMessage.fatal && !firstMessage.ruleId && !firstMessage.line && (await eslint.isPathIgnored(filePath)); | ||
return ignored ? false : result; | ||
}); // @ts-ignore | ||
return (await Promise.all(filterPromises)).filter(result => !!result); | ||
return (await Promise.all(filterPromises)).filter(Boolean); | ||
} | ||
@@ -335,12 +347,3 @@ /** | ||
} | ||
/** | ||
* @param {string | string[]} x | ||
*/ | ||
function asList(x) { | ||
/* istanbul ignore next */ | ||
return Array.isArray(x) ? x : [x]; | ||
} | ||
module.exports = linter; |
@@ -18,3 +18,3 @@ { | ||
"eslintPath": { | ||
"description": "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`.", | ||
"description": "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`.", | ||
"type": "string" | ||
@@ -21,0 +21,0 @@ }, |
{ | ||
"name": "eslint-webpack-plugin", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "A ESLint plugin for webpack", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
"engines": { | ||
"node": ">= 12.13.0" | ||
"node": ">= 14.15.0" | ||
}, | ||
@@ -31,2 +31,3 @@ "scripts": { | ||
"lint:js": "eslint --cache .", | ||
"lint:spelling": "cspell \"**/*.*\"", | ||
"lint:types": "tsc --pretty --noEmit", | ||
@@ -47,8 +48,8 @@ "lint": "npm-run-all -l -p \"lint:**\"", | ||
"peerDependencies": { | ||
"eslint": "^7.0.0 || ^8.0.0", | ||
"eslint": "^8.0.0", | ||
"webpack": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"@types/eslint": "^7.29.0 || ^8.4.1", | ||
"jest-worker": "^28.0.2", | ||
"@types/eslint": "^8.4.10", | ||
"jest-worker": "^29.4.1", | ||
"micromatch": "^4.0.5", | ||
@@ -59,9 +60,10 @@ "normalize-path": "^3.0.0", | ||
"devDependencies": { | ||
"@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", | ||
"@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", | ||
"@types/fs-extra": "^9.0.13", | ||
"@types/micromatch": "^4.0.2", | ||
"@types/node": "^18.11.18", | ||
"@types/normalize-path": "^3.0.0", | ||
@@ -71,19 +73,20 @@ "@types/webpack": "^5.28.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^28.0.3", | ||
"babel-jest": "^29.4.1", | ||
"chokidar": "^3.5.3", | ||
"cross-env": "^7.0.3", | ||
"del": "^6.0.0", | ||
"cspell": "^6.19.2", | ||
"del": "^6.1.1", | ||
"del-cli": "^4.0.1", | ||
"eslint": "^8.14.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint": "^8.33.0", | ||
"eslint-config-prettier": "^8.6.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"fs-extra": "^10.1.0", | ||
"husky": "^7.0.4", | ||
"jest": "^28.0.3", | ||
"lint-staged": "^12.4.1", | ||
"husky": "^8.0.3", | ||
"jest": "^29.4.1", | ||
"lint-staged": "^13.1.0", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.6.2", | ||
"standard-version": "^9.3.2", | ||
"typescript": "^4.6.4", | ||
"webpack": "^5.72.0" | ||
"prettier": "^2.8.3", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^4.9.5", | ||
"webpack": "^5.75.0" | ||
}, | ||
@@ -90,0 +93,0 @@ "keywords": [ |
@@ -39,5 +39,5 @@ <div align="center"> | ||
> **Note** | ||
> **Note**: | ||
> | ||
> You also need to install `eslint >= 7` from npm, if you haven't already: | ||
> You also need to install `eslint >= 8` from npm, if you haven't already: | ||
@@ -44,0 +44,0 @@ ```console |
@@ -36,5 +36,7 @@ export = ESLintWebpackPlugin; | ||
declare namespace ESLintWebpackPlugin { | ||
export { Compiler, Options }; | ||
export { Compiler, Module, NormalModule, Options }; | ||
} | ||
type Compiler = import('webpack').Compiler; | ||
type Options = import('./options').Options; | ||
type Module = import('webpack').Module; | ||
type NormalModule = import('webpack').NormalModule; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45536
1165
30
+ Added@jest/schemas@29.6.3(transitive)
+ Added@jest/types@29.6.3(transitive)
+ Added@sinclair/typebox@0.27.8(transitive)
+ Added@types/istanbul-lib-coverage@2.0.6(transitive)
+ Added@types/istanbul-lib-report@3.0.3(transitive)
+ Added@types/istanbul-reports@3.0.4(transitive)
+ Added@types/yargs@17.0.33(transitive)
+ Added@types/yargs-parser@21.0.3(transitive)
+ Addedci-info@3.9.0(transitive)
+ Addedjest-util@29.7.0(transitive)
+ Addedjest-worker@29.7.0(transitive)
- Removedjest-worker@28.1.3(transitive)
Updated@types/eslint@^8.4.10
Updatedjest-worker@^29.4.1