Skip to content

Commit

Permalink
Merge branch 'master' into feature/add-wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
gkapfham committed Jul 20, 2019
2 parents a944fbd + dffd7c4 commit 1fe1f91
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 43 deletions.
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ mutmut = "*"
bandit = "*"
codacy-coverage = "*"
pydocstyle = "*"
radon = "*"
xenon = "*"

[pipenv]
allow_prereleases = true
Expand Down
103 changes: 66 additions & 37 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions scripts/lint.bat
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,35 @@ if ERRORLEVEL 1 (
echo -- Passed
)

echo -- Running bandit
pipenv run bandit -c bandit.yml %FILES%
echo -- Running pydocstyle
pipenv run pydocstyle %FILES%
if ERRORLEVEL 1 (
echo -- Failed
set PASSED=false
) else (
echo -- Passed
)

echo -- Running pydocstyle
pipenv run pydocstyle %FILES%
echo -- Running radon cc
pipenv run radon cc %FILES%
if ERRORLEVEL 1 (
echo -- Failed
set PASSED=false
) else (
echo -- Passed
)

echo -- Running radon mi
pipenv run radon cc %FILES%
if ERRORLEVEL 1 (
echo -- Failed
set PASSED=false
) else (
echo -- Passed
)

echo -- Running xenon
pipenv run xenon --max-absolute D --max-modules B --max-average A gator
if ERRORLEVEL 1 (
echo -- Failed
set PASSED=false
Expand Down
29 changes: 27 additions & 2 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
#!/bin/bash

# determine whether or not black code formatting
# will fail if code is not correctly formatted
# "--check" returns non-zero exit code if formatting needed
# otherwise, the black check is run for diagnostic purposes
if [[ "$1" == "--check" ]]; then
CHECK="--check"
else
CHECK=""
fi

# assume that all of the linters passed and prove otherwise
PASSED=true

OS="$(uname)"

# collect the files on MacOS
if [[ "$OS" == "Darwin" ]]; then
FILES=$(find -E . -type f -regex '\./(gator|tests)/.*.py')
else
FILES=$(find . -type f -regextype posix-extended -regex '\./(gator|tests)/.*.py')
fi

# lint all of the Python source code files
FILES="$FILES *.py"

declare -A LINTERS
# xenon cannot accept a lists of files or directories,
# so give the directory of the main module instead
MODULE="gator"

# Notes about the linters run on Linux and MacOS:
# - black checks and fixes Python code formatting
# - pylint and flake8 check Python code
# - bandit finds security problems in Python code
# - radon checks code quality for diagnostic purposes
# --> cc is for calculating cyclomatic complexity
# --> mi is for calculating maintainability index
# - xenon returns an error code for code quality thresholds
# --> absolute: worst tolerable score for a function or block
# --> modules: worst tolerable score for a module
# --> average: worst tolerable average score across a module

LINTERS=( ["black"]="pipenv run black $CHECK $FILES" ["pylint"]="pipenv run pylint $FILES" ["flake8"]="pipenv run flake8 $FILES" ["bandit"]="pipenv run bandit -c bandit.yml $FILES" ["pydocstyle"]="pipenv run pydocstyle $FILES" )
# define all of the linters to iteratively run
declare -A LINTERS
LINTERS=( ["black"]="pipenv run black $CHECK $FILES" ["pylint"]="pipenv run pylint $FILES" ["flake8"]="pipenv run flake8 $FILES" ["bandit"]="pipenv run bandit -c bandit.yml $FILES" ["radon-cc"]="pipenv run radon cc $FILES" ["radon-mi"]="pipenv run radon mi $FILES" ["xenon"]="pipenv run xenon --max-absolute D --max-modules B --max-average A $MODULE" ["pydocstyle"]="pipenv run pydocstyle $FILES" )

# run each of the already configured linters
for tool in "${!LINTERS[@]}"; do
echo " -- Running $tool"
# shellcheck disable=SC2086
Expand All @@ -34,6 +58,7 @@ for tool in "${!LINTERS[@]}"; do
echo ""
done

# display the final diagnostic information
if [[ "$PASSED" != "true" ]]; then
echo "Not all linters passed!"
exit 1
Expand Down

0 comments on commit 1fe1f91

Please sign in to comment.