-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support prettier #16
Comments
Adding this hasn't been ruled out. A while ago I did actually fiddle with this some in this outdated branch, and it seemed to work reasonably well. It's mostly a matter of carefully adding comments to disable and reenable Prettier as well as for ESLint. |
Seems, it does not work. I have the following
and that component:
after
during
|
As stated in the newest Prettier docs, using packages like |
After some digging, this appears to be caused by the I was hoping to get this to work for GitHub Actions, so that all linting and styling errors are both reported through the same mechanism, so that they can then be written as inline errors into the Pull Request UI If anyone knows of another way to use |
What's the problem with chaining this in one npm script? |
@dummdidumm I'm looking to make use of this Github linting action: https://github.com/wearerequired/lint-action ... so that any errors picked up by eslint are visible in the Pull Request UI I believe that if I can get The issue is that there's no compatibility between eslint, prettier, and svelte source code. The other solution is to remove |
Maybe prettier/eslint-plugin-prettier#415 this PR would help, I can add |
I don't understand this fully. Does this mean that |
Yes! But Or we can make a fake parser for Then in processor we do: {
preprocess(text, filename) {
return [
text, // represents the whole `.svelte` file, will be parsed by fake parser and be compatible with `eslint-plugin-prettier`
// .. original code blocks
]
}
} // fake parser
exports.parseForESLint = function() {
return {
// ...
ast: {
// ...
}
}
} Final usage {
"parser": "eslint-plugin-svelte3",
"prosessor": "eslint-plugin-svelte3"
} Or, we should just ignore this isse. User should always use |
Now I'm confused. I thought that |
A rule only cares about In my PR prettier/eslint-plugin-prettier#415 (or similar prettier/stylelint-prettier#22), if the whole file can be parsed by But the question is how could the whole file be run with The answer is the fake |
You can see this pattern at the following:
|
Hi, eslint-plugin-prettier maintainer here :) Interop between eslint-plugin-prettier and processors that teach eslint about non-js file types gets FUN, however recently @JounQin shown me the concept of processors providing virtual filenames, which reduces potential for wonky interop. Currently eslint-plugin-svelte3 doesn't leverage these virtual filenames by default - only if named_blocks is set. This means that when named_blocks is set - eslint-plugin-prettier sees the virtual filename However when named_blocks is not set there is no virtual filename, only the "on disk" filename Now eslint-prettier-plugin does maintain a list of cases where a processor does not use virtual filenames and thus it should force using the JS parser instead of whatever gets inferred from the filename, but it'd be super nice if I didn't have to add support for every processor. It's a clunky breaking change on your end, (which sucks, sorry) but I think the best long-term fix might be to remove the named_blocks setting and have it's behaviour on by default for the sake of better interoperability. This will also improve interop with other situations such as when a user only enables some eslint typescript-specific rules for *.ts - by adding virtual filenames these rules will be ran over TS in svelte files when the |
While is clearly not the path @BPScott want to follow, I can confirm that updating the array in this line by adding However after that Prettier starts to complain about some rules inside JavaScript expressions, which also ends up leading to new errors. Example: <h1>Hello, {name}</h1> Prettier forces the above code to: <h1>Hello, {name;}</h1> This kind of rules should only be applied to JavaScript inside So making Prettier work properly with ESLint in a Svelte project will be probably a little harder and maybe require some fine tuning in one or more related plugins. Edit: I've setup a minimal repo to help reproduce the errors when trying to use ESLint, Prettier and Svelte: https://github.com/kazzkiq/svelte-eslint-prettier-error |
The proposed solution in #16 (comment) is probably not feasible because TS users have to switch it back because apparently the TS parser doesn't like virtual files: #162 |
We recommend to use See also https://github.com/prettier/eslint-plugin-prettier#svelte-support |
thank you @JounQin for the info. I've found |
I know that the plugin doesn't work with prettier at the moment. However, the documentation doesn't explain the rationale behind this decision, and whether you have interest in "fixing" it or not. I suggest to either amend the documentation, or leave this issue opened as a part of the road map.
For example, eslint-plugin-vue works just fine with prettier, and I don't see how Vue components are logically different from Svelte components.
The text was updated successfully, but these errors were encountered: