Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved lint pre-commit hook (#918)
- Loading branch information
1 parent
9b6859a
commit 94f7e6d
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters