Skip to content

Commit

Permalink
Add --fix flag
Browse files Browse the repository at this point in the history
  • Loading branch information
driazati committed Apr 7, 2022
1 parent fa098cd commit 4333a82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/lint/git-black.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# under the License.
set -euo pipefail

INPLACE_FORMAT=false
INPLACE_FORMAT=${INPLACE_FORMAT:=false}
LINT_ALL_FILES=true
REVISION=

Expand Down
8 changes: 4 additions & 4 deletions tests/lint/git-clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ set -u
set -o pipefail


INPLACE_FORMAT=false
INPLACE_FORMAT=${INPLACE_FORMAT:=false}
LINT_ALL_FILES=true
REVISION=
REVISION=$(git rev-list --max-parents=0 HEAD)

while (( $# )); do
case "$1" in
Expand All @@ -48,6 +48,7 @@ while (( $# )); do
esac
done


cleanup()
{
rm -rf /tmp/$$.clang-format.txt
Expand Down Expand Up @@ -78,8 +79,7 @@ fi
if [[ "$LINT_ALL_FILES" == "true" ]]; then
echo "Running git-clang-format against all C++ files"
FILES=$(git ls-files | grep -E '\.(c|cc|cpp|mm|h|hpp)$')
BASE_COMMIT=$(git rev-list --max-parents=0 HEAD)
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$BASE_COMMIT" ${FILES[@]} 1> /tmp/$$.clang-format.txt
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" ${FILES[@]} 1> /tmp/$$.clang-format.txt
else
echo "Running git-clang-format against $REVISION"
git-${CLANG_FORMAT} --diff --extensions h,mm,c,cc --binary=${CLANG_FORMAT} "$REVISION" 1> /tmp/$$.clang-format.txt
Expand Down
10 changes: 8 additions & 2 deletions tests/scripts/ci.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,18 +319,24 @@ def serve_docs(directory: str = "_docs") -> None:
cmd([sys.executable, "-m", "http.server"], cwd=directory_path)


def lint(interactive: bool = False) -> None:
def lint(interactive: bool = False, fix: bool = False) -> None:
"""
Run CI's Sanity Check step
arguments:
interactive -- start a shell after running build / test scripts
fix -- where possible (currently black and clang-format) edit files in place with formatting fixes
"""
env = {}
if fix:
env["IS_LOCAL"] = "true"
env["INPLACE_FORMAT"] = "true"

docker(
name=gen_name(f"ci-lint"),
image="ci_lint",
scripts=["./tests/scripts/task_lint.sh"],
env={},
env=env,
interactive=interactive,
)

Expand Down

0 comments on commit 4333a82

Please sign in to comment.