Skip to content

eslint-plugin-query: false positive for out-of-scope constants with arrow functions #5416

@TkDodo

Description

@TkDodo

interestingly, we have a test for this:

{
  name: 'should ignore constants defined out of scope (react hook)',
  code: `
    const CONST_VAL = 1
    function useHook() {
      useQuery({
        queryKey: ["foo"],
        queryFn: () => CONST_VAL
      });
    }
  `,
},

which passes, but it starts to break as soon as we use an arrow function:

{
  name: 'should ignore constants defined out of scope (react hook arrow fn)',
  code: `
    const CONST_VAL = 1
    const useHook = () => {
      useQuery({
        queryKey: ["foo"],
        queryFn: () => CONST_VAL
      });
    }
  `,
},

message: 'The following dependencies are missing in your queryKey: CONST_VAL',

@Newbie012 can you please take a look

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions