30

鉴于我有一个 .editorconfig 文件,该文件指示一致的缩进、行尾、尾随空格等。

# 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

作为一名开发人员,我想使用能够理解 .editorconfig 文件的命令行工具一致地修复所有文件。我想避免繁琐的任务,例如手动打开和更改文件。

我想如果有一个命令,例如:

editorconfix.sh --autofix .

为此目的存在哪些工具?你使用什么脚本?

4

2 回答 2

36

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.

于 2017-01-14T22:42:20.597 回答
2

此外,如果您使用 Gradle、Maven 或 Ant,还有一些工具:

检查文件

./gradlew editorconfigCheck

尝试自动修复它们

./gradlew editorconfigFormat
于 2020-05-07T08:28:44.710 回答