Elyes Haouas has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/82712?usp=email )
Change subject: util/lint: Add lint rule to warn if <stdint.h> is included but not used ......................................................................
util/lint: Add lint rule to warn if <stdint.h> is included but not used
Change-Id: I318189f88c4ee8803075efc4fe2cb9b58547c126 Signed-off-by: Elyes Haouas ehaouas@noos.fr --- A util/lint/lint-stable-034-stdint-h 1 file changed, 41 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/12/82712/1
diff --git a/util/lint/lint-stable-034-stdint-h b/util/lint/lint-stable-034-stdint-h new file mode 100755 index 0000000..61ca04d --- /dev/null +++ b/util/lint/lint-stable-034-stdint-h @@ -0,0 +1,41 @@ +#!/usr/bin/env sh +# SPDX-License-Identifier: GPL-2.0-or-later +# +# DESCR: Verify if <stdint.h> is needed in modified files +# + +# Get the list of modified files +MODIFIED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '.c$|.h$') +if [ -z "$MODIFIED_FILES" ]; then + exit 0 +fi + +# Create temporary files to hold the lists +TMP_INCLUDE=$(mktemp) +TMP_TYPES=$(mktemp) + +# Find files including <stdint.h> +for file in $MODIFIED_FILES; do + if grep -q '#include <stdint.h>' "$file"; then + echo "$file" >> "$TMP_INCLUDE" + fi +done + +# Find files using stdint.h types +for file in $MODIFIED_FILES; do + if grep -q '\bint8_t\b|int16_t\b|int32_t\b|int64_t\b|uint8_t\b|uint16_t\b|uint32_t\b|uint64_t\b|intptr_t\b|uintptr_t\b' "$file"; then + echo "$file" >> "$TMP_TYPES" + fi +done + +# Compare the two lists to find unnecessary includes +UNNEEDED_INCLUDE=$(comm -23 <(sort "$TMP_INCLUDE") <(sort "$TMP_TYPES")) + +# Output warnings for unneeded includes +if [ -n "$UNNEEDED_INCLUDE" ]; then + echo "Warning: The following files include <stdint.h> but do not use its types:" + echo "$UNNEEDED_INCLUDE" +fi + +# Clean up temporary files +rm -f "$TMP_INCLUDE" "$TMP_TYPES"