@lwc/eslint-plugin-lwc
Official ESLint rules for Lightning Web Components (LWC).
Installation
$ npm install eslint @babel/core @babel/eslint-parser @lwc/eslint-plugin-lwc --save-dev
Usage
Add @lwc/eslint-plugin-lwc
to the plugins
section of your configuration. Then configure the desired rules in the rules
sections. Some of the syntax used in Lightning Web Components is not yet stage 4 (eg. class fields or decorators), and the out-of-the-box parser from ESLint doesn't support this syntax yet. In order to parse the LWC files properly, set the parser
field to @babel/eslint-parser
.
Example of .eslintrc
:
{
"parser": "@babel/eslint-parser",
"parserOptions": {
"requireConfigFile": false,
"babelOptions": {
"parserOpts": {
"plugins": ["classProperties", ["decorators", { "decoratorsBeforeExport": false }]]
}
}
},
"plugins": ["@lwc/eslint-plugin-lwc"],
"rules": {
"@lwc/lwc/no-deprecated": "error",
"@lwc/lwc/valid-api": "error",
"@lwc/lwc/no-document-query": "error",
"@lwc/lwc/ssr-no-unsupported-properties": "error"
}
}
Usage with TypeScript
To enable working with TypeScript projects, install @babel/preset-typescript
as a dependency add "typescript"
to parserOptions.babelOptions.parserOpts.plugins
in your .eslintrc
.
Example:
{
"parserOptions": {
"babelOptions": {
"parserOpts": {
"plugins": [
"classProperties",
["decorators", { "decoratorsBeforeExport": false }],
"typescript"
]
}
}
}
}
For more details about configuration please refer to the dedicated section in the ESLint documentation: https://eslint.org/docs/user-guide/configuring
Configurations
To choose from three configuration settings, install the eslint-config-lwc
sharable configuration package.
Processors
Processor ID | Description |
---|
lwc/ssr | Lint only JavaScript files of SSR-able components |
Rules
LWC
Best practices
Compat performance
Older browsers like IE11 run LWC in compatibility mode. For more information about browser performance, please refer to Supported Browsers in the Lightning Web Components Developer Guide.
Deprecated