-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add make format
command
#568
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ffb54b7
Add `make format` command
leplatrem f30ebd5
Remove bash option
leplatrem 412a0fc
Restore variables
leplatrem 37403e5
Update secrets baseline
leplatrem e7a76dd
Remove yamllint from help
leplatrem af57006
Remove safety check for Git and detect-secrets
leplatrem File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,81 @@ | ||
#!/bin/bash | ||
#!/bin/sh | ||
|
||
set -euo pipefail | ||
set -e | ||
|
||
POETRY_RUN="poetry run" | ||
|
||
CURRENT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) | ||
BASE_DIR="$(dirname "$CURRENT_DIR")" | ||
HAS_GIT="$(command -v git || echo '')" | ||
echo $HAS_GIT | ||
|
||
$POETRY_RUN bandit -lll --recursive "${BASE_DIR}" --exclude "${BASE_DIR}/poetry.lock,${BASE_DIR}/.venv,${BASE_DIR}/.mypy,${BASE_DIR}/build" | ||
bandit () { | ||
$POETRY_RUN bandit -lll --recursive "${BASE_DIR}" --exclude "${BASE_DIR}/poetry.lock,${BASE_DIR}/.venv,${BASE_DIR}/.mypy,${BASE_DIR}/build" | ||
} | ||
black () { | ||
$POETRY_RUN black ${check:+--check} "${BASE_DIR}" | ||
} | ||
detect_secrets () { | ||
# Scan only files fixed into the repo, omit poetry.lock | ||
FILES_TO_SCAN=`git ls-tree --full-tree -r --name-only HEAD | grep -v poetry.lock` | ||
$POETRY_RUN detect-secrets-hook $FILES_TO_SCAN --baseline .secrets.baseline | ||
} | ||
isort () { | ||
$POETRY_RUN isort ${check:+--check-only} "${BASE_DIR}" | ||
} | ||
pylint () { | ||
$POETRY_RUN pylint "${BASE_DIR}/ctms" "${BASE_DIR}/tests/unit" | ||
} | ||
mypy () { | ||
$POETRY_RUN mypy "${BASE_DIR}/ctms" | ||
} | ||
all () { | ||
echo "running black" | ||
black | ||
echo "running isort" | ||
isort | ||
echo "running mypy" | ||
mypy | ||
echo "running pylint" | ||
pylint | ||
echo "running bandit" | ||
bandit | ||
echo "running detect_secrets" | ||
detect_secrets | ||
} | ||
|
||
if [ -n "$HAS_GIT" ]; then | ||
# Scan only files checked into the repo, omit poetry.lock | ||
SECRETS_TO_SCAN=`git ls-tree --full-tree -r --name-only HEAD | grep -v poetry.lock` | ||
$POETRY_RUN detect-secrets-hook $SECRETS_TO_SCAN --baseline .secrets.baseline | ||
fi | ||
usage () { | ||
echo "Usage: bin/lint.sh [OPTION]" | ||
echo " run linting checks" | ||
echo "Options": | ||
echo " bandit" | ||
echo " black [--fix]" | ||
echo " detect-secrets" | ||
echo " isort [--fix]" | ||
echo " mypy" | ||
echo " pylint" | ||
} | ||
|
||
$POETRY_RUN isort --check-only "${BASE_DIR}" | ||
$POETRY_RUN black --check "${BASE_DIR}" | ||
$POETRY_RUN mypy "${BASE_DIR}/ctms" | ||
$POETRY_RUN pylint "${BASE_DIR}/ctms" "${BASE_DIR}/tests/unit" | ||
subcommand=''; | ||
check="true" | ||
if [ -z $1 ]; then | ||
all | ||
else | ||
subcommand=$1; shift | ||
case $subcommand in | ||
"black" | "isort") | ||
case $1 in | ||
"--fix") | ||
check="" | ||
;; | ||
esac | ||
case $subcommand in | ||
"isort") isort;; | ||
"black") black;; | ||
esac | ||
;; | ||
grahamalama marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
"pylint") pylint;; | ||
"mypy") mypy;; | ||
"bandit") bandit;; | ||
"detect-secrets") detect_secrets;; | ||
*) usage;; | ||
esac | ||
fi |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the motivation for these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just because I took it from https://github.com/mozilla/jira-bugzilla-integration/blob/main/bin/lint.sh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, initially I was going to suggest keeping this the way it is and migrating JBI to "bash strict mode".
But turns out there are some gotchas with that approach as well.
So, maybe
-euo pipefail
is "safer", if not too safe, but this could also be fine as is, since I'm less convinced about the safety that these flags provide.