Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 1.83 KB

no-unknown-wire-adapters.md

File metadata and controls

50 lines (36 loc) · 1.83 KB

Disallow usage of unknown wire adapters (no-unknown-wire-adapters)

To support use cases such as prefetching and offline, all wired properties must be statically analyzable, which means that all wire adapters must be known.

Rule details

This rule can be configured as follows:

{
    adapters: [
        // for modules exporting wire adapters using named exports
        { module: '<module name>', identifier: '<adapter identifier>' },

        // for modules exporting wire adapters using default exports
        { module: '<module name>', identifier: 'default' },

        // to match multiple adapters, use glob patterns
        { module: '<module name glob pattern>', identifier: '<adapter identifier glob pattern>' },
    ];
}

Any usage of the @wire decorator will be flagged as an error unless a list of known adapters has been provided.

/*eslint lwc/no-unexpected-wire-adapters: ["error", {"adapters": [{"module": "myAdapters", "identifier": "fooAdapter"}, {"module": "@salesforce/apex/*", "identifier": "*"}]}]*/

import { LightningElement, wire } from 'lwc';
import { apexMethod } from '@salesforce/apex/Namespace.Classname.apexMethodReference';
import { otherApexMethod } from '@salesforce/apex/Namespace/Classname.apexMethodReference';
import defaultAdapter, { fooAdapter, barAdapter } from 'myAdapters';

export default class Example extends LightningElement {
    @wire(fooAdapter) // valid
    foo;

    @wire(barAdapter) // invalid, missing adapter in config: {"module": "myAdapters", "identifier": "barAdapter"}
    bar;

    @wire(defaultAdapter) // invalid, missing adapter in config: {"module": "myAdapters", "identifier": "default"}
    default;

    @wire(apexMethod) // valid
    apexMethodResult;

    @wire(otherApexMethod) // invalid, does not match "@salesforce/apex/*" glob pattern
    otherApexMethodResult;
}