Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Official ESLint rules for LWC

License

NotificationsYou must be signed in to change notification settings

salesforce/eslint-plugin-lwc

Repository files navigation

Official ESLint rules for Lightning Web Components (LWC).

Installation

$ npm install eslint @babel/core @babel/eslint-parser @lwc/eslint-plugin-lwc --save-dev

Usage

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',},},];

Usage with TypeScript

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

Configurations

To choose from three configuration settings, install theeslint-config-lwc sharable configuration package.

Processors

Processor IDDescription
lwc/ssrLint only JavaScript files of SSR-able components

Rules

LWC

Rule IDDescriptionFixable
lwc/consistent-component-nameensure component class name matches file name🔧
lwc/no-api-reassignmentsprevent public property reassignments
lwc/no-deprecateddisallow usage of deprecated LWC APIs
lwc/no-document-querydisallow DOM query at the document level
lwc/no-attributes-during-constructiondisallow setting attributes during construction
lwc/no-disallowed-lwc-importsdisallow importing unsupported APIs from thelwc package
lwc/no-leading-uppercase-api-nameensure public property doesn't start with an upper-case character
lwc/no-unexpected-wire-adapter-usagesenforce wire adapters to be used withwire decorator
lwc/no-unknown-wire-adaptersdisallow usage of unknown wire adapters
lwc/valid-apivalidateapi decorator usage
lwc/valid-trackvalidatetrack decorator usage
lwc/valid-wirevalidatewire decorator usage
lwc/valid-graphql-wire-adapter-callback-parametersensure graphql wire adapters are using 'errors' instead of 'error'
lwc/no-host-mutation-in-connected-callbackdisallow the host element mutation in 'connectedCallback'
lwc/consistent-component-nameensure component class name matches file name🔧
lwc/no-api-reassignmentsprevent public property reassignments
lwc/no-deprecateddisallow usage of deprecated LWC APIs
lwc/no-document-querydisallow DOM query at the document level
lwc/no-attributes-during-constructiondisallow setting attributes during construction
lwc/no-disallowed-lwc-importsdisallow importing unsupported APIs from thelwc package
lwc/no-leading-uppercase-api-nameensure public property doesn't start with an upper-case character
lwc/no-unexpected-wire-adapter-usagesenforce wire adapters to be used withwire decorator
lwc/no-unknown-wire-adaptersdisallow usage of unknown wire adapters
lwc/valid-apivalidateapi decorator usage
lwc/valid-trackvalidatetrack decorator usage
lwc/valid-wirevalidatewire decorator usage
lwc/ssr-no-restricted-browser-globalsdisallow access to global browser APIs during SSR
lwc/ssr-no-unsupported-propertiesdisallow access of unsupported properties in SSR
lwc/ssr-no-node-envdisallow usage of process.env.NODE_ENV in SSR
lwc/ssr-no-disallowed-lwc-importsrestrict specific imports from the lwc package in SSR-able components
lwc/valid-graphql-wire-adapter-callback-parametersensure graphql wire adapters are using 'errors' instead of 'error'
lwc/ssr-no-host-mutation-in-connected-callbackdisallow the host element mutation in 'connectedCallback'
lwc/ssr-no-static-imports-of-user-specific-scoped-modulesdisallow static imports of user-specific scoped modules in SSR-able components
lwc/ssr-no-form-factordisallow formFactor in SSR-able components

Best practices

Rule IDDescriptionFixable
lwc/no-async-operationrestrict usage of async operations
lwc/no-dupe-class-membersdisallow duplicate class members
lwc/no-inner-htmldisallow usage ofinnerHTML
lwc/no-template-childrenprevent accessing the immediate children of this.template
lwc/no-leaky-event-listenersprevent event listeners from leaking memory
lwc/prefer-custom-eventsuggest usage ofCustomEvent overEvent constructor
lwc/ssr-no-unsupported-node-apidisallow unsupported Node API calls in SSR-able components

Compat performance

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 IDDescriptionFixable
lwc/no-async-awaitdisallow usage of the async-await syntax
lwc/no-for-ofdisallow usage of the for-of syntax
lwc/no-rest-parameterdisallow usage of the rest parameter syntax

Deprecated

Rule IDReplaced by
lwc/no-dupe-class-membersno-dupe-class-members(base eslint rule)

[8]ページ先頭

©2009-2025 Movatter.jp