1.8.1 • Published 7 days ago

@lwc/eslint-plugin-lwc v1.8.1

Weekly downloads
14,644
License
MIT
Repository
github
Last release
7 days ago

@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"
    }
}

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.

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 the lwc 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 with wire decorator
lwc/no-unknown-wire-adaptersdisallow usage of unknown wire adapters
lwc/valid-apivalidate api decorator usage
lwc/valid-trackvalidate track decorator usage
lwc/valid-wirevalidate wire decorator usage
lwc/no-restricted-browser-globals-during-ssrdisallow access to global browser APIs during SSR
lwc/no-unsupported-ssr-propertiesdisallow access of unsupported properties in SSR
lwc/no-node-env-in-ssrdisallow usage of process.env.NODE_ENV in SSR
lwc/valid-graphql-wire-adapter-callback-parametersensure graphql wire adapters are using 'errors' instead of 'error'

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 of innerHTML
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 of CustomEvent over Event constructor

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.

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
1.8.1

7 days ago

1.8.0

10 days ago

1.7.2

4 months ago

1.6.4

7 months ago

1.7.0

6 months ago

1.6.3

11 months ago

1.6.2

1 year ago

1.6.1

1 year ago

1.5.1

1 year ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.0-236.0

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

3 years ago

1.0.1

3 years ago

0.12.2-232.0

3 years ago

1.0.0

3 years ago

0.12.2

3 years ago

0.12.1

3 years ago

0.12.0

3 years ago

0.11.0

3 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago