Skip to content

Latest commit

 

History

History
87 lines (58 loc) · 1.76 KB

no-disallowed-lwc-imports.md

File metadata and controls

87 lines (58 loc) · 1.76 KB

Prevent importing restricted APIs from the "lwc" package (no-disallowed-lwc-imports)

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.

Rule details

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.

allowlist

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';

allowBareImports

The allowBareImports property, when set to true, allows the following to be treated as correct code:

import 'lwc';

The default value is false.

allowExports

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.