Skip to content

unused-fields: fake positive on different scopes #150

Open
@caiotoon

Description

The rule is currently matching any occurrences in the entire file, even when usage is in different functions. The following invalid test fails:

    {
      code: `
        function method1() {
          graphql\`fragment Test2 on SomeEntity {
            unused1
          }\`;
          const { unused1 } = node;
          return unused1;
        }
        function method2() {
          graphql\`fragment Test on Page {
            unused1
            used1
          }\`;
          var { used1 } = node;
        }
      `,
      errors: [
        {
          message: unusedFieldsWarning('unused1'),
          line: 7
        }
      ]
    }

The message is currently clear and matches the behaviour, so I believe this might have been intentional given the difficulty of trying to maintain scope and context for the validation.

[...] this file does not seem to use it directly. [...]

Opening this one to track the possibility of adding a new rule to validate considering the scope.

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