Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editorconfig: How to autofix all files in a project [closed]

Tags:

editorconfig

Given I have an .editorconfig file that dictates consistent indent, line endings, trailing whitespace, etc.

# http://editorconfig.org root = true  [*] indent_style = space indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true 

As a Developer, I want to fix all files consistently with a command line tool that understands .editorconfig files. I want to avoid tedious tasks, for instance, manually open and change files.

I imagine if there was a command like for example:

editorconfix.sh --autofix . 

Which tools exist for this purpose? What scripts do you use?

like image 562
Jesper Rønn-Jensen Avatar asked Sep 06 '16 07:09

Jesper Rønn-Jensen


People also ask

Can we override rules in EditorConfig?

editorconfig file doesn't override a particular setting. An example of such a preference is indent style—tabs or spaces. EditorConfig settings are supported by many code editors and IDEs, including Visual Studio.

What is root true in EditorConfig?

Here the root=true specify to the editor that it is the top-most EditorConfig file, any rules specified under this section header- [*] will be applied to all the files including your *. js, *. css, etc. You can have specific rules for specific files for example [*.

Should I commit EditorConfig?

editorconfig to GitHub or not? It depends. If the files are specific to your project, then it is appropriate to commit them. If they are appropriate for your work flow, then it is not.

How does EditorConfig help out?

EditorConfig helps maintain consistent coding styles for multiple developers working on the same project across various editors and IDEs.


1 Answers

There is eclint (and a fork called editorconfig-tools). Run

eclint check 'src/**/*' 

to check all files in the src directory, or

eclint fix 'src/**/*' 

to fix them. But please note that the tool can produce some surprises when it comes to indentation! The author of the tool says in a GitHub comment that he has stopped using the tool himself in favour of language-specific linters:

To me, EditorConfig is all about – would you believe it – configuring your editor and nothing more. I don't think it should be responsible for linting or fixing, as there are language-specific tools to accomplish those goals (e.g., ESLint for JavaScript). The only way you can reliably lint or fix indentation is to be aware of the language in question and EditorConfig is language agnostic.

like image 154
danmichaelo Avatar answered Sep 19 '22 15:09

danmichaelo