Error when used with eslint-plugin-graphql in v2.5.0
See original GitHub issueWhat version of eslint
are you using?
4.15.0
What version of prettier
are you using?
1.10.2
What version of eslint-plugin-prettier
are you using?
2.5.0
Please paste any applicable config files that you’re using (e.g. .prettierrc
or .eslintrc
files)
Relevant rules:
{
'prettier/prettier': [
1,
{
printWidth: 120,
trailingComma: 'es5',
singleQuote: true,
semi: false,
},
],
'graphql/template-strings': [
2,
{
env: 'literal',
schemaJson: require('./graphql/schema.json'),
},
],
}
What source code are you linting?
This seems to happen for any .graphql
file while using eslint-plugin-graphql
(I’m on version 1.4.1).
What did you expect to happen? It should lint correctly.
What actually happened?
In eslint-plugin-prettier
2.4.0
everything works, but since 2.5.0
I get the following error:
Syntax Error: Unexpected Name "ESLintPluginGraphQLFile" (1:1)
> 1 | ESLintPluginGraphQLFile`#import "./redacted-file-name.graphql"
| ^
Assuming this has to do with the plugin now passing the filename to prettier, and eslint-plugin-graphql causes graphql files to have a weird filename reported somehow?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:8
- Comments:12 (5 by maintainers)
Top Results From Across the Web
@graphql-eslint/eslint-plugin - npm
Key Features. Integrates with ESLint core (as a ESTree parser); Works on .graphql files, gql usages and /* GraphQL */ magic comments ...
Read more >Migrating from v2 to v3 - Gatsby
Introduction. This is a reference for upgrading your site from Gatsby v2 to Gatsby v3. Since the last major release was in September...
Read more >eslint-plugin-prettier | Yarn - Package Manager
Runs Prettier as an ESLint rule and reports differences as individual ESLint issues. ... you should use a different tool such as prettier-eslint...
Read more >Unable to get eslint-plugin-graphql to notice deprecated fields
'graphql/template-strings': [ 'error', { env: 'literal', // eslint-disable-next-line global-require schemaJson: require('./graphql.schema.json') ...
Read more >Introducing GraphQL-ESLint! – The Guild
Lints both GraphQL schema and GraphQL operations. Extended type-info for more advanced use-cases and sophisticated validations; ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After doing some deep pondering trying to wrangle this. I believe I understand what is going on and the best way for fix this.
I don’t think there needs to be a
processedFileExtensions
option. Instead people can disable the prettier rule for a subset of files using eslint overrides. Add an overrides section to the bottom of your eslint config, after yourrules: {}
like so:This shall disable the prettier rules for graphql, instead of forcing the parser to be potentially incorrect for all files.
The problem occurs because eslint-plugin-graphql registers an eslint processor that runs over
.graphql
and.gql
files which transforms those files into a block of JS that eslint can understand (basically wrapping the file content in a tagged template literal so it becomes valid JS). This processor runs for all files before all rules, and there is no way to say “only allow this parser for a subset of rules”. This is reasonable as processors are designed to extract javascripty parts from a file rather than teach eslint about a whole new language and you’d want all existing rules to run over those pieces of extracted JS.I don’t think there is any value in forcing the parser for graphql files as the processor is not considered autofixable and the processor currently swallows up all linting issues that aren’t their own rules. Thus issues raised by the prettier/prettier rule would never be visible and would never be autofixed. There is no point in running prettier over these files if the results will never be exposed. If eslint-plugin-graphql fixes their code to expose rule violations other than their own then it would be straightforward to enable prettier, but forcing the ‘babylon’ parser, for graphql and gql:
I found that its also possible to work around this problem without downgrading
eslint-plugin-prettier
by instead using its configuration option to specify the parser:Not sure if this has any unintended side effects - I assume not, since you would not need to use anything except a javascript parser from within eslint (which only deals with javascript).