mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-10-29 03:44:39 +08:00
fix: lint and update workflow related items
This commit is contained in:
2
.github/workflows/awesome_workflow.yml
vendored
2
.github/workflows/awesome_workflow.yml
vendored
@@ -9,7 +9,7 @@ jobs:
|
|||||||
name: Code Formatter
|
name: Code Formatter
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v7
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: actions/setup-python@v4
|
- uses: actions/setup-python@v4
|
||||||
|
|||||||
61
filename_formatter.sh
Normal file
61
filename_formatter.sh
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo -e "Arguments:
|
||||||
|
[0] - Used by Bash (script filename)
|
||||||
|
[1] - Base directory
|
||||||
|
[2] - Filename type (maximum two values)
|
||||||
|
[3] - Ignored files or folders (optional; use "\""./<directory_name>"\"")
|
||||||
|
"
|
||||||
|
|
||||||
|
# Separate $2 value (filename types) if it has a comma
|
||||||
|
if [[ "$2" == *","* ]];
|
||||||
|
then
|
||||||
|
string="$2"
|
||||||
|
|
||||||
|
str_value=${string#*,}
|
||||||
|
str_value2=${string%%,*}
|
||||||
|
else
|
||||||
|
str_value="$2"
|
||||||
|
str_value2="$2"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Do not run script if there are no given arguments.
|
||||||
|
if [[ "$1" == "" ]] || [[ "$2" == "" ]];
|
||||||
|
then
|
||||||
|
echo "No arguments given. Please specify minimum two arguments."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Changed files:"
|
||||||
|
|
||||||
|
IFS=$'\n'; set -f
|
||||||
|
for fname in $(find $1 -type f -name "*$str_value2" -or -name "*$str_value")
|
||||||
|
do
|
||||||
|
ignored_files="$(echo "$3" | tr "," "\n")"
|
||||||
|
|
||||||
|
str="${fname}"
|
||||||
|
value=${str%/*} # If the base directory is `.`, check in all directories for the ignored filenames
|
||||||
|
|
||||||
|
for files in $ignored_files
|
||||||
|
do
|
||||||
|
echo ${fname}
|
||||||
|
if [ "${fname}" == "$value/$files" ] || [ "$value" == "$files" ];
|
||||||
|
then
|
||||||
|
continue 2
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
#echo ${fname}
|
||||||
|
new_fname=$(echo "${fname}" | tr ' ' '_')
|
||||||
|
#echo " ${new_fname}"
|
||||||
|
new_fname=$(echo "${new_fname}" | tr '[:upper:]' '[:lower:]')
|
||||||
|
#echo " ${new_fname}"
|
||||||
|
new_fname=$(echo "${new_fname}" | tr '-' '_')
|
||||||
|
#echo " ${new_fname}"
|
||||||
|
if [ "${fname}" != "${new_fname}" ]
|
||||||
|
then
|
||||||
|
echo " ${fname} --> ${new_fname}"
|
||||||
|
git "mv" "${fname}" "${new_fname}" # Requires you to be in version control
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
unset IFS; set +f
|
||||||
@@ -5,15 +5,28 @@ import sys
|
|||||||
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
|
print("Python {}.{}.{}".format(*sys.version_info)) # Python 3.8
|
||||||
with open("git_diff.txt") as in_file:
|
with open("git_diff.txt") as in_file:
|
||||||
modified_files = sorted(in_file.read().splitlines())
|
modified_files = sorted(in_file.read().splitlines())
|
||||||
print("{} files were modified.".format(len(modified_files)))
|
print(f"{len(modified_files)} files were modified.")
|
||||||
|
|
||||||
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
|
cpp_exts = (
|
||||||
|
".c",
|
||||||
|
".c++",
|
||||||
|
".cc",
|
||||||
|
".cpp",
|
||||||
|
".cu",
|
||||||
|
".cuh",
|
||||||
|
".cxx",
|
||||||
|
".h",
|
||||||
|
".h++",
|
||||||
|
".hh",
|
||||||
|
".hpp",
|
||||||
|
".hxx",
|
||||||
|
)
|
||||||
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
|
cpp_files = [file for file in modified_files if file.lower().endswith(cpp_exts)]
|
||||||
print(f"{len(cpp_files)} C++ files were modified.")
|
print(f"{len(cpp_files)} C++ files were modified.")
|
||||||
if not cpp_files:
|
if not cpp_files:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
subprocess.run(
|
_ = subprocess.run(
|
||||||
[
|
[
|
||||||
"clang-tidy",
|
"clang-tidy",
|
||||||
"--fix",
|
"--fix",
|
||||||
@@ -26,7 +39,7 @@ with open("git_diff.txt") as in_file:
|
|||||||
text=True,
|
text=True,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
_ = subprocess.run(
|
||||||
["clang-format", "-i", "-style=file", *cpp_files],
|
["clang-format", "-i", "-style=file", *cpp_files],
|
||||||
check=True,
|
check=True,
|
||||||
text=True,
|
text=True,
|
||||||
|
|||||||
Reference in New Issue
Block a user