HASKI-RAK / HASKI-Backend

This is the Backend System for our HASKI project.
GNU Lesser General Public License v2.1
4 stars 1 forks source link

Linting extended #51

Closed theUpsider closed 1 year ago

theUpsider commented 1 year ago

Describe the feature to be developed

This feature aims to enhance project configuration and setup, streamline development, improve code quality checks, and simplify setup for developers.

Describe the Impact on the System

The changes primarily affect the project's setup and configuration files, as well as some scripts related to database setup and cleanup. The most significant impact will be on the following areas:

Definition of Done

Before this pull request can be considered complete, the following tasks need to be accomplished:

theUpsider commented 1 year ago

Also made a git hook for pre-commit:

#!/bin/sh
# This is a git pre-commit hook to run isort, black, and flake8 on staged files
# Set venv_dir variable based on OS
case "$OSTYPE" in
  msys*) venv_dir="./venv_hooks/Scripts" ;;
  *)     venv_dir="./venv_hooks/bin" ;;
esac

# Install virtualenv if not already installed and create virtualenv if not already created
if [ ! -d "./venv_hooks" ]; then
    echo "Creating virtualenv"
    python -m venv venv_hooks
    $venv_dir/python -m pip install -r requirements.txt
fi
echo "Activating virtualenv"
source $venv_dir/activate
# Get list of staged python files
files="$(git diff --name-only --cached | grep '.*\.py$' | paste -sd ' ' -)"
if [ "$files" == "" ]; then
    echo "No files to reformat, skipping"
    exit 0
fi
# isort
echo "Running isort on staged files"
isort $files --settings-file=./pyproject.toml
if [ $? -ne 0 ]; then
    echo "isort failed, please run isort on your code"
    exit 1
fi
# black
# check if black config exists
if [ -f ./pyproject.toml ]; then
    echo "Found black config"
else
    echo "No black config found, skipping"
    exit 0
fi
echo "Running black on staged files"
black $files --config=pyproject.toml
if [ $? -ne 0 ]; then
    echo "Black check failed, please run black on your code"
    exit 1
fi

# flake8
echo "Running flake8 on staged files"
flake8 $files
if [ $? -ne 0 ]; then
    echo "flake8 failed, please run flake8 on your code"
    exit 1
fi

# # Add files to commit
# echo "Adding files to commit"
# git add $files

This would be placed in .git\hooks\pre-commit to work.

sonarcloud[bot] commented 1 year ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

93.5% 93.5% Coverage
1.7% 1.7% Duplication