Merge pull request #6064 from zmstone/style-check-newline-at-eof

Style: check newline at EOF
This commit is contained in:
Zaiming (Stone) Shi 2021-11-04 18:01:45 +01:00 committed by GitHub
commit 3b02366a5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 96 additions and 55 deletions

27
.github/workflows/code-style-check.yaml vendored Normal file
View File

@ -0,0 +1,27 @@
name: Code style check
on: [pull_request]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 1000
- name: Set git token
if: endsWith(github.repository, 'enterprise')
run: |
echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
git config --global credential.helper store
- name: Run elvis check
run: |
set -e
if [ -f EMQX_ENTERPRISE ]; then
./scripts/elvis-check.sh $GITHUB_BASE_REF emqx-enterprise
else
./scripts/elvis-check.sh $GITHUB_BASE_REF emqx
fi
- name: Check line-break at EOF
- run: |
./scripts/check-nl-at-eof.sh

View File

@ -1,16 +0,0 @@
name: Elvis Linter
on: [pull_request]
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Set git token
if: endsWith(github.repository, 'enterprise')
run: |
echo "https://ci%40emqx.io:${{ secrets.CI_GIT_TOKEN }}@github.com" > $HOME/.git-credentials
git config --global credential.helper store
- run: |
./scripts/elvis-check.sh $GITHUB_BASE_REF

View File

@ -112,7 +112,8 @@ t_out(_) ->
t_out_2(_) -> t_out_2(_) ->
{empty, {pqueue, [{-1, {queue, [a], [], 1}}]}} = ?PQ:out(0, ?PQ:from_list([{1, a}])), {empty, {pqueue, [{-1, {queue, [a], [], 1}}]}} = ?PQ:out(0, ?PQ:from_list([{1, a}])),
{{value, a}, {queue, [], [], 0}} = ?PQ:out(1, ?PQ:from_list([{1, a}])), {{value, a}, {queue, [], [], 0}} = ?PQ:out(1, ?PQ:from_list([{1, a}])),
{{value, a}, {pqueue, [{-1, {queue, [], [b], 1}}]}} = ?PQ:out(1, ?PQ:from_list([{1, a}, {1, b}])), {{value, a}, {pqueue, [{-1, {queue, [], [b], 1}}]}} =
?PQ:out(1, ?PQ:from_list([{1, a}, {1, b}])),
{{value, a}, {queue, [b], [], 1}} = ?PQ:out(1, ?PQ:from_list([{1, a}, {0, b}])). {{value, a}, {queue, [b], [], 1}} = ?PQ:out(1, ?PQ:from_list([{1, a}, {0, b}])).
t_out_p(_) -> t_out_p(_) ->

View File

@ -100,7 +100,8 @@ on_start(InstId, #{redis_type := Type,
Options = case maps:get(enable, SSL) of Options = case maps:get(enable, SSL) of
true -> true ->
[{ssl, true}, [{ssl, true},
{ssl_options, emqx_plugin_libs_ssl:save_files_return_opts(SSL, "connectors", InstId)} {ssl_options,
emqx_plugin_libs_ssl:save_files_return_opts(SSL, "connectors", InstId)}
]; ];
false -> [{ssl, false}] false -> [{ssl, false}]
end ++ [{sentinel, maps:get(sentinel, Config, undefined)}], end ++ [{sentinel, maps:get(sentinel, Config, undefined)}],

View File

@ -33,7 +33,7 @@ nested_get({var, Key}, Data, Default) ->
nested_get({path, Path}, Data, Default) when is_list(Path) -> nested_get({path, Path}, Data, Default) when is_list(Path) ->
do_nested_get(Path, Data, Data, Default). do_nested_get(Path, Data, Data, Default).
do_nested_get([Key|More], Data, OrgData, Default) -> do_nested_get([Key | More], Data, OrgData, Default) ->
case general_map_get(Key, Data, OrgData, undefined) of case general_map_get(Key, Data, OrgData, undefined) of
undefined -> Default; undefined -> Default;
Val -> do_nested_get(More, Val, OrgData, Default) Val -> do_nested_get(More, Val, OrgData, Default)
@ -51,7 +51,7 @@ nested_put({var, Key}, Val, Map) ->
nested_put({path, Path}, Val, Map) when is_list(Path) -> nested_put({path, Path}, Val, Map) when is_list(Path) ->
do_nested_put(Path, Val, Map, Map). do_nested_put(Path, Val, Map, Map).
do_nested_put([Key|More], Val, Map, OrgData) -> do_nested_put([Key | More], Val, Map, OrgData) ->
SubMap = general_map_get(Key, Map, OrgData, undefined), SubMap = general_map_get(Key, Map, OrgData, undefined),
general_map_put(Key, do_nested_put(More, Val, SubMap, OrgData), Map, OrgData); general_map_put(Key, do_nested_put(More, Val, SubMap, OrgData), Map, OrgData);
do_nested_put([], Val, _Map, _OrgData) -> do_nested_put([], Val, _Map, _OrgData) ->
@ -131,13 +131,13 @@ setnth(tail, List, Val) when is_list(List) -> List ++ [Val];
setnth(tail, _List, Val) -> [Val]; setnth(tail, _List, Val) -> [Val];
setnth(I, List, _Val) when not is_integer(I) -> List; setnth(I, List, _Val) when not is_integer(I) -> List;
setnth(0, List, _Val) -> List; setnth(0, List, _Val) -> List;
setnth(I, List, _Val) when is_integer(I), I > 0 -> setnth(I, List, Val) when is_integer(I), I > 0 ->
do_setnth(I, List, _Val); do_setnth(I, List, Val);
setnth(I, List, _Val) when is_integer(I), I < 0 -> setnth(I, List, Val) when is_integer(I), I < 0 ->
lists:reverse(do_setnth(-I, lists:reverse(List), _Val)). lists:reverse(do_setnth(-I, lists:reverse(List), Val)).
do_setnth(1, [_|Rest], Val) -> [Val|Rest]; do_setnth(1, [_ | Rest], Val) -> [Val | Rest];
do_setnth(I, [E|Rest], Val) -> [E|setnth(I-1, Rest, Val)]; do_setnth(I, [E | Rest], Val) -> [E | setnth(I-1, Rest, Val)];
do_setnth(_, [], _Val) -> []. do_setnth(_, [], _Val) -> [].
getnth(0, _) -> getnth(0, _) ->

32
scripts/check-nl-at-eof.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
set -euo pipefail
cd -P -- "$(dirname -- "$0")/.."
nl_at_eof() {
local file="$1"
if ! [ -f "$file" ]; then
return
fi
case "$file" in
*.png|*rebar3)
return
;;
esac
local lastbyte
lastbyte="$(tail -c 1 "$file" 2>&1)"
if [ "$lastbyte" != '' ]; then
echo "$file"
return 1
fi
}
n=0
while read -r file; do
if ! nl_at_eof "$file"; then
n=$(( n + 1 ))
fi
done < <(git ls-files)
exit $n

View File

@ -5,16 +5,16 @@
set -euo pipefail set -euo pipefail
ELVIS_VERSION='1.0.0-emqx-2' elvis_version='1.0.0-emqx-2'
base="${1:-}" base="${1:-}"
repo="${2:-emqx}"
REPO="${GITHUB_REPOSITORY:-${repo}}"
if [ "${base}" = "" ]; then if [ "${base}" = "" ]; then
echo "Usage $0 <git-compare-base-ref>" echo "Usage $0 <git-compare-base-ref>"
exit 1 exit 1
fi fi
elvis_version="${2:-$ELVIS_VERSION}"
echo "elvis -v: $elvis_version" echo "elvis -v: $elvis_version"
echo "git diff base: $base" echo "git diff base: $base"
@ -27,11 +27,7 @@ if [[ "$base" =~ [0-9a-f]{8,40} ]]; then
# base is a commit sha1 # base is a commit sha1
compare_base="$base" compare_base="$base"
else else
if [[ $CI == true ]];then remote="$(git remote -v | grep -E "github\.com(:|/)emqx/$REPO((\.git)|(\s))" | grep fetch | awk '{print $1}')"
remote="$(git remote -v | grep -E "github\.com(.|/)$GITHUB_REPOSITORY" | grep fetch | awk '{print $1}')"
else
remote="$(git remote -v | grep -E 'github\.com(.|/)emqx' | grep fetch | awk '{print $1}')"
fi
git fetch "$remote" "$base" git fetch "$remote" "$base"
compare_base="$remote/$base" compare_base="$remote/$base"
fi fi