简体   繁体   中英

How to use .editorconfig for code formatting in git pre-commit hook?

In my project there is a requirement to check for code formatting errors. This needs to happen during a git commit. I want to make use of the pre-commit hook but the catch here is the format validation needs to be performed using the rules mentioned in .editorconfig file, which is already present in the project repository.

Please do suggest a way to use .editorcofig in git pre-commit hook.

There appears to be a tool which can check code for conformance to an .editorconfig file. There are probably others; this is just the first one I found in a search.

However, I should point out that the Git FAQ notes that pre-commit hooks can be bypassed trivially with --no-verify without anyone being able to notice. As a result, while they can be helpful for developers who want to use them, they aren't an effective control, and you'll need to use a CI system (or, if possible, a pre-receive hook) on the server side to prevent bypassing them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM