cheapvs_llm / scripts /fix_code.sh
sangttruong's picture
add data
27dc10f
#!/bin/bash
# Check if a folder or file name is provided
if [ -z "$1" ]; then
echo "Usage: $0 <folder_or_file>"
exit 1
fi
TARGET=$1
# Validate if the folder or file exists
if [ ! -e "$TARGET" ]; then
echo "Error: '$TARGET' does not exist."
exit 1
fi
# Function to process Python files
process_file_or_folder() {
local ITEM=$1
if [ -d "$ITEM" ]; then
echo "Processing folder: $ITEM"
echo "Fixing import order with isort..."
isort "$ITEM"
echo "Running Ruff to auto-fix Pylint issues..."
ruff check "$ITEM" --fix
echo "Modernizing Python syntax with Pyupgrade..."
find "$ITEM" -name "*.py" -exec pyupgrade --py38-plus {} \;
echo "Formatting code with Black..."
black "$ITEM"
elif [ -f "$ITEM" ]; then
echo "Processing file: $ITEM"
echo "Fixing import order with isort..."
isort "$ITEM"
echo "Running Ruff to auto-fix Pylint issues..."
ruff check "$ITEM" --fix
echo "Modernizing Python syntax with Pyupgrade..."
pyupgrade --py38-plus "$ITEM"
echo "Formatting code with Black..."
black "$ITEM"
else
echo "Error: '$ITEM' is not a valid file or folder."
exit 1
fi
}
# Call the function
process_file_or_folder "$TARGET"
echo "Fixes completed for: $TARGET"