- Notifications
You must be signed in to change notification settings - Fork37
Official ESLint rules for LWC
License
salesforce/eslint-plugin-lwc
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Official ESLint rules for Lightning Web Components (LWC).
$ npm install eslint @babel/core @babel/eslint-parser @lwc/eslint-plugin-lwc --save-dev
Starting with v3.0.0, @lwc/eslint-plugin-lwc only supports eslint@v9. Use @lwc/eslint-plugin-lwc@v1.x for older versions of eslint.
Import@lwc/eslint-plugin-lwc
and use it in theplugins
section of your configuration as shown below. Then configure the desired rules in therules
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 theparser
field to@babel/eslint-parser
in thelanguageOptions
section of the eslint config.
Example ofeslint.config.js
:
consteslintPluginLwc=require('@lwc/eslint-plugin-lwc');constbabelParser=require('@babel/eslint-parser');module.exports=[{languageOptions:{parser:babelParser,parserOptions:{requireConfigFile:false,babelOptions:{parserOpts:{plugins:['classProperties',['decorators',{decoratorsBeforeExport:false}],],},},},},plugins:{'@lwc/lwc':eslintPluginLwc,// https://github.com/salesforce/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',},},];
To enable working with TypeScript projects, install@babel/preset-typescript
as a dependency add"typescript"
tolanguageOptions.parserOptions.babelOptions.parserOpts.plugins
in youreslint.config.js
.
Example:
consteslintPluginLwc=require('@lwc/eslint-plugin-lwc');constbabelParser=require('@babel/eslint-parser');module.exports=[{languageOptions:{parser:babelParser,parserOptions:{requireConfigFile:false,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
To choose from three configuration settings, install theeslint-config-lwc
sharable configuration package.
Processor ID | Description |
---|---|
lwc/ssr | Lint only JavaScript files of SSR-able components |
Rule ID | Description | Fixable |
---|---|---|
lwc/consistent-component-name | ensure component class name matches file name | 🔧 |
lwc/no-api-reassignments | prevent public property reassignments | |
lwc/no-deprecated | disallow usage of deprecated LWC APIs | |
lwc/no-document-query | disallow DOM query at the document level | |
lwc/no-attributes-during-construction | disallow setting attributes during construction | |
lwc/no-disallowed-lwc-imports | disallow importing unsupported APIs from thelwc package | |
lwc/no-leading-uppercase-api-name | ensure public property doesn't start with an upper-case character | |
lwc/no-unexpected-wire-adapter-usages | enforce wire adapters to be used withwire decorator | |
lwc/no-unknown-wire-adapters | disallow usage of unknown wire adapters | |
lwc/valid-api | validateapi decorator usage | |
lwc/valid-track | validatetrack decorator usage | |
lwc/valid-wire | validatewire decorator usage | |
lwc/valid-graphql-wire-adapter-callback-parameters | ensure graphql wire adapters are using 'errors' instead of 'error' | |
lwc/no-host-mutation-in-connected-callback | disallow the host element mutation in 'connectedCallback' | |
lwc/consistent-component-name | ensure component class name matches file name | 🔧 |
lwc/no-api-reassignments | prevent public property reassignments | |
lwc/no-deprecated | disallow usage of deprecated LWC APIs | |
lwc/no-document-query | disallow DOM query at the document level | |
lwc/no-attributes-during-construction | disallow setting attributes during construction | |
lwc/no-disallowed-lwc-imports | disallow importing unsupported APIs from thelwc package | |
lwc/no-leading-uppercase-api-name | ensure public property doesn't start with an upper-case character | |
lwc/no-unexpected-wire-adapter-usages | enforce wire adapters to be used withwire decorator | |
lwc/no-unknown-wire-adapters | disallow usage of unknown wire adapters | |
lwc/valid-api | validateapi decorator usage | |
lwc/valid-track | validatetrack decorator usage | |
lwc/valid-wire | validatewire decorator usage | |
lwc/ssr-no-restricted-browser-globals | disallow access to global browser APIs during SSR | |
lwc/ssr-no-unsupported-properties | disallow access of unsupported properties in SSR | |
lwc/ssr-no-node-env | disallow usage of process.env.NODE_ENV in SSR | |
lwc/ssr-no-disallowed-lwc-imports | restrict specific imports from the lwc package in SSR-able components | |
lwc/valid-graphql-wire-adapter-callback-parameters | ensure graphql wire adapters are using 'errors' instead of 'error' | |
lwc/ssr-no-host-mutation-in-connected-callback | disallow the host element mutation in 'connectedCallback' | |
lwc/ssr-no-static-imports-of-user-specific-scoped-modules | disallow static imports of user-specific scoped modules in SSR-able components | |
lwc/ssr-no-form-factor | disallow formFactor in SSR-able components |
Rule ID | Description | Fixable |
---|---|---|
lwc/no-async-operation | restrict usage of async operations | |
lwc/no-dupe-class-members | disallow duplicate class members | |
lwc/no-inner-html | disallow usage ofinnerHTML | |
lwc/no-template-children | prevent accessing the immediate children of this.template | |
lwc/no-leaky-event-listeners | prevent event listeners from leaking memory | |
lwc/prefer-custom-event | suggest usage ofCustomEvent overEvent constructor | |
lwc/ssr-no-unsupported-node-api | disallow unsupported Node API calls in SSR-able components |
Older browsers like IE11 run LWC in compatibility mode. For more information about browser performance, please refer toSupported Browsers in the Lightning Web Components Developer Guide.
Rule ID | Description | Fixable |
---|---|---|
lwc/no-async-await | disallow usage of the async-await syntax | |
lwc/no-for-of | disallow usage of the for-of syntax | |
lwc/no-rest-parameter | disallow usage of the rest parameter syntax |
Rule ID | Replaced by |
---|---|
lwc/no-dupe-class-members | no-dupe-class-members(base eslint rule) |
About
Official ESLint rules for LWC
Topics
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.