chore(lint): Add Elvis Linter Config and Github Action

This commit is contained in:
ayodele.akingbule 2020-12-09 13:14:06 +01:00 committed by tigercl
parent fd986bbbb2
commit 315d14d3ed
4 changed files with 81 additions and 0 deletions

13
.github/workflows/elvis_lint.yaml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Elvis Linter
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: |
echo "$GITHUB_BASE_REF"
echo "$GITHUB_HEAD_REF"
./elvis-check.sh $GITHUB_BASE_REF $GITHUB_HEAD_REF

1
.gitignore vendored
View File

@ -41,3 +41,4 @@ erlang.mk
*.coverdata
etc/emqx.conf.rendered
Mnesia.*/
elvis

36
elvis-check.sh Executable file
View File

@ -0,0 +1,36 @@
#!/bin/bash
set -euo pipefail
echo "GITHUB_BASE_REF $1"
echo "GITHUB_HEAD_REF $2"
echo "$GITHUB_SHA"
ELVIS_VERSION='1.0.0-emqx-1'
base=${GITHUB_BASE_REF:-$1}
elvis_version="${3:-$ELVIS_VERSION}"
echo "$elvis_version"
echo "$base"
if [ ! -f ./elvis ] || [ "$(./elvis -v | grep -oE '[1-9]+\.[0-9]+\.[0-9]+\-emqx-[0-9]+')" != "$ELVIS_VERSION" ]; then
curl -fLO "https://github.com/emqx/elvis/releases/download/$elvis_version/elvis"
chmod +x ./elvis
fi
git fetch origin "$base"
git checkout -b refBranch HEAD
git diff --name-only origin/"$base" refBranch
bad_file_count=0
for n in $(git diff --name-only origin/"$base" refBranch); do
if ! ./elvis rock "$n"; then
bad_file_count=$(( bad_file_count + 1))
fi
done
if [ $bad_file_count -gt 0 ]; then
echo "elvis: $bad_file_count errors"
exit 1
fi

31
elvis.config Normal file
View File

@ -0,0 +1,31 @@
[
{
elvis,
[
{config,
[
{dirs => ["apps"],
filter => "*.erl",
ruleset => erl_files,
# rules => [
# {elvis_style, max_module_length, #{}},
# {elvis_style, no_common_caveats_call, #{}}
# ]
},
{dirs => ["."],
filter => "Makefile",
ruleset => makefiles
},
{dirs => ["."],
filter => "rebar.config",
ruleset => rebar_config
},
{dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]
}
]
}
].