Add pre-commit hooks to fix common formatting issues causing CI failures (#9494)

This commit is contained in:
J. Nick Koston 2025-07-14 14:25:18 -10:00 committed by GitHub
parent 619e2d69c0
commit b2a8b0a22f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
38 changed files with 12 additions and 39 deletions

View File

@ -1 +1 @@
a3cdfc378d28b53b416a1d5bf0ab9077ee18867f0d39436ea8013cf5a4ead87a
a3cdfc378d28b53b416a1d5bf0ab9077ee18867f0d39436ea8013cf5a4ead87a

View File

@ -1,4 +1,4 @@
[run]
omit =
omit =
esphome/components/*
tests/integration/*

View File

@ -73,4 +73,3 @@ jobs:
});
}
}

View File

@ -27,13 +27,15 @@ repos:
- pydocstyle==5.1.1
files: ^(esphome|tests)/.+\.py$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
rev: v5.0.0
hooks:
- id: no-commit-to-branch
args:
- --branch=dev
- --branch=release
- --branch=beta
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/asottile/pyupgrade
rev: v3.20.0
hooks:
@ -43,6 +45,7 @@ repos:
rev: v1.37.1
hooks:
- id: yamllint
exclude: ^(\.clang-format|\.clang-tidy)$
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
hooks:

View File

@ -126,7 +126,8 @@ def write_file_content(path: Path, content: str) -> None:
def write_hash(hash_value: str) -> None:
"""Write hash to file"""
hash_file = Path(__file__).parent.parent / ".clang-tidy.hash"
write_file_content(hash_file, hash_value)
# Strip any trailing newlines to ensure consistent formatting
write_file_content(hash_file, hash_value.strip() + "\n")
def main() -> None:

View File

@ -72,7 +72,7 @@ for f in ./tests/components/$target_component/*.*.yaml; do
if [ "$target_platform" = "all" ] || [ $file_name_parts = 2 ]; then
# Test has *not* defined a specific target platform. Need to run tests for all possible target platforms.
for target_platform_file in ./tests/test_build_components/build_components_base.*.yaml; do
IFS='/' read -r -a folder_name <<< "$target_platform_file"
IFS='.' read -r -a file_name <<< "${folder_name[3]}"
@ -83,7 +83,7 @@ for f in ./tests/components/$target_component/*.*.yaml; do
else
# Test has defined a specific target platform.
# Validate we have a base test yaml for selected platform.
# The target_platform is sourced from the following location.
# 1. `./tests/test_build_components/build_components_base.[target_platform].yaml`

View File

@ -1,4 +1,3 @@
*.apng -text
*.webp -text
*.gif -text

View File

@ -15,4 +15,3 @@ display:
packages:
animation: !include common.yaml

View File

@ -21,4 +21,3 @@ binary_sensor:
- platform: ble_presence
irk: 1234567890abcdef1234567890abcdef
name: "ESP32 BLE Tracker with Identity Resolving Key"

View File

@ -17,4 +17,3 @@ color:
hex: 008000
- id: cps_blue
hex: 000080

View File

@ -41,4 +41,3 @@ display:
- delay 120ms
- [0x29]
- delay 20ms

View File

@ -42,4 +42,3 @@ binary_sensor:
x_max: 480
y_min: 320
y_max: 360

View File

@ -15,4 +15,3 @@ sensor:
name: "Loop Time"
cpu_frequency:
name: "CPU Frequency"

View File

@ -14,4 +14,3 @@ sensor:
name: "ENS160 Total Volatile Organic Compounds"
aqi:
name: "ENS160 Air Quality Index"

View File

@ -9,4 +9,3 @@ esp32:
wifi:
ssid: MySSID
password: password1

View File

@ -1,2 +1 @@
<<: !include common.yaml

View File

@ -1,2 +1 @@
<<: !include common.yaml

View File

@ -1,2 +1 @@
*.pcf -text

View File

@ -1,2 +1 @@
*.ttf -text

View File

@ -56,4 +56,3 @@ lvgl:
packages:
lvgl: !include lvgl-package.yaml
xvgl: !include common.yaml

View File

@ -3,4 +3,3 @@ substitutions:
scl_pin: GPIO22
<<: !include common.yaml

View File

@ -35,4 +35,3 @@ display:
allow_other_uses: true
- number: ${enable_pin}
bus_mode: single

View File

@ -4,4 +4,3 @@ substitutions:
packages:
base: !include common.yaml

View File

@ -1,4 +1,3 @@
<<: !include common-esp32.yaml
http_request:

View File

@ -11,4 +11,3 @@ openthread:
pskc: 0xc23a76e98f1a6483639b1ac1271e2e27
mesh_local_prefix: fd53:145f:ed22:ad81::/64
force_dataset: true

View File

@ -9,4 +9,3 @@ packages:
file: common.yaml
ref: dev
refresh: 1d

View File

@ -11,4 +11,3 @@ packages:
file: common.yaml
ref: dev
refresh: 1d

View File

@ -41,4 +41,3 @@ display:
- delay 120ms
- [0x29]
- delay 20ms

View File

@ -35,4 +35,3 @@ spi:
interface: any
clk_pin: 8
mosi_pin: 9

View File

@ -35,4 +35,3 @@ spi:
interface: any
clk_pin: 8
mosi_pin: 9

View File

@ -17,4 +17,3 @@ udp:
id: my_udp
data: !lambda |-
return std::vector<uint8_t>{1,3,4,5,6};

View File

@ -27,4 +27,3 @@ logger:
logs:
web_server: VERBOSE
web_server_idf: VERBOSE

View File

@ -3,4 +3,3 @@ substitutions:
sda_pin: GPIO21
<<: !include common.yaml

View File

@ -54,4 +54,3 @@ sensor:
device_id: smart_switch_device
lambda: return 4.0;
update_interval: 0.1s

View File

@ -82,4 +82,3 @@ output:
write_action:
- lambda: |-
ESP_LOGD("test", "Light output: %d", state);

View File

@ -134,4 +134,3 @@ switch:
name: "Test Switch"
id: test_switch
optimistic: true

View File

@ -158,7 +158,7 @@ def test_write_hash() -> None:
mock_write.assert_called_once()
args = mock_write.call_args[0]
assert str(args[0]).endswith(".clang-tidy.hash")
assert args[1] == hash_value
assert args[1] == hash_value.strip() + "\n"
@pytest.mark.parametrize(

View File

@ -1 +1 @@
*.received.yaml
*.received.yaml