Editorconfig:如何自动修复项目中的所有文件
Editorconfig: How to autofix all files in a project
鉴于我有一个 .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 .
有哪些工具可用于此目的?你使用什么脚本?
有eclint (and a fork called editorconfig-tools)。 运行
eclint check 'src/**/*'
检查src
目录中的所有文件,或
eclint fix 'src/**/*'
修复它们。但请注意,该工具在缩进时会产生一些惊喜!该工具 says in a GitHub comment 的作者表示他自己已停止使用该工具,转而使用 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.
此外,如果您使用 Gradle,Maven 或 Ant 有以下工具:
检查文件
./gradlew editorconfigCheck
尝试自动修复它们
./gradlew editorconfigFormat
鉴于我有一个 .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 .
有哪些工具可用于此目的?你使用什么脚本?
有eclint (and a fork called editorconfig-tools)。 运行
eclint check 'src/**/*'
检查src
目录中的所有文件,或
eclint fix 'src/**/*'
修复它们。但请注意,该工具在缩进时会产生一些惊喜!该工具 says in a GitHub comment 的作者表示他自己已停止使用该工具,转而使用 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.
此外,如果您使用 Gradle,Maven 或 Ant 有以下工具:
检查文件
./gradlew editorconfigCheck
尝试自动修复它们
./gradlew editorconfigFormat