I prefer 4 spaces because they take up more screen space, which means that I can fit fewer indentation levels before it starts to feel uncomfortable, so in general it means that I start addressing some potential spaghetti code issues earlier.
(although tabs are better because anybody can configure their editor to show as many or as few spaces as they want to, I had to say it)
Auto-formatting causes trouble with source control. You end up having large patch-sets than desired. It can be hard to locate what was actually changed in a file.
@avalander
You can use prettier cli to format the files. Install prettier dependency and add this script in package.json of any javascript/typescript projects
{
"scripts" : {
"format:two": "prettier --tab-width 2 --write \"src//*.ts\" \"test//.ts\",
"format:four": "prettier --tab-width 2 --write \"src//.ts\" \"test/*/.ts\"
}
}
then run:
$ npm run format:two
or
$ yarn run format:two
for more info you can checkout prettier official website
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I prefer 4 spaces because they take up more screen space, which means that I can fit fewer indentation levels before it starts to feel uncomfortable, so in general it means that I start addressing some potential spaghetti code issues earlier.
(although tabs are better because anybody can configure their editor to show as many or as few spaces as they want to, I had to say it)
The argument about "how many spaces" is really an argument in favour of tabs.
It goes beyond how many as well, since the moment you use spaces, you start having people align code with them as well. :/
vs code can auto format an entire file to use the number of spaces one desires, and always uses spaces
Yeah but at my work we use two spaces, can I configure vscode to display four spaces but actually save the file with two?
not that I'm aware of. you'd just have to change it before you commit
Auto-formatting causes trouble with source control. You end up having large patch-sets than desired. It can be hard to locate what was actually changed in a file.
@avalander
You can use prettier cli to format the files. Install prettier dependency and add this script in package.json of any javascript/typescript projects
{
"scripts" : {
"format:two": "prettier --tab-width 2 --write \"src//*.ts\" \"test//.ts\",
"format:four": "prettier --tab-width 2 --write \"src//.ts\" \"test/*/.ts\"
}
}
then run:
$ npm run format:two
or
$ yarn run format:two
for more info you can checkout prettier official website