From 9593aedffb8599695a5bf5188f30d791a4bdd64e Mon Sep 17 00:00:00 2001 From: erwann lesech Date: Mon, 15 Jan 2024 00:25:18 +0100 Subject: [PATCH 1/5] fix: improve prototype precision --- .github/workflows/clang_tidy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/clang_tidy.sh b/.github/workflows/clang_tidy.sh index cebb7456..c5e9aa73 100755 --- a/.github/workflows/clang_tidy.sh +++ b/.github/workflows/clang_tidy.sh @@ -19,7 +19,7 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do parameters=$(echo "$line" | sed 's/^[^(]*(//;s/)[^{]*$//;s/,/\n/g' | wc -l) # Count the number of lines in the function (excluding blank and '{', '}' lines) - lines_in_function=$(sed -n "/$function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l) + lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l) lines_in_function=$((lines_in_function-1)) lines_in_function=$((lines_in_function-1)) if [[ "$parameters" -gt 4 ]]; then From 396bfeb7f6665ac281565eaa8d935e541131ec99 Mon Sep 17 00:00:00 2001 From: erwann lesech Date: Mon, 15 Jan 2024 22:45:53 +0100 Subject: [PATCH 2/5] fix: improve precision and fix pointer function This commit should improve the clang_tidy script to accept pointer return type functions --- .github/workflows/clang_tidy.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/workflows/clang_tidy.sh b/.github/workflows/clang_tidy.sh index c5e9aa73..b8342cb7 100755 --- a/.github/workflows/clang_tidy.sh +++ b/.github/workflows/clang_tidy.sh @@ -17,20 +17,26 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do function_name=$(echo "$line" | awk '{print $3}' | sed 's/([^)]*)//g') fi parameters=$(echo "$line" | sed 's/^[^(]*(//;s/)[^{]*$//;s/,/\n/g' | wc -l) - + + if [[ "${function_name:0:1}" == "*" ]]; then + function_name="\\$function_name" + else + function_name="$function_name" + fi + # Count the number of lines in the function (excluding blank and '{', '}' lines) - lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l) lines_in_function=$((lines_in_function-1)) + lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l) lines_in_function=$((lines_in_function-1)) if [[ "$parameters" -gt 4 ]]; then - echo "Too many parameters in function: $function_name" + echo "Too many parameters in function: $return_type $function_name" fi if [[ "$lines_in_function" -gt 40 ]]; then - echo "Too many lines in function: $function_name" + echo "Too many lines in function: $return_type $function_name" fi - # echo "Function: $function_name" + # echo "Function: $return_type $function_name" # echo "Return type: $return_type" # echo "Parameters: $parameters" # echo "Lines in function: $lines_in_function" From d9c6b6524ee04c4a8a86609b05399ff5ed888d75 Mon Sep 17 00:00:00 2001 From: erwann lesech Date: Mon, 15 Jan 2024 22:51:52 +0100 Subject: [PATCH 3/5] feat: add check newline at EOF --- .github/workflows/clang_tidy.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang_tidy.sh b/.github/workflows/clang_tidy.sh index b8342cb7..de105c4c 100755 --- a/.github/workflows/clang_tidy.sh +++ b/.github/workflows/clang_tidy.sh @@ -41,10 +41,13 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do # echo "Parameters: $parameters" # echo "Lines in function: $lines_in_function" # echo "---------------------" - + done # echo "Total functions: $function_count" if [[ "$function_count" -gt 10 ]]; then echo "Too many functions in file: $file" fi + + # Check for newline at EOF + test "$(tail -c 1 "$file" | wc -l)" -eq 0 && echo "no newline at EOF in file: $file" done \ No newline at end of file From 7f34aca9f0b09c500765773889f9a76a70433ec8 Mon Sep 17 00:00:00 2001 From: erwann lesech Date: Mon, 15 Jan 2024 23:28:44 +0100 Subject: [PATCH 4/5] feat: add headers rule top and bottom --- .github/workflows/clang_tidy.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/.github/workflows/clang_tidy.sh b/.github/workflows/clang_tidy.sh index de105c4c..de8df8a6 100755 --- a/.github/workflows/clang_tidy.sh +++ b/.github/workflows/clang_tidy.sh @@ -2,6 +2,7 @@ root_dir=$(git rev-parse --show-toplevel) +# C files check for file in $(find "$root_dir/src" -type f -name '*.c'); do function_count=$(grep -E '^(bool|int|char|double|void|float|struct [a-zA-Z][a-zA-Z_]*|unsigned|long)[[:space:]]+[*]*[a-zA-Z_][a-zA-Z0-9_]*[[:space:]]*\([^)]*\)[[:space:]]*' "$file" | wc -l) # echo "Processing file: $file" @@ -50,4 +51,22 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do # Check for newline at EOF test "$(tail -c 1 "$file" | wc -l)" -eq 0 && echo "no newline at EOF in file: $file" -done \ No newline at end of file +done + +# Header files check +for header_file in $(find "$root_dir/src" -type f -name '*.h'); do + # Get the header name without the path and extension + header_name=$(basename "$header_file" .h) + + #put the header name in uppercase + header_name=$(echo "$header_name" | tr '[:lower:]' '[:upper:]') + header_name="${header_name}_H" + + # Check if the header file begins and ends correctly + if ! grep -qE "#ifndef[[:space:]]*$header_name" "$header_file" || ! grep -qE "#define[[:space:]]*$header_name[[:space:]]*$" "$header_file" || ! grep -qE "#endif[[:space:]]*/\*.*$header_name.*\*/" "$header_file"; then + echo "Header file $header_file is not correctly formatted." + tail -n +9 "$header_file" | head -n 3 + tail -n 1 "$header_file" + fi + +done From 130ec8ea786c4259003121fb49a0fe1842a763cd Mon Sep 17 00:00:00 2001 From: erwann lesech Date: Mon, 15 Jan 2024 23:34:57 +0100 Subject: [PATCH 5/5] fix: fix interface name function --- .github/workflows/clang_tidy.sh | 7 +++++-- src/options/options.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/clang_tidy.sh b/.github/workflows/clang_tidy.sh index caf44931..52302a8a 100755 --- a/.github/workflows/clang_tidy.sh +++ b/.github/workflows/clang_tidy.sh @@ -19,23 +19,26 @@ for file in $(find "$root_dir/src" -type f -name '*.c'); do fi parameters=$(echo "$line" | sed 's/^[^(]*(//;s/)[^{]*$//;s/,/\n/g' | wc -l) + cpy_function_name="$function_name" + if [[ "${function_name:0:1}" == "*" ]]; then function_name="\\$function_name" else function_name="$function_name" fi + # Count the number of lines in the function (excluding blank and '{', '}' lines) lines_in_function=$(sed -n "/$return_type $function_name/,/^}/p" "$file" | sed '/^$/d' | sed '/^[[:space:]]*{$/d' | sed '/^[[:space:]]*}$/d' | wc -l) lines_in_function=$((lines_in_function-1)) if [[ "$parameters" -gt 4 ]]; then - echo "Too many parameters in function: $function_name" + echo "Too many parameters in function: $return_type $cpy_function_name" echo "Parameters: $parameters" fi if [[ "$lines_in_function" -gt 40 ]]; then - echo "Too many lines in function: $function_name" + echo "Too many lines in function: $return_type $cpy_function_name" echo "Lines in function: $lines_in_function" fi diff --git a/src/options/options.c b/src/options/options.c index 127ebb6c..b84bda67 100644 --- a/src/options/options.c +++ b/src/options/options.c @@ -211,4 +211,4 @@ void pretty_print(struct ast_node *ast, bool pretty_print_enabled, int *number) if (write(fd, "}\n", 3) == -1) return; close(fd); -} \ No newline at end of file +}