Skip to content

Commit

Permalink
update pre-commit for superlinter
Browse files Browse the repository at this point in the history
  • Loading branch information
mmacata committed Jul 5, 2024
1 parent a069293 commit 75fc8a4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 36 deletions.
22 changes: 22 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@
name: linting (via docker)
entry: /linting.sh
language: docker
- id: super-linting
name: super-linter (via docker)
language: docker_image
entry: >
-e RUN_LOCAL=true
-e DEFAULT_BRANCH=main
-e DEFAULT_WORKSPACE=/src
-e BASH_SEVERITY=warning
-e VALIDATE_BASH=true
-e VALIDATE_BASH_EXEC=true
-e VALIDATE_CSS=true
-e VALIDATE_DOCKERFILE_HADOLINT=true
-e VALIDATE_GITHUB_ACTIONS=true
-e VALIDATE_HTML=true
-e VALIDATE_JAVASCRIPT_ES=true
-e VALIDATE_JAVASCRIPT_STANDARD=true
-e VALIDATE_JSON=true
-e VALIDATE_MARKDOWN=true
-e VALIDATE_POWERSHELL=true
-e VALIDATE_RENOVATE=true
-e VALIDATE_XML=true
mundialis/super-linter:latest
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ COPY .github/workflows/linting.yml $WORKFLOW_LINTING_WORKFLOW
RUN echo black==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."black-version"'.default) >> /requirements.txt
RUN echo flake8==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."flake8-version"'.default) >> /requirements.txt
RUN echo pylint==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."pylint-version"'.default) >> /requirements.txt
RUN echo mdformat==$(cat $WORKFLOW_LINTING_WORKFLOW | yq .on.workflow_call.inputs | jq -r '."mdformat-version"'.default) >> /requirements.txt
RUN pip install -r requirements.txt

# Copy script to be executed on docker startup
Expand Down
9 changes: 9 additions & 0 deletions docker/super-linter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM ghcr.io/super-linter/super-linter:latest

# pre-commit seems to set too strict permissions:
# error: could not lock config file //.gitconfig: Permission denied
# Therefore do not configure globally
# https://github.com/super-linter/super-linter/blob/main/lib/linter.sh#L345
RUN sed -i 's+git config --global --add safe.directory+git config --add safe.directory+g' /action/lib/linter.sh

# push to mundialis/super-linter
35 changes: 0 additions & 35 deletions pre_commit_hooks/linting.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fi
RUN_BLACK=TRUE
RUN_FLAKE8=TRUE
RUN_PYLINT=TRUE
RUN_MDFORMAT=TRUE

####################################
# Overwrite linter versions if set #
Expand Down Expand Up @@ -84,24 +83,6 @@ else
echo "- pylint version not overwritten in code workflow"
fi

if [ $(yq '.jobs.lint.with | has("mdformat-version")' $CODE_LINTING_WORKFLOW) == true ]
then
DEFAULT_MDFORMAT_VERSION=$(cat /requirements.txt | grep mdformat== | cut -d "=" -f 3)
NEW_MDFORMAT_VERSION=$(yq '.jobs.lint.with."mdformat-version"' $CODE_LINTING_WORKFLOW)
if [ "$(echo $NEW_MDFORMAT_VERSION | tr '"' 'x')" = "xx" ]
then
RUN_MDFORMAT=FALSE
echo "- mdformat configured to be skipped (empty string)"
elif [ $DEFAULT_MDFORMAT_VERSION != $NEW_MDFORMAT_VERSION ]
then
# sed would fail with Permission denied
# sed -i "s+$DEFAULT_MDFORMAT_VERSION+$NEW_MDFORMAT_VERSION+g" /requirements.txt
echo "- Warning: overwritten mdformat version will not be installed!"
fi
else
echo "- mdformat version not overwritten in code workflow"
fi

echo

###################
Expand All @@ -113,7 +94,6 @@ echo
echo "flake8: `flake8 --version`"
echo "pylint: `pylint --version`"
echo "black: `black --version`"
echo "mdformat: `mdformat --version`"

########
# lint #
Expand Down Expand Up @@ -188,21 +168,6 @@ else
echo "BLACK configured to be skipped"
fi

if [ $RUN_MDFORMAT != "FALSE" ]
then
echo
echo "MDFORMAT:"
mdformat --check .
if [ $? -ne 0 ]
then
RETURNCODE=1
FAILINGSTEP="$FAILINGSTEP MDFORMAT (run 'mdformat --check .')"
fi
else
echo
echo "MDFORMAT configured to be skipped"
fi

if [ $RETURNCODE -ne 0 ]
then
echo "Failing steps: ${FAILINGSTEP}"
Expand Down

0 comments on commit 75fc8a4

Please sign in to comment.