relayjs / eslint-plugin-relay

A plugin for the code linter ESLint to lint specific details about Relay.
MIT License
99 stars 46 forks source link

It's impossible to disable `unused-fields` and `must-colocate-fragment-spreads` with `reportUnusedDisableDirectives` #152

Open alecmev opened 4 weeks ago

alecmev commented 4 weeks ago

The problem is pretty simple, this plugin has its own handling of eslint-disable directives in GraphQL strings:

https://github.com/relayjs/eslint-plugin-relay/blob/24fd162eee099e3f8145f26b3e7d82fa60952466/src/rule-unused-fields.js#L23-L25

Which is at odds with ESLint's overall approach of "run every rule enabled in the configuration, and then just swallow the errors reported by eslint-disabled code". Currently I get the following error:

Unused eslint-disable directive (no problems were reported from 'relay/unused-fields')

And there's no way around it sans just disabling reportUnusedDisableDirectives, which I don't want to do. My current workaround is to wrap offending template literals in /* eslint-disable relay/unused-fields */.

The only solution I see is to do what graphql-eslint does and utilize a processor (very preferably the same one, so that they don't clash with each other). See https://github.com/relayjs/eslint-plugin-relay/issues/153 for a related problem.

captbaritone commented 3 weeks ago

Thanks for the report. Can you share an example of code that triggers the issue here? Is it that when you include an eslint-ignore inline in the graphql tagged template literal (# eslint-disable-next-line relay/unused-fields) that this triggers eslint's own reportUnusedDisableDirectives?

captbaritone commented 3 weeks ago

Additional question: Does this happen when Relay's lint rule is enabled by itself, or is it an interaction with graphql-eslint?

alecmev commented 3 weeks ago

Is it that when you include an eslint-ignore inline in the graphql tagged template literal (# eslint-disable-next-line relay/unused-fields) that this triggers eslint's own reportUnusedDisableDirectives?

Exactly! Done inside a useLazyLoadQuery(graphql`...`).

Does this happen when Relay's lint rule is enabled by itself, or is it an interaction with graphql-eslint?

Thanks for asking this, I went to double-check and removed graphql-eslint's config outright (instead of using the workaround of including *.graphql in eslint-plugin-relay's files), and the directives aren't reported as unused anymore. So your hunch is correct, this happens only when graphql-eslint's processor is enabled. In retrospect, this is obvious, as without the processor to ESLint the template literal is just an opaque string 😛 Would you like me to close this issue in favor of #153?