Skip to content

Commit

Permalink
Stylecheck script fails on MacOS ethereum#13492
Browse files Browse the repository at this point in the history
- Install GNU grep on macOS with `brew install grep`
- Use GNU grep with -E option
- The following errors fixed.
```
$scripts/check_style.sh
ggrep: warning: stray \ before /
ggrep: warning: stray \ before /
ggrep: warning: * at start of expression
ggrep: warning: * at start of expression
```
  • Loading branch information
hiroshitashir committed Jun 22, 2023
1 parent b26090c commit 0a72b2d
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions scripts/check_style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ set -eu

ERROR_LOG="$(mktemp -t check_style_XXXXXX.log)"

if [ "$(uname)" == "Darwin" ]; then
if ! command -v ggrep &> /dev/null
then
brew install grep # install GNU grep on macOS
fi
grepCommand=ggrep
else
grepCommand=grep
fi

EXCLUDE_FILES=(
# The line below is left unquoted to allow the shell globbing path expansion
test/cmdlineTests/*/{err,output}
Expand All @@ -25,7 +35,7 @@ REPO_ROOT="$(dirname "$0")"/..
cd "$REPO_ROOT" || exit 1

WHITESPACE=$(git grep -n -I -E "^.*[[:space:]]+$" |
grep -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true
${grepCommand} -v "test/libsolidity/ASTJSON\|test/libsolidity/ASTRecoveryTests\|test/compilationTests/zeppelin/LICENSE\|${EXCLUDE_FILES_JOINED}" || true
)

if [[ "$WHITESPACE" != "" ]]
Expand All @@ -38,27 +48,27 @@ fi

function preparedGrep
{
git grep -nIE "$1" -- '*.h' '*.cpp' | grep -v "${EXCLUDE_FILES_JOINED}"
git grep -nIE "$1" -- '*.h' '*.cpp' | ${grepCommand} -v "${EXCLUDE_FILES_JOINED}"
return $?
}

FORMATERROR=$(
(
preparedGrep "#include \"" | grep -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters
preparedGrep "#include \"" | ${grepCommand} -E -v -e "license.h" -e "BuildInfo.h" # Use include with <> characters
preparedGrep "\<(if|for|while|switch)\(" # no space after "if", "for", "while" or "switch"
preparedGrep "\<for\>\s*\([^=]*\>\s:\s.*\)" # no space before range based for-loop
preparedGrep "\<if\>\s*\(.*\)\s*\{\s*$" # "{\n" on same line as "if"
preparedGrep "namespace .*\{"
preparedGrep "[,\(<]\s*const " # const on left side of type
preparedGrep "^\s*(static)?\s*const " # const on left side of type (beginning of line)
preparedGrep "^ [^*]|[^*] | [^*]" # uses spaces for indentation or mixes spaces and tabs
preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | grep -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
preparedGrep "[a-zA-Z0-9_]\s*[&][a-zA-Z_]" | ${grepCommand} -E -v "return [&]" # right-aligned reference ampersand (needs to exclude return)
# right-aligned reference pointer star (needs to exclude return and comments)
preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | grep -E -v -e "return [*]" -e "^* [*]" -e "^*//.*"
preparedGrep "[a-zA-Z0-9_]\s*[*][a-zA-Z_]" | ${grepCommand} -E -v -e "return [*]" -e "^\s*[*]" -e "^.*//.*"
# unqualified move()/forward() checks, i.e. make sure that std::move() and std::forward() are used instead of move() and forward()
preparedGrep "move\(.+\)" | grep -v "std::move" | grep -E "[^a-z]move"
preparedGrep "forward\(.+\)" | grep -v "std::forward" | grep -E "[^a-z]forward"
) | grep -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*\/(\/|\*)" -e "^test/" || true
preparedGrep "move\(.+\)" | ${grepCommand} -v "std::move" | ${grepCommand} -E "[^a-z]move"
preparedGrep "forward\(.+\)" | ${grepCommand} -v "std::forward" | ${grepCommand} -E "[^a-z]forward"
) | ${grepCommand} -E -v -e "^[a-zA-Z\./]*:[0-9]*:\s*/(/|\*)" -e "^test/" || true
)

if [[ "$FORMATERROR" != "" ]]
Expand Down

0 comments on commit 0a72b2d

Please sign in to comment.