eslint-config-webpack
v4.12.0
Published
Provides Webpack's eslint rules as an extensible shared config
Readme
eslint-config-webpack
Install
npm i -D eslint-config-webpackUsage
Webpack's eslint config contains all of our ESLint rules.
In your eslint.config.js add ...
import { defineConfig } from "eslint/config";
import config from "eslint-config-webpack";
export default defineConfig([
{
extends: [config],
},
]);Webpack-specific configs
Three opt-in configs cover conventions only webpack's own repositories need.
They are not part of recommended — extend them explicitly:
import { defineConfig } from "eslint/config";
import config from "eslint-config-webpack";
import configs from "eslint-config-webpack/configs.js";
export default defineConfig([
{
extends: [
config,
configs["webpack/special"],
configs["webpack/schemas"],
configs["webpack/types"],
],
},
]);| Config | Files | What it checks |
| ----------------- | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| webpack/special | source files | webpack/require-license-comment — every file opens with the MIT license header. |
| webpack/schemas | **/schemas/**/*.json | webpack/valid-schema — the JSON schema conventions webpack's declaration and validator generators rely on. webpack/format-schema — key order, and definitions kept in sync with the base schema (autofixable). |
| webpack/types | **/lib/**/*.{js,mjs,cjs} | webpack/inherit-jsdoc — an overriding method carries the JSDoc of the method it overrides (autofixable). |
webpack/valid-schema accepts options for which keywords a schema may use.
keywords replaces the default set — webpack's own — outright, allow adds to
it and disallow removes from it:
export default defineConfig([
{
extends: [configs["webpack/schemas"]],
rules: {
"webpack/valid-schema": [
"error",
{ allow: ["x-generator"], disallow: ["cli"] },
],
},
},
]);Every other check is unconditional. The rule reports a schema that uses a
keyword outside that set, puts anything next to a $ref, gives type more than one
value, uses instanceof without tsType, absolutePath off a string or
properties off a non-object, describes properties without
additionalProperties, nests or mis-sizes oneOf/anyOf/allOf, or leaves a
property without a description starting in uppercase and ending in a single dot.
webpack/inherit-jsdoc needs type information, so webpack/types sets up
@typescript-eslint/parser with projectService — the project therefore needs
a tsconfig.json covering the linted files, and typescript installed. The
rule copies the base class method's JSDoc onto every override that is missing
it or has drifted from it, dropping @abstract. stripTags chooses which tags
are dropped:
export default defineConfig([
{
extends: [configs["webpack/types"]],
rules: {
"webpack/inherit-jsdoc": ["error", { stripTags: ["abstract", "virtual"] }],
},
},
]);Getters, setters, static methods and methods overriding a declaration file (so
Object.toString or Set.add) are left alone. Inheritance is resolved through
the whole chain, so restoring a JSDoc that several classes deep an override
inherits takes more than one --fix run — repeat it until the tree stops
changing.
