When working on Javascript/Typescript projects probably most of us know the following;
eslint is used to avoid code errors
prettier is used to format you text
These are tools that you need to add. But the most elemental code formatting is not here, it is in the widely supported .editorconfig file.
You can generate such a file with this command:
It is basically an ini file
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
quote_type = single
The best thing is that your code editor or IDE will recognise this file automatically and formats your code per this .editorconfig file by default, or there is a plugin.
Visual Studio Code (VSC) uses a plugin
Vim uses a plugin
Nvim supports this by default
IntelliJ IDEA uses a plugin
Sublime uses a plugin
Atom uses a plugin
And if you want to include these rules in linting locally or in the pipeline, even prettier supports it!
Happy coding!