C
C
CaptainJustness2020-06-10 17:56:41
phpstorm
CaptainJustness, 2020-06-10 17:56:41

Once and for all: JavaScript indent 2 or 4 spaces?

Hello.

I am using PhpStorm IDE. By default in the settings, JS has 4 indents. In all projects, I indented 4 spaces. But then I connected NodeJS to the IDE, earned ESlint and began to complain that I needed to fix it by 2 spaces. Now I'm confused.. 2 or 4. Started googling, found a google style code, it is recommended to use 2 spaces in it. So what's the bottom line? One giant recommends 4 others 2. How to be? Change settings for JS to 2 spaces? In this case PHP will have 4 spaces and JS 2. Isn't that sloppy? I will definitely not do 2 spaces for PHP, this is a bad thing. In general, this topic torments me, as it is right, and why one giant says one thing to another another .. Whom to trust and why? Write as you like and don't do it)) I'll get used to it. But you need to get used to the really right decision.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
DevMan, 2020-06-10
@CaptainJustness

once and for all it won’t work at all: someone likes two spaces, someone likes four, and someone likes tabs.
I prefer four space tabs. and this does not prevent me from working with people who have other preferences.

R
Robur, 2020-06-10
@Robur

the choice between 2 or 4 spaces is obvious - tabs.

L
LoveCode &Coffe, 2020-06-10
@LoveCode &Coffe

Once and for all: Should I put a semicolon or not?
a) Bet;
b) Do not put
the correct answer c) Do as you like. And prettier will do the right thing.
It seems like he will also make the indents what he needs. You just need to tweak the config

M
Mikhail Osher, 2020-06-10
@miraage

In recent years, JS, most often, makes 2 spaces.
In PHP, everything is written in PSR - 4 spaces.
To make it easier to write, and not bother, you can sketch some .editorconfig at the root of the project.
In general, I consider it evil to mix front and back projects.

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.js,*.jsx]
indent_size = 2

D
Dima Polos, 2020-06-10
@dimovich85

Check with the person who gives the money)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question