Skip to content

False positive in @lwc/lwc/valid-graphql-wire-adapter-callback-parameter if a class method signature expects an object with an error property #160

Open
@amurashincertinia

Description

@amurashincertinia

There is a bug in @lwc/lwc/valid-graphql-wire-adapter-callback-parameter which falsely reports undecorated class methods if their argument is an object with an error property like in this example:

class C {
    f({ error }) {
        return error;
    }
}

The root cause of the issue is that the graphQlDecorator const is initialised as false if decorators === undefined:

// Check that the @wire decorator is using graphql
const graphQlDecorator =
    decorators !== undefined && // this yields `false`
    decorators.find((decorator) => { // this does not run

Which satisfies the condition for verification:

// Verify that the method definition is using 'errors' not 'error
if (graphQlDecorator !== undefined) { // this evaluates to `true`

Replacing the decorators !== undefined check with an optional chaining operator fixes the issue.

const graphQlDecorator = decorators?.find((decorator) => { // happy days!

An alternative solution without optional chaining:

const graphQlDecorator = (decorators || []).find((decorator) => {

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions