Restricts importing disallowed modules from the lwc
package. It's recommended to only use the "safe" APIs allowed by this rule.
This rule also disallows default imports as well as bare imports and exports – only importing explicitly named modules is allowed.
Examples of incorrect code:
import { SecretApiYouShouldNotUse } from 'lwc';
import * as lwc from 'lwc';
import lwc from 'lwc';
import 'lwc';
export * from 'lwc';
Examples of correct code:
import { LightningElement } from 'lwc';
import { LightningElement, wire, api } from 'lwc';
If you disable this rule, then you may import unstable or otherwise undesirable APIs from lwc
.
The allowlist
property overrides the default list of APIs that could be imported from the lwc
package. It accepts an array of strings.
Examples of incorrect code:
/* eslint lwc/valid-api: ["error", { "allowlist": ["LightningElement"] }] */
import { wire } from 'lwc';
Examples of correct code:
/* eslint lwc/valid-api: ["error", { "allowlist": ["LightningElement"] }] */
import { LightningElement } from 'lwc';
The allowBareImports
property, when set to true
, allows the following to be treated as correct code:
import 'lwc';
The default value is false
.
The allowExports
property, when set to true
, allows any exports
(such as the following) to be treated as correct code:
export * from 'lwc';
export { LightningElement } from 'lwc';
export { doesNotExist } from 'lwc';
The default value is false
.