Random indentation for standardized

Asked

Viewed 55 times

2

How to automatically transform indentation of files with random spacing like 1, 2 or 3 spaces to 4 or any other value used?

The idea is to be clearer to those who are developing at the moment.

1 answer

3

I suggest you create a file .editorconfig in the project folder with something like:

# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Estilo unix, usa LF como quebra de linha e adiciona uma linha no vazia no final
[*]
end_of_line = lf
insert_final_newline = true

# charset utf-8 para py e js
[*.{js,py}]
charset = utf-8

# 4 espaços de indentação para py
[*.py]
indent_style = space
indent_size = 4

# Aqui Makefile usará TAB ao invés de espaços
[Makefile]
indent_style = tab

# Se tiver uma pasta chamada lib todos JS usarão 2 espaços para indenção
[lib/**.js]
indent_style = space
indent_size = 2

# arquivos como package.json or .travis.yml usarão 2 espaços
[{package.json,.travis.yml}]
indent_style = space
indent_size = 2

This is just one example of course, it depends on the type of project, more details on how to set up https://editorconfig.org/

After creating the file install the plugin in Vscode:

In the example above the advantage of this is that by chance other people use other editors they will be able to follow the standards you set

Browser other questions tagged

You are not signed in. Login or sign up in order to post.