Search code examples
intellij-ideasvelte

Force Intellij to format Svelte pages with 4 spaces for indenting?


  • IDEA: 2021.1.3
  • Svelte plugin: 0.19.0

I have the Svelte IDEA plugin installed and it keeps trying to indent everything with 2 spaces, instead of 4 spaces (the rest of the project uses 4 spaces).

I can't figure out how to customise it.

  • There's no "Svelte" entry under File | Settings | Editor | Code Style
  • All other code styles are set to 4 spaces (typescript, html, javascript, etc.)
  • There's no .editorconfig file in my project source

I could swear this thing was indenting consistent with the rest of the project just a few weeks ago, but now I'm not sure.

How do I tell IDEA to use 4 spaces for indenting Svelte files?


Solution

  • For me, the answer the was to turn off "detect and use existing file indents".

    enter image description here

    The indenting widget in the bottom right of the editor will tell you if IDEA has decided your file is "2 spaces" or "4 spaces". You can also use this widget to force re-indent to 4 spaces.

    enter image description here

    This auto-detection probably explains why IDEA suddenly started to behave differently. Maybe there was a change in a recent IDEA patch, or perhaps my project files changed through editing to trigger the algorithm into thinking the Svelte files were using 2 spaces for indenting.