File size: 1,265 Bytes
27dc10f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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"