Skip to content

Commit

Permalink
Merge pull request #50 from ErwannLesech/clang_tidy
Browse files Browse the repository at this point in the history
Clang tidy update
  • Loading branch information
ErwannLesech authored Jan 16, 2024
2 parents 097bd32 + 130ec8e commit 2c483e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
43 changes: 37 additions & 6 deletions .github/workflows/clang_tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,31 +18,61 @@ 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)

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 "/$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))

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

# 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"
# echo "---------------------"

done
# echo "Total functions: $function_count"
if [[ "$function_count" -gt 10 ]]; then
echo "Too many functions in file: $file"
echo "Total functions: $function_count"
fi
done

# Check for newline at EOF
test "$(tail -c 1 "$file" | wc -l)" -eq 0 && echo "no newline at EOF in file: $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
2 changes: 1 addition & 1 deletion src/options/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 2c483e7

Please sign in to comment.