Add pre-commit hooks to fix common formatting issues causing CI failures - #9494
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds automation and consistency for end-of-file newline handling by integrating a pre-commit hook and normalizing newline output in tooling.
- Introduce
end-of-file-fixerhook and exclude certain files fromyamllint - Update
script/clang_tidy_hash.pyto strip and enforce a single trailing newline when writing the hash - Remove stray trailing blank lines/dashes across numerous YAML fixtures and CI config
Reviewed Changes
8000Copilot reviewed 33 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/integration/fixtures/*.yaml | Removed extra trailing - lines to enforce single newline policy |
| tests/components/**/*.yaml/.gitattributes | Cleared stray trailing - or blank lines per hook requirement |
| script/clang_tidy_hash.py | Strip and append exactly one newline when writing .clang-tidy.hash |
| .pre-commit-config.yaml | Bump pre-commit-hooks rev, add end-of-file-fixer, exclude lint |
| .github/workflows/ci-clang-tidy-hash.yml | Remove extra trailing blank line |
Comments suppressed due to low confidence (2)
script/clang_tidy_hash.py:126
- Update the docstring to reflect that write_hash now normalizes trailing newlines (strips extras and enforces exactly one).
def write_hash(hash_value: str) -> None:
script/clang_tidy_hash.py:130
- [nitpick] Consider adding a unit test for write_hash to verify it always writes exactly one newline, preventing future regressions.
write_file_content(hash_file, hash_value.strip() + "\n")
|
We can also remove the separate yamllint job after this as pre-commit run --all-files passes now That will save even more ci time |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #9494 +/- ##
==========================================
+ Coverage 59.67% 59.70% +0.02%
==========================================
Files 50 50
Lines 10268 10268
Branches 1379 1379
==========================================
+ Hits 6127 6130 +3
+ Misses 3782 3780 -2
+ Partials 359 358 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Thanks. This one was particularly annoying to fix to fix manually. |
What does this implement/fix?
This PR adds the
end-of-file-fixerandtrailing-whitespacepre-commit hooks to automatically fix common formatting issues that frequently cause CI failures. These simple additions will prevent numerous CI failures and save significant time and resources that are currently wasted on fixing these issues manually.The hooks automatically fix:
This standardization helps maintain consistent file formatting across the codebase and eliminates common sources of CI failures.
Types of changes
Related issue or feature (if applicable): N/A
Pull request in esphome-docs with documentation (if applicable): N/A
Test Environment
Example entry for
config.yaml:# N/A - This is a development tooling changeChecklist:
tests/folder).If user exposed functionality or configuration variables are added/changed:
Additional changes:
end-of-file-fixerandtrailing-whitespacehooks to.pre-commit-config.yamlscript/clang_tidy_hash.pyto ensure consistent newline handling when writing the hash file.clang-tidyand.clang-formatfiles from yamllint since they use special formattingBenefits: