Skip to content

Error parsing spread syntax with lang="pug" #228

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

Closed
4 tasks done
vglfr opened this issue Oct 14, 2022 · 3 comments
Closed
4 tasks done

Error parsing spread syntax with lang="pug" #228

vglfr opened this issue Oct 14, 2022 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@vglfr
Copy link

vglfr commented Oct 14, 2022

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I'm using eslint-plugin-svelte. (*.svelte file linting does not work with the parser alone. You should also use eslint-plugin-svelte with it.)
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-svelte repo and open the issue in eslint-plugin-svelte repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.25.0

What version of eslint-plugin-svelte and svelte-eslint-parser are you using?

What did you do?

Configuration

.eslintrc.yaml

env:
  browser: true
  es6: true
extends:
  - "eslint:recommended"
  - "plugin:svelte/recommended"
parserOptions:
  ecmaVersion: 2020
  sourceType: module

Test.svelte

<script>
  let objs = [{a: 1, b: 2}, {a: 2, b: 3}]
</script>

<template lang="pug">
  +each("objs as obj")
    p("{...obj}") {obj.a}
</template>

What did you expect to happen?

Successful parse.

What actually happened?

$ eslint Test.svelte

/home/projects/node-zm1om6/Test.svelte
7:8 error Parsing error: Unexpected token

✖ 1 problem (1 error, 0 warnings)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/node-zm1om6?file=Test.svelte

Additional comments

With ("{...obj}") dropped linter issues no-unused-vars and no-undef. It seems eslint-plugin-svelte processes markup as plaintext.

With svelte-preprocess in place Svelte compiler won't issue a warning; however a genuine error would likely result in incorrect line number. Apparently preprocessor does not map original pug to resulting html (same issue with sass). Not good in compiler, it's probably a no-go for linter.

That sounds like a load of work and wontfix. However if you think it's feasible please outline the solution, I'd like to dig in.

@ota-meshi
Copy link
Member

Thank you for posting issue.

I don't use pug so I'm not sure if it's possible.
At least it can't be used as an eslint parser if it can't be mapped to the correct location. Also, eslint's parser needs to be synchronous, so we can't even include svelte-preprocess in this parser.

@vglfr
Copy link
Author

vglfr commented Oct 17, 2022

It looks like it is possible to pull out the same trick svelte-preprocess does synchronously. There are two objections to it however:

  • we'll still have cursor positions mangled; it's really bad but handles no-undef and such; personally I could live with it
  • more importantly, current AST seems to be html-specific; expanding it to Pug and rewriting eslint-svelte-plugin rules to handle both Html and Pug (which would fix cursor positions) sounds tedious enough, but what if someone wants to handle another markup? another style processor or scripting language?

What do you think? Do you plan to support the whole gamut of languages supported by svelte-preprocess in this parser/plugin, and if yes then what's your vision for it (AST / rules)? Would you accept Pug parsing support without a plan to fix cursor position?

@ota-meshi
Copy link
Member

Would you accept Pug parsing support without a plan to fix cursor position?

If it doesn't return the correct position of the node, ESLint's auto-fix will break the source code and is unacceptable.

Do you plan to support the whole gamut of languages supported by svelte-preprocess in this parser/plugin.

The <style> tag does not contain scripts, so I think it can be partially supported, but <template> contains various directives and fragmented scripts, so I think it is difficult.
And, I don't know Pug syntax or AST. So I'm not sure how to implement Pug support.
If someone is willing to work on Pug support and even maintain it, I would consider adding Pug support to svelte-eslint-parser and eslint-plugin-svelte.

However, those who worked on eslint-plugin-vue's experimental Pug support quickly stopped maintaining them.
So I'm afraid I won't be able to find someone to do the maintenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants