Skip to content

Commit

Permalink
Merge pull request #1486 from maxmind/kevin/precious
Browse files Browse the repository at this point in the history
Replace husky with precious
  • Loading branch information
kevcenteno authored Nov 6, 2024
2 parents f72991a + 24831f6 commit 11c943d
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 684 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ jobs:
run: npm run lint
- name: Run prettier
run: npm run prettier:ci
- name: Test compile
run: npx tsc --noEmit
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ typings/

# next.js build output
.next

# Precious install
local
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

36 changes: 0 additions & 36 deletions .husky/_/husky.sh

This file was deleted.

4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

53 changes: 53 additions & 0 deletions .precious.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[commands.prettier-scripts]
type = "both"
cmd = [
"npx",
"prettier",
"--parser",
"typescript"
]
lint-flags = ["--check"]
tidy-flags = ["--write"]
path-args = "absolute-file"
include = ["src/**/*.ts"]
ok-exit-codes = 0

[commands.prettier-json]
type = "both"
cmd = [
"npx",
"prettier",
"--parser",
"json"
]
lint-flags = ["--check"]
tidy-flags = ["--write"]
path-args = "absolute-file"
include = ["**/*.json"]
ok-exit-codes = 0

[commands.eslint-scripts]
type = "both"
cmd = [
"npx",
"eslint",
"--config",
"eslint.config.mjs",
]
lint-flags = []
tidy-flags = ["--fix"]
path-args = "absolute-file"
include = ["src/**/*.ts", "src/**/*.js", "e2e/**/*.ts", "e2e/**/*.js"]
ok-exit-codes = 0

[commands.tsc-scripts]
type = "lint"
cmd = [
"npx",
"tsc",
"--noEmit"
]
include = ["src/**/*.ts"]
invoke = "once"
path-args = "none"
ok-exit-codes = 0
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/package.json
**/package-lock.json
5 changes: 3 additions & 2 deletions README.dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Steps for releasing:
[GitHub](https://github.com/maxmind/minfraud-api-node/releases) and
[NPM](https://npmjs.com/package/@maxmind/minfraud-api-node).

## Set up pre-commit hooks
## Set up Precious to tidy and lint

`npm run setup` to install husky pre-commit hooks
1. Run `mkdir -p local && ./bin/install-precious local` to set up Precious locally
2. Run `./git/setup.sh` to set up pre-commit hook that invokes Precious
22 changes: 22 additions & 0 deletions bin/install-precious
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# This is for installing precious and other 3rd party libs needed for linting
# in CI

set -euo pipefail
set -x

if [ -z "${1:-}" ]; then
echo "💥 You need to specify where to install precious. usage: ./bin/install-precious /path/to/bin/dir"
exit 1
fi

TARGET=$1
export TARGET

curl --silent --location \
https://raw.githubusercontent.com/houseabsolute/ubi/master/bootstrap/bootstrap-ubi.sh |
sh

./"$TARGET"/ubi --project houseabsolute/omegasort --in "$TARGET"
./"$TARGET"/ubi --project houseabsolute/precious --in "$TARGET"
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default tseslint.config(
"jest.config.js",
"eslint.config.mjs",
"coverage",
"prettier.config.mjs",
],
},
);
27 changes: 27 additions & 0 deletions git/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -eu

function timed_run() {
description=$1
command=$2
timer=$(date +%s)

$command
exit_code=$?
timer=$(($(date +%s) - timer))

verbose=${MM_VERBOSE_HOOKS:-0}

if [ "$verbose" == "1" ]; then
echo "ℹ️ $description - $timer seconds"
echo "exit code: $exit_code"
fi

if [ $exit_code -ne 0 ]; then
echo "ℹ️ $description - failed"
exit $exit_code
fi
}

timed_run "local/precious lint" "local/precious lint --staged"
7 changes: 7 additions & 0 deletions git/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

chmod +x git/hooks/*
cd .git/hooks || exit
rm -f pre-commit.sample
ln -s ../../git/hooks/pre-commit .
git config --local core.hooksPath .git/hooks
Loading

0 comments on commit 11c943d

Please sign in to comment.