Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lint precommit hook #127

Merged
merged 2 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .husky/pre-commit
nhanphan marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

set +e

# Stash un-staged changes - optional, see note below
nhanphan marked this conversation as resolved.
Show resolved Hide resolved
git stash -q --keep-index

# Run pnpm commands
echo "Linting..."
pnpm lint
LINT_EXIT_CODE=$?

# Restore un-staged changes - optional, see note below
git stash pop -q

# Check if tests or lint failed
if [ $LINT_EXIT_CODE -ne 0 ]; then
echo "Linting failed run 'pnpm lint:fix' to fix linting issues"
exit 1
fi

set -e

exit 0
14 changes: 14 additions & 0 deletions configs/scripts/client/format-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# go to parent folder
cd $(dirname $(dirname $(dirname $SCRIPT_DIR)))
WORKING_DIR=$(pwd)

# command-line input
ARGS=$*

# js client tests folder
cd ${WORKING_DIR}/clients/js

pnpm install && pnpm format:fix
14 changes: 14 additions & 0 deletions configs/scripts/client/lint-js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
# go to parent folder
cd $(dirname $(dirname $(dirname $SCRIPT_DIR)))
WORKING_DIR=$(pwd)

# command-line input
ARGS=$*

# js client tests folder
cd ${WORKING_DIR}/clients/js

pnpm install && pnpm format
19 changes: 19 additions & 0 deletions configs/scripts/program/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
OUTPUT="./programs/.bin"
# go to parent folder
cd $(dirname $(dirname $(dirname ${SCRIPT_DIR})))

rm -rf $OUTPUT

if [ -z ${PROGRAMS+x} ]; then
PROGRAMS="$(cat .github/.env | grep "PROGRAMS" | cut -d '=' -f 2)"
fi

PROGRAMS=$(echo ${PROGRAMS} | jq -c '.[]' | sed 's/"//g')
WORKING_DIR=$(pwd)

for p in ${PROGRAMS[@]}; do
cargo fmt --all --manifest-path ./programs/${p}/Cargo.toml
done
19 changes: 19 additions & 0 deletions configs/scripts/program/lint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
OUTPUT="./programs/.bin"
# go to parent folder
cd $(dirname $(dirname $(dirname ${SCRIPT_DIR})))

rm -rf $OUTPUT

if [ -z ${PROGRAMS+x} ]; then
PROGRAMS="$(cat .github/.env | grep "PROGRAMS" | cut -d '=' -f 2)"
fi

PROGRAMS=$(echo ${PROGRAMS} | jq -c '.[]' | sed 's/"//g')
WORKING_DIR=$(pwd)

for p in ${PROGRAMS[@]}; do
cargo fmt --all --manifest-path ./programs/${p}/Cargo.toml -- --check
done
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
"validator": "CI=1 amman start --config ./configs/validator.cjs",
"validator:debug": "amman start --config ./configs/validator.cjs",
"validator:logs": "CI=1 amman logs",
"validator:stop": "amman stop"
"validator:stop": "amman stop",
"lint:fix": "./configs/scripts/client/format-js.sh && ./configs/scripts/program/format.sh",
"format:fix": "pnpm lint:fix",
"lint": "./configs/scripts/client/lint-js.sh && ./configs/scripts/program/lint.sh",
"prepare": "husky"
},
"devDependencies": {
"@metaplex-foundation/amman": "^0.12.1",
"@metaplex-foundation/kinobi": "0.18.8-alpha.0",
"@metaplex-foundation/shank-js": "^0.1.7",
"husky": "^9.0.11",
"typescript": "^4.9.4"
},
"packageManager": "[email protected]"
}
}
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading