dimaMachina / graphql-eslint

ESLint parser, plugin and set rules for GraphQL (for schema and operations). Easily customizable with custom rules. Integrates with IDEs and modern GraphQL tools.
https://the-guild.dev/graphql/eslint
MIT License
795 stars 103 forks source link

Report lint issues inline, not on first char of file, for Vue and Svelte #2103

Open bmulholland opened 9 months ago

bmulholland commented 9 months ago

Is it possible to resolve the limitations that results in the workaround introduced at https://github.com/dimaMachina/graphql-eslint/pull/1346 ?

bmulholland commented 9 months ago

Amongst other things, I expect this limitation means that https://github.com/reviewdog/reviewdog (and similar, diff-based approaches) won't fail PRs that introduce linting errors, meaning we lost a critical enforcement of these policies.

dimaMachina commented 8 months ago

as I remember graphql-tag-pluck returns compiled code for vue/svelte files, as result - location of extracted documents will be incorrect from the source file

Maybe there is some workaround to parse vue/svelte files with vue/svelte parsers and run graphql-eslint processor on extracted js/ts code-blocks, example

  overrides: [
    {
      files: ['**/*.svelte'],
      parser: 'svelte-eslint-parser',
    },
    {
      files: ['**/*.svelte/*.{js,ts}'],
      processor: '@graphql-eslint/graphql',
    }
]

PR welcome

bmulholland commented 8 months ago

Oh interesting, yeah that limitation makes sense. Thanks for the detail, I appreciate it. I suspect the strings are often the same, so also a naive string match could work to correct the locations?

I don't quite understand how the workaround with parsers would maintain location information. Why wouldn't that have the same limitation?

bmulholland commented 3 days ago

Just to jot down an idea I had here: pluck could add a magic comment at the top of its output, which includes the location it was extracted from. Then this could be read and added as an offset when reporting the lint.