eslint-webpack-plugin
Advanced tools
Comparing version 4.0.1 to 4.1.0
@@ -9,3 +9,9 @@ "use strict"; | ||
} = require('jest-worker'); | ||
// @ts-ignore | ||
const { | ||
setup, | ||
lintFiles | ||
} = require('./worker'); | ||
const { | ||
getESLintOptions | ||
@@ -25,3 +31,3 @@ } = require('./options'); | ||
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */ | ||
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** @typedef {{threads: number, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */ | ||
@@ -37,20 +43,11 @@ | ||
} = options; | ||
const { | ||
ESLint | ||
} = require(eslintPath || 'eslint'); | ||
// Filter out loader options before passing the options to ESLint. | ||
const eslint = new ESLint(getESLintOptions(options)); | ||
const eslint = setup({ | ||
eslintPath, | ||
configType: options.configType, | ||
eslintOptions: getESLintOptions(options) | ||
}); | ||
return { | ||
threads: 1, | ||
ESLint, | ||
lintFiles, | ||
eslint, | ||
lintFiles: async files => { | ||
const results = await eslint.lintFiles(files); | ||
// istanbul ignore else | ||
if (options.fix) { | ||
await ESLint.outputFixes(results); | ||
} | ||
return results; | ||
}, | ||
// no-op for non-threaded | ||
@@ -78,2 +75,3 @@ cleanup: async () => {} | ||
eslintPath, | ||
configType: options.configType, | ||
eslintOptions: getESLintOptions(options) | ||
@@ -80,0 +78,0 @@ }] |
@@ -123,3 +123,3 @@ "use strict"; | ||
*/ | ||
const save = (name, content) => /** @type {Promise<void>} */ | ||
const save = (name, content) => ( /** @type {Promise<void>} */ | ||
new Promise((finish, bail) => { | ||
@@ -141,3 +141,3 @@ const { | ||
}); | ||
}); | ||
})); | ||
if (!outputReport || !outputReport.filePath) { | ||
@@ -144,0 +144,0 @@ return; |
@@ -43,2 +43,3 @@ "use strict"; | ||
* @property {RegExp|RegExp[]=} resourceQueryExclude | ||
* @property {string=} configType | ||
*/ | ||
@@ -98,2 +99,7 @@ | ||
} | ||
// Some options aren't available in flat mode | ||
if (loaderOptions.configType === 'flat') { | ||
delete eslintOptions.extensions; | ||
} | ||
return eslintOptions; | ||
@@ -100,0 +106,0 @@ } |
@@ -5,2 +5,6 @@ { | ||
"properties": { | ||
"configType": { | ||
"description": "Enable flat config by setting this value to `flat`.", | ||
"type": "string" | ||
}, | ||
"context": { | ||
@@ -7,0 +11,0 @@ "description": "A string indicating the root of your files.", |
@@ -5,2 +5,3 @@ "use strict"; | ||
/** @typedef {import('eslint').ESLint.Options} ESLintOptions */ | ||
/** @typedef {import('eslint').ESLint.LintResult} LintResult */ | ||
@@ -12,3 +13,3 @@ Object.assign(module.exports, { | ||
/** @type {{ new (arg0: import("eslint").ESLint.Options): import("eslint").ESLint; outputFixes: (arg0: import("eslint").ESLint.LintResult[]) => any; }} */ | ||
/** @type {{ new (arg0: ESLintOptions): ESLint; outputFixes: (arg0: LintResult[]) => any; }} */ | ||
let ESLint; | ||
@@ -25,3 +26,4 @@ | ||
* @property {string=} eslintPath - import path of eslint | ||
* @property {ESLintOptions=} eslintOptions - linter options | ||
* @property {string=} configType | ||
* @property {ESLintOptions} eslintOptions - linter options | ||
* | ||
@@ -32,9 +34,27 @@ * @param {setupOptions} arg0 - setup worker | ||
eslintPath, | ||
eslintOptions = {} | ||
configType, | ||
eslintOptions | ||
}) { | ||
fix = !!(eslintOptions && eslintOptions.fix); | ||
({ | ||
ESLint | ||
} = require(eslintPath || 'eslint')); | ||
eslint = new ESLint(eslintOptions); | ||
const eslintModule = require(eslintPath || 'eslint'); | ||
let FlatESLint; | ||
if (eslintModule.LegacyESLint) { | ||
ESLint = eslintModule.LegacyESLint; | ||
({ | ||
FlatESLint | ||
} = eslintModule); | ||
} else { | ||
({ | ||
ESLint | ||
} = eslintModule); | ||
if (configType === 'flat') { | ||
throw new Error("Couldn't find FlatESLint, you might need to set eslintPath to 'eslint/use-at-your-own-risk'"); | ||
} | ||
} | ||
if (configType === 'flat') { | ||
eslint = new FlatESLint(eslintOptions); | ||
} else { | ||
eslint = new ESLint(eslintOptions); | ||
} | ||
return eslint; | ||
} | ||
@@ -46,2 +66,3 @@ | ||
async function lintFiles(files) { | ||
/** @type {LintResult[]} */ | ||
const result = await eslint.lintFiles(files); | ||
@@ -48,0 +69,0 @@ // if enabled, use eslint autofixing where possible |
{ | ||
"name": "eslint-webpack-plugin", | ||
"version": "4.0.1", | ||
"version": "4.1.0", | ||
"description": "A ESLint plugin for webpack", | ||
@@ -33,3 +33,6 @@ "license": "MIT", | ||
"lint": "npm-run-all -l -p \"lint:**\"", | ||
"test:only": "cross-env NODE_ENV=test jest --testTimeout=60000", | ||
"fix:js": "npm run lint:js -- --fix", | ||
"fix:prettier": "npm run lint:prettier -- --write", | ||
"fix": "npm-run-all -l fix:js fix:prettier", | ||
"test:only": "cross-env NODE_OPTIONS=--experimental-vm-modules NODE_ENV=test jest --testTimeout=60000", | ||
"test:watch": "npm run test:only -- --watch", | ||
@@ -51,39 +54,39 @@ "test:coverage": "npm run test:only -- --collectCoverageFrom=\"src/**/*.js\" --coverage", | ||
"dependencies": { | ||
"@types/eslint": "^8.37.0", | ||
"jest-worker": "^29.5.0", | ||
"@types/eslint": "^8.56.5", | ||
"jest-worker": "^29.7.0", | ||
"micromatch": "^4.0.5", | ||
"normalize-path": "^3.0.0", | ||
"schema-utils": "^4.0.0" | ||
"schema-utils": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
"@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.15.11", | ||
"@types/normalize-path": "^3.0.0", | ||
"@types/webpack": "^5.28.1", | ||
"@babel/cli": "^7.23.9", | ||
"@babel/core": "^7.24.0", | ||
"@babel/preset-env": "^7.24.0", | ||
"@commitlint/cli": "^18.4.3", | ||
"@commitlint/config-conventional": "^18.4.3", | ||
"@types/fs-extra": "^11.0.4", | ||
"@types/micromatch": "^4.0.6", | ||
"@types/node": "^20.11.24", | ||
"@types/normalize-path": "^3.0.2", | ||
"@types/webpack": "^5.28.5", | ||
"@webpack-contrib/eslint-config-webpack": "^3.0.0", | ||
"babel-eslint": "^10.1.0", | ||
"babel-jest": "^29.5.0", | ||
"chokidar": "^3.5.3", | ||
"babel-jest": "^29.7.0", | ||
"chokidar": "^3.6.0", | ||
"cross-env": "^7.0.3", | ||
"cspell": "^6.31.1", | ||
"del": "^6.1.1", | ||
"del-cli": "^4.0.1", | ||
"eslint": "^8.38.0", | ||
"eslint-config-prettier": "^8.8.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"fs-extra": "^10.1.0", | ||
"cspell": "^8.5.0", | ||
"del": "^7.1.0", | ||
"del-cli": "^5.1.0", | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"fs-extra": "^11.2.0", | ||
"husky": "^8.0.3", | ||
"jest": "^29.5.0", | ||
"lint-staged": "^13.2.1", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^15.2.2", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.8.7", | ||
"prettier": "^3.2.5", | ||
"standard-version": "^9.5.0", | ||
"typescript": "^5.0.4", | ||
"webpack": "^5.78.0" | ||
"typescript": "^5.3.3", | ||
"webpack": "^5.90.3" | ||
}, | ||
@@ -90,0 +93,0 @@ "keywords": [ |
@@ -10,3 +10,3 @@ <div align="center"> | ||
[![coverage][cover]][cover-url] | ||
[![chat][chat]][chat-url] | ||
[![discussion][discussion]][discussion-url] | ||
[![size][size]][size-url] | ||
@@ -16,3 +16,3 @@ | ||
> 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 version of eslint-webpack-plugin only works with webpack 5. For the webpack 4, see the [2.x branch](https://github.com/webpack-contrib/eslint-webpack-plugin/tree/2.x). | ||
@@ -111,2 +111,21 @@ This plugin uses [`eslint`](https://eslint.org/) to find and fix problems in your JavaScript code | ||
### `configType` | ||
- Type: | ||
```ts | ||
type configType = "flat" | "eslintrc"; | ||
``` | ||
- Default: `eslintrc` | ||
Specify the type of configuration to use with ESLint. | ||
- `eslintrc` is the classic configuration format available in most ESLint versions. | ||
- `flat` is the new format introduced in ESLint 8.21.0. | ||
The new configuration format is explained in its [own documentation](https://eslint.org/docs/latest/use/configure/configuration-files-new). | ||
> This configuration format being considered as experimental, it is not exported in the main ESLint module in ESLint 8. | ||
> You need to set your `eslintPath` to `eslint/use-at-your-own-risk` for this config format to work. | ||
### `context` | ||
@@ -318,3 +337,3 @@ | ||
results: Array<import('eslint').ESLint.LintResult>, | ||
data?: import('eslint').ESLint.LintResultData | undefined | ||
data?: import('eslint').ESLint.LintResultData | undefined, | ||
) => string) | ||
@@ -350,5 +369,5 @@ ) | ||
[cover-url]: https://codecov.io/gh/webpack-contrib/eslint-webpack-plugin | ||
[chat]: https://badges.gitter.im/webpack/webpack.svg | ||
[chat-url]: https://gitter.im/webpack/webpack | ||
[discussion]: https://img.shields.io/github/discussions/webpack/webpack | ||
[discussion-url]: https://github.com/webpack/webpack/discussions | ||
[size]: https://packagephobia.now.sh/badge?p=eslint-webpack-plugin | ||
[size-url]: https://packagephobia.now.sh/result?p=eslint-webpack-plugin |
@@ -8,3 +8,2 @@ export type ESLint = import('eslint').ESLint; | ||
threads: number; | ||
ESLint: ESLint; | ||
eslint: ESLint; | ||
@@ -22,3 +21,3 @@ lintFiles: LintTask; | ||
/** @typedef {(files: string|string[]) => Promise<LintResult[]>} LintTask */ | ||
/** @typedef {{threads: number, ESLint: ESLint, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** @typedef {{threads: number, eslint: ESLint, lintFiles: LintTask, cleanup: AsyncTask}} Linter */ | ||
/** @typedef {JestWorker & {lintFiles: LintTask}} Worker */ | ||
@@ -39,3 +38,3 @@ /** | ||
poolSize: number, | ||
options: Options | ||
options: Options, | ||
): Linter; | ||
@@ -49,4 +48,4 @@ /** | ||
key: string | undefined, | ||
{ threads, ...options }: Options | ||
{ threads, ...options }: Options, | ||
): Linter; | ||
import { Worker as JestWorker } from 'jest-worker'; |
@@ -21,3 +21,3 @@ export = ESLintWebpackPlugin; | ||
wanted: string[], | ||
exclude: string[] | ||
exclude: string[], | ||
): Promise<void>; | ||
@@ -40,4 +40,4 @@ /** | ||
type Compiler = import('webpack').Compiler; | ||
type Options = import('./options').Options; | ||
type Module = import('webpack').Module; | ||
type NormalModule = import('webpack').NormalModule; | ||
type Options = import('./options').Options; |
@@ -11,3 +11,3 @@ export = linter; | ||
options: Options, | ||
compilation: Compilation | ||
compilation: Compilation, | ||
): { | ||
@@ -14,0 +14,0 @@ lint: Linter; |
@@ -6,3 +6,3 @@ export type ESLintOptions = import('eslint').ESLint.Options; | ||
results: LintResult[], | ||
data?: LintResultData | undefined | ||
data?: LintResultData | undefined, | ||
) => string; | ||
@@ -30,2 +30,3 @@ export type OutputReport = { | ||
resourceQueryExclude?: (RegExp | RegExp[]) | undefined; | ||
configType?: string | undefined; | ||
}; | ||
@@ -65,2 +66,3 @@ export type Options = PluginOptions & ESLintOptions; | ||
* @property {RegExp|RegExp[]=} resourceQueryExclude | ||
* @property {string=} configType | ||
*/ | ||
@@ -67,0 +69,0 @@ /** @typedef {PluginOptions & ESLintOptions} Options */ |
@@ -17,12 +17,12 @@ /** | ||
export function arrify<T>( | ||
value: T | ||
value: T, | ||
): T extends null | undefined | ||
? [] | ||
: T extends string | ||
? [string] | ||
: T extends readonly unknown[] | ||
? T | ||
: T extends Iterable<infer T_1> | ||
? T_1[] | ||
: [T]; | ||
? [string] | ||
: T extends readonly unknown[] | ||
? T | ||
: T extends Iterable<infer T_1> | ||
? T_1[] | ||
: [T]; | ||
/** | ||
@@ -41,3 +41,3 @@ * @param {string|string[]} files | ||
patterns: string | string[], | ||
extensions?: string | string[] | ||
extensions?: string | string[], | ||
): string[]; | ||
@@ -44,0 +44,0 @@ /** |
@@ -6,8 +6,10 @@ export type setupOptions = { | ||
eslintPath?: string | undefined; | ||
configType?: string | undefined; | ||
/** | ||
* - linter options | ||
*/ | ||
eslintOptions?: ESLintOptions | undefined; | ||
eslintOptions: ESLintOptions; | ||
}; | ||
export type ESLint = import('eslint').ESLint; | ||
export type ESLintOptions = import('eslint').ESLint.Options; | ||
export type LintResult = import('eslint').ESLint.LintResult; |
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
47607
1207
369
3
Updated@types/eslint@^8.56.5
Updatedjest-worker@^29.7.0
Updatedschema-utils@^4.2.0