Prettier on virtual documents generated by processor
See original GitHub issueDescribe the bug
Codefile with GraphQL operations:
import { gql } from "apollo-server-core";
export const OPERATION = gql`
query operation($id: ID!) {
operation(id: $id) {
id
}
}
`;
Prettier try to convert it to:
import { gql } from "apollo-server-core";
export const OPERATION = gql`query operation($id: ID!) {
operation(id: $id) {
id
}
}`;
To Reproduce
.prettierrc.json
{
"printWidth": 120,
"overrides": [
{
"files": "*.graphql",
"options": {
"parser": "graphql"
}
}
]
}
.eslintrc.json
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"processor": "@graphql-eslint/graphql",
"overrides": [
{
"files": ["*.graphql"],
"parser": "@graphql-eslint/eslint-plugin",
"plugins": ["@graphql-eslint"],
"rules": {
"@graphql-eslint/require-id-when-available": ["error"]
}
}
]
}
Expected behavior
Keep codefile with GraphQL operations:
import { gql } from "apollo-server-core";
export const OPERATION = gql`
query operation($id: ID!) {
operation(id: $id) {
id
}
}
`;
Environment:
- OS: Linux 5.10.34-1-lts
@graphql-eslint/...
: 0.9.1- NodeJS: 14.16.0
Additional context
I will try to explain what I think is happening adding new line characters \n
to the document:
import { gql } from "apollo-server-core";\n
\n
export const OPERATION = gql`\n
query operation($id: ID!) {\n
operation(id: $id) {\n
id\n
}\n
}\n
`;\n
The @graphql-eslint/eslint-plugin
processor extract from “gql`” to “`;” so the generated virtual document begin with a new line:
\n
query operation($id: ID!) {\n
operation(id: $id) {\n
id\n
}\n
}\n
I think is better extract from “gql`\n” to “`;” if the \n
exists and my assumptions are correct…
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Configuration File - Prettier
Overrides let you have different configuration for certain file extensions, folders and specific files. Prettier borrows ESLint's override format. ... files is ...
Read more >How To Format Code with Prettier in Visual Studio Code
Step 1 — Using the Format Document Command · Step 2 — Formatting Code on Save · Step 3 — Changing the Prettier...
Read more >prettier.configPath is ignored when current file is virtual (?)
Summary. When editing a file from GitHub Gist using GistPad, the prettier.configPath is ignored. Github Repository to Reproduce Issue.
Read more >Contributing - Datasette documentation
This document describes how to contribute to Datasette core. ... The next step is to create a virtual environment for your project and...
Read more >homebrew-core - Homebrew Formulae
a2ps 4.14 Any‑to‑PostScript filter
aacgain 1.8 AAC‑supporting version of mp3gain
aalib 1.4rc5 Portable ASCII art graphics library
aamath 0.3 Renders mathematical expressions as ASCII art
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 FreeTop 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
Top GitHub Comments
Thanks @joual for reporting it, and @B2o5T for the help here! Awesome work 😃 I think we can safely close this one. @xeladejo if you think we need to reopen - just ping me! 😃
Yeah, that seems to work fine.
If it were possible to use
--fix
in the problems detected in virtual documents it would be perfect.Thanks you.
— EDITED —
The
--fix
trouble seems happen only onvscode
, in the CLI the line is incorrect but it seems to be fixed correctly. I will try to test it better.