question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Prettier and ESLint in VS Code crash svelte compiler

See original GitHub issue

Describe the bug With this template where we want ESLint to co exist with prettier I have 2 problems when the plugins are nebale with this config

As described in the prettier docs this enable ESLint to call prettier

  1. Lint crashes in the svlte compile - see stack trace
  2. Prettier fails to format on save the App.svelte file - and error flashes up in the status bar

Logs see stack trace

To Reproduce Uncommented the line aboveand comment the one above it

  1. Run npm run lint from the command line
  2. edit the App.svelte and save the file

Expected behavior

  1. no error and llinter succeeds
  2. File is reformated via prettier

Stacktraces

Stack trace

$ npm run lint

svelte-project@1.0.0 lint C:\projects\svelte-code-cypress-project eslint src/*

ParseError: Expected } 1 | export let name 2 |

3 | {name;name=0} | ^ Occurred while linting C:\projects\svelte-code-cypress-project\src\App.svelte:3 at error$1 (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13329:20) at Parser$2.error (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13405:10) at Parser$2.eat (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13419:19) at mustache (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13220:17) at new Parser$2 (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13364:22) at Object.parse$1 [as parse] (C:\projects\svelte-code-cypress-project\node_modules\svelte\compiler.js:13495:21) at Object.parse (C:\projects\svelte-code-cypress-project\node_modules\prettier-plugin-svelte\plugin.js:669:51) at Object.parse$2 [as parse] (C:\projects\svelte-code-cypress-project\node_modules\prettier\index.js:10629:19) at coreFormat (C:\projects\svelte-code-cypress-project\node_modules\prettier\index.js:13888:23) at format (C:\projects\svelte-code-cypress-project\node_modules\prettier\index.js:14146:73) npm ERR! code ELIFECYCLE npm ERR! errno 2 npm ERR! svelte-project@1.0.0 lint: eslint src/* npm ERR! Exit status 2 npm ERR! npm ERR! Failed at the svelte-project@1.0.0 lint script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\steve\AppData\Roaming\npm-cache_logs\2019-09-11T17_00_42_583Z-debug.log

Information about your Svelte project:

  • Your browser and the version: (e.x. Chrome 52.1, Firefox 48.0, IE 10) Not relevant - build error

  • Your operating system: (e.x. OS X 10, Ubuntu Linux 19.10, Windows XP, etc) Windows 10 latest 1903

  • Svelte version (Please check you can reproduce the issue with the latest release!) 3.12.1

  • Whether your project uses Webpack or Rollup Roll up

Severity How severe an issue is this bug to you? Is this annoying, blocking some users, blocking an upgrade or blocking your usage of Svelte entirely?

Serious - can’t lint or run prettier on svelte files

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
toerndevcommented, Feb 5, 2020

@Conduitry Sorry let me rephrase! I’m looking for the maintainers’ technical opinion on the possibility of having the eslint plugin working on the whole file instead. If the maintainers are open to explore the idea, it’s more enticing to start trying to solve it. 😃

No I get that the Prettier plugin isn’t official and that maybe noone in the Svelte team uses Prettier, and am not asking your to prioritize it although I’m sure tons of newcomers will want this support… 😉 There’s also the question of whether plugins are behaving as expected within the larger javascript & eslint ecosystem. How the eslint plugin might/should work, given enough development. Thus the question in my last reply about an alternative approach.

2reactions
SteveALeecommented, Feb 5, 2020

it although I’m sure tons of newcomers will want this support… 😉

I’d like to add my support to this, at least as a single newcomerto svelte. My workflow always included prettier to reformat my messy editing on file save. So it was natural to continue to use it for the JS part of svelte files.

I get that svelte files are NOT javascript but a compiled super set and that might lead to some issues but in general I want prettier to continue to work. In fact I doubt there will be any issues as Richard was careful to overload existing JS syntax for all new features - eg labels

Read more comments on GitHub >

github_iconTop Results From Across the Web

Svelte with prettier/eslint - Stack Overflow
I would like to setup prettier and eslint, I installed those dependencies and the extension for Svelte for VS Code.
Read more >
Svelte for VS Code - Visual Studio Marketplace
Extension for Visual Studio Code - Svelte language support for VS Code. ... The formatter is a Prettier plugin, which means some formatting...
Read more >
prettier-plugin-svelte - Bountysource
As described in the prettier docs this enable ESLint to call prettier. 1) Lint crashes in the svlte compile - see stack trace...
Read more >
Svelte | Everything I know - My Knowledge Wiki
Sapper - Framework for building web applications of all sizes, with a beautiful development experience and flexible filesystem-based routing. Code. Awesome ...
Read more >
Let's Learn Svelte - CodingCat.dev
In this crash course, you'll learn all the basics including ... skeleton project without the TypeScript, ESLint, or Prettier configurations.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found