Skip to content

Commit

Permalink
Improved lint pre-commit hook (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
theethernaut committed Nov 20, 2020
1 parent 9b6859a commit 94f7e6d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
34 changes: 34 additions & 0 deletions hooks/lint
@@ -0,0 +1,34 @@
#!/usr/bin/env bash

# Detect changes in js and sol files
jsChangedFiles=$(git diff --name-only --exit-code --staged -- '***.js')
solChangedFiles=$(git diff --name-only --exit-code --staged -- '***.sol' ':!contracts/interfaces/*.sol')
isolChangedFiles=$(git diff --name-only --exit-code --staged -- 'contracts/interfaces/*.sol')

# Lint Javascript, only on changed files
if [[ ! -z $jsChangedFiles ]]; then
echo "Javascript changed files [$jsChangedFiles]"
stderrOutput=$(npx eslint $jsChangedFiles 2>&1)
if [[ ! -z $stderrOutput ]]; then
echo "Javascript lint failed with: $stderrOutput"
exit 1
fi
fi

# Lint Solidity, only on changed files
if [[ ! -z $solChangedFiles ]]; then
echo "Solidity changed files [$solChangedFiles]"
stderrOutput=$(npx solhint $solChangedFiles 2>&1)
if [[ ! -z $stderrOutput ]]; then
echo "Solidity lint failed with: $stderrOutput"
exit 1
fi
fi
if [[ ! -z $isolChangedFiles ]]; then
echo "Solidity interface files changed [$isolChangedFiles]"
stderrOutput=$(npx solhint $isolChangedFiles --config contracts/interfaces/.solhint.json 2>&1) # Capture stderr
if [[ ! -z $stderrOutput ]]; then
echo "Solidity interface lint failed with: $stderrOutput"
exit 1
fi
fi
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -31,7 +31,7 @@
},
"husky": {
"hooks": {
"pre-commit": "./hooks/circleci && npm run lint && pretty-quick --staged"
"pre-commit": "./hooks/circleci && pretty-quick --staged && ./hooks/lint"
}
},
"repository": {
Expand Down

0 comments on commit 94f7e6d

Please sign in to comment.