In the <template> area Intellij is using 2 spaces for indention and for the <script> part it's using 4 spaces. I get errors running npm run dev because of the different indention.
I have set Intellij to use 4 spaces for all filetypes that I could find (not including JS or .vue). The project itself uses 2 spaces (I would like to change that).
However, now like I said it's using two different indention styles within the same file and that causes a whole lot of problems.
Code -> Reformat code changes the code to this style with 2 different indentions.
Any idea what's going on? Thanks!
First, make sure you don't have Detect and use existing file indents for editing enabled in Settings/Preferences | Editor | Code Style. If you do, when you auto-indent, it might apply the wrong settings.
Then, try reformatting the code using Control+Alt+L or Code -> Reformat Code.
Related
I am using vscode editing legacy php code. The phpcs extensions is great in finding potential problems. However, the old code is using tab instead of 4 spaces for indentation. phpcs would report with:
Spaces must be used to indent lines; tabs are not allowedPHPCS(Generic.WhiteSpace.DisallowTabIndent.TabsUsed)
Because it is old code, I am not planning to fix all of the tab problem. Is there any way to turn off this rule?
I tried to find phpcs config files, cannot find any. Ideally I can set a globaly, or project-wise, to disable it. Can anybody help?
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?
Svelte inherits indentation from HTML and JavaScript. Pay attention to the following settings:
Preferences / Settings | Editor | Code Style | JavaScript | Tabs and Indents | Indent.
Preferences / Settings | Editor | Code Style | HTML | Tabs and Indents | Indent.
If the settings are set to 4, check your .editorconfig file (if it exists) and finds indent_size = 2 entries. You can try to temporarily remove the .editorconfig file to make sure that the issue isn't related to it.
For me, the answer the was to turn off "detect and use existing file indents".
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.
This auto-detection probably explains why IDEA suddenly started to behave differently. Maybe there was a change int he 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.
I need to indent multiple files in WebStorm. Its option "Auto-indent" in the Code menu only indents current line.
How do I use it on multiple files like I can use "Reformat Code"?
Select the folder you want to reformat the code for in the Project tool window. Then select Code | Reformat Code
This page explains it. https://www.jetbrains.com/help/idea/2016.1/reformatting-source-code.html
Auto-indenting in IntelliJ IDEA seems to automatically takes lines previous to the selection in to consideration. This means that if the indentation is incorrect in the part of the file you're working on (e.g., 3 or 5 spaces where there should be 4, or even worse, a mix of tabs and spaces) it's annoyingly difficult to add correctly indented code.
Both new lines I'm adding and lines I use auto-indent on because I've changed them anyway get messed up like this. Since the file I'm working on is being worked on by someone else as well on another branch, I really don't want to modify over a third of the file just to indent everything correctly, but I would still like the lines that I'm actually modifying/adding to be correct - I don't see any reason to perpetuate the error when it's not necessary.
Currently the best mechanism for fixing it I've found is to manually do the spaces on a line and go from there, but it's really quite annoying, especially since I can't use the tab key or IntelliJ will immediately move to the incorrect indentation. It's barely better than copy/pasting the text to Sublime Text, fix the indentation there and paste it back without formatting.
My apologies if this has already been asked, I've tried to search for it, but it's very hard to search for this as there's so many auto-indent questions.
IntelliJ IDEA recently added a feature (in v14 or 1v4.1 if I recall) where it will detect indentation that is different from your settings. It will honor those indentations (in order to keep the file consistent). Usually as soon as you start editing the file, you get a banner, although that can be turned off. The banner looks like this:
This allows you to modify this setting on a per file basis, or turn it off completely (i.e. the "Show Settings" option).
I suspect this feature is what is causing you the issue. I am not sure how it handles a case where a file has mixed indentation (e.g. most of the file is 4, but some sections are 3 or 5 spaces). You can try turning this feature off in Settings > Editor > Code Style > "Detect and use existing file indents for editing"
On Intellij IDEA 14, I have tried to set my preferences in Editor > Code Style > LESS to do 2 space indents but no matter what I do, my code ends up getting formatted with 4 space indents. How do I get it to do 2 space indents for LESS?
If your project has an ".editorconfig" file, IntelliJ 14 uses that by default (which overwrites your settings). If you absolutely do not wish to use these settings, you need to disable the editorconfig plugin.
Not as likely, but if you make a scratch buffer and rename it to filename.ext. It does not honor the code style for *.ext, it defaults to tabs. You have to copy the scratch buffer to a real file and then it will apply the code style for *.ext.