Skip to content

Commit

Permalink
style(all): configure format-on-commit
Browse files Browse the repository at this point in the history
This uses `husky` v6 at the root of the workspace and `lint-staged` in each of the projects that need formatting. The lastest `husky` works a little differently than what we were using before (v4). Mostly, it uses the `core.hookspath` git config to point to `.husky/` within the project, setting that config property using a custom `prepare` script at the root. We then have a `pre-commit` script that asks `pnpm` to figure out all the changed packages and runs the `pre-commit` script in each one if it's there.
  • Loading branch information
eventualbuddha committed Jul 6, 2021
1 parent 62c6849 commit c8b5a0f
Show file tree
Hide file tree
Showing 21 changed files with 459 additions and 279 deletions.
8 changes: 8 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
. "$(dirname "$0")/_/husky.sh"

# Run `pre-commit` script in packages changed since the last commit.
pnpm \
--workspace-concurrency=1 \
--filter='[HEAD]' \
run --if-present pre-commit
40 changes: 17 additions & 23 deletions apps/bas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,23 @@
"stylelint:run:fix": "stylelint 'src/**/*.{js,jsx,ts,tsx}' --fix && stylelint 'src/**/*.css' --config .stylelintrc-css.js --fix",
"test": "is-ci test:coverage test:watch",
"test:watch": "script/react-scripts test",
"test:coverage": "script/react-scripts test --coverage --watchAll=false"
},
"husky": {
"hooks": {
"pre-commit": "tsc --build && lint-staged"
}
"test:coverage": "script/react-scripts test --coverage --watchAll=false",
"pre-commit": "lint-staged"
},
"lint-staged": {
"linters": {
"*.+(js|jsx|ts|tsx)": [
"stylelint --fix",
"eslint --quiet --fix",
"git add"
],
"*.css": [
"stylelint --config .stylelintrc-css.js --fix",
"git add"
],
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write",
"git add"
]
}
"*.+(js|jsx|ts|tsx)": [
"stylelint --fix",
"eslint --quiet --fix"
],
"*.css": [
"stylelint --config .stylelintrc-css.js --fix"
],
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write"
],
"package.json": [
"sort-package-json"
]
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -92,10 +86,10 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.21.5",
"eslint-plugin-vx": "workspace:*",
"husky": "^2.1.0",
"is-ci-cli": "^2.1.2",
"lint-staged": "^8.1.5",
"prettier": "^2.1.2",
"sort-package-json": "^1.50.0",
"stylelint": "^13.7.2",
"stylelint-config-palantir": "^5.0.0",
"stylelint-config-prettier": "^8.0.2",
Expand All @@ -108,4 +102,4 @@
"../module-smartcards"
]
}
}
}
13 changes: 6 additions & 7 deletions apps/bmd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@
"test:e2e:ci": "start-server-and-test start http://localhost:3000 cypress:run",
"test:e2e:watch": "start-server-and-test start http://localhost:3000 cypress:open",
"test:update": "TZ=UTC script/react-scripts test -u --watchAll=false --env=jest-environment-jsdom-sixteen",
"test:watch": "TZ=UTC script/react-scripts test --env=jest-environment-jsdom-sixteen"
},
"husky": {
"hooks": {
"pre-commit": "tsc --build && lint-staged"
}
"test:watch": "TZ=UTC script/react-scripts test --env=jest-environment-jsdom-sixteen",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(js|jsx|ts|tsx)": [
Expand All @@ -43,6 +39,9 @@
],
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write"
],
"package.json": [
"sort-package-json"
]
},
"browserslist": {
Expand Down Expand Up @@ -148,7 +147,6 @@
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-vx": "workspace:*",
"husky": "^4.2.5",
"is-ci-cli": "^2.0.0",
"jest-date-mock": "^1.0.8",
"jest-environment-jsdom-sixteen": "^1.0.3",
Expand All @@ -157,6 +155,7 @@
"lint-staged": "^10.2.4",
"prettier": "^2.1.1",
"react-dev-utils": "^11.0.3",
"sort-package-json": "^1.50.0",
"start-server-and-test": "^1.11.0",
"stylelint": "^13.3.3",
"stylelint-config-palantir": "^4.0.1",
Expand Down
15 changes: 7 additions & 8 deletions apps/bsd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
"test": "is-ci test:coverage test:watch",
"test:watch": "TZ=UTC script/react-scripts test --env=jest-environment-jsdom-sixteen",
"test:coverage": "TZ=UTC script/react-scripts test --coverage --watchAll=false",
"test:debug": "TZ=UTC script/react-scripts --inspect-brk test --runInBand --no-cache"
},
"husky": {
"hooks": {
"pre-commit": "tsc && lint-staged"
}
"test:debug": "TZ=UTC script/react-scripts --inspect-brk test --runInBand --no-cache",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(js|jsx|ts|tsx)": [
Expand All @@ -37,6 +33,9 @@
],
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write"
],
"package.json": [
"sort-package-json"
]
},
"browserslist": {
Expand Down Expand Up @@ -123,14 +122,14 @@
"eslint-plugin-vx": "workspace:*",
"fetch-mock": "^9.9.0",
"history": "^4.10.1",
"husky": "^4.2.5",
"is-ci-cli": "^2.1.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"jest-fetch-mock": "^3.0.3",
"lint-staged": "^10.2.3",
"node-fetch": "^2.6.0",
"prettier": "^2.1.2",
"react-refresh": "^0.9.0",
"sort-package-json": "^1.50.0",
"stylelint": "^13.4.0",
"stylelint-config-palantir": "^5.0.0",
"stylelint-config-prettier": "^8.0.1",
Expand All @@ -145,4 +144,4 @@
"../module-scan"
]
}
}
}
13 changes: 4 additions & 9 deletions apps/election-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
"stylelint:run:fix": "stylelint 'src/**/*.{js,jsx,ts,tsx}' --fix && stylelint 'src/**/*.css' --config .stylelintrc-css.js --fix",
"test": "is-ci test:coverage test:watch",
"test:watch": "TZ=PST script/react-scripts test --env=jest-environment-jsdom-sixteen",
"test:coverage": "TZ=PST script/react-scripts test --coverage --watchAll=false"
},
"husky": {
"hooks": {
"pre-commit": "tsc && lint-staged"
}
"test:coverage": "TZ=PST script/react-scripts test --coverage --watchAll=false",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
Expand Down Expand Up @@ -150,14 +146,13 @@
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^4.0.5",
"eslint-plugin-vx": "workspace:*",
"husky": "^4.2.1",
"is-ci-cli": "^2.1.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"lint-staged": "^10.0.7",
"prettier": "^2.0.5",
"react-refresh": "^0.9.0",
"react-test-renderer": "^16.13.1",
"sort-package-json": "^1.44.0",
"sort-package-json": "^1.50.0",
"stylelint": "^13.1.0",
"stylelint-config-palantir": "^4.0.1",
"stylelint-config-prettier": "^8.0.1",
Expand All @@ -171,4 +166,4 @@
"../module-smartcards"
]
}
}
}
13 changes: 4 additions & 9 deletions apps/module-scan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@
"test:coverage": "jest --coverage",
"test:debug": "node --inspect-brk $(which jest) --runInBand --no-cache",
"test:watch": "jest --watch",
"watch": "tsc --build --watch"
},
"husky": {
"hooks": {
"pre-commit": "tsc --build && lint-staged"
}
"watch": "tsc --build --watch",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
Expand Down Expand Up @@ -100,14 +96,13 @@
"eslint-plugin-jest": "^24.1.3",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vx": "workspace:*",
"husky": "^4.3.7",
"is-ci-cli": "^2.1.2",
"jest": "^26.6.3",
"jest-watch-typeahead": "^0.6.4",
"lint-staged": "^10.5.3",
"nock": "^13.1.0",
"prettier": "^2.2.1",
"sort-package-json": "^1.48.1",
"sort-package-json": "^1.50.0",
"supertest": "^6.0.1",
"ts-jest": "^26.4.4",
"ts-node": "^9.1.1",
Expand All @@ -117,4 +112,4 @@
"engines": {
"node": ">= 12"
}
}
}
4 changes: 3 additions & 1 deletion apps/module-smartcards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ make coverage

## Mock a Smart Card

Once you're running the server, you can enable a mock card reader with fixture data as in the examples below. Supply your own election definition, or use one of the existing [`fixtures/`](./fixtures).
Once you're running the server, you can enable a mock card reader with fixture
data as in the examples below. Supply your own election definition, or use one
of the existing [`fixtures/`](./fixtures).

### Using your own election definition

Expand Down
15 changes: 5 additions & 10 deletions apps/precinct-scanner/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@
"stylelint:run:fix": "stylelint 'src/**/*.{js,jsx,ts,tsx}' --fix && stylelint 'src/**/*.css' --config .stylelintrc-css.js --fix",
"test": "is-ci test:coverage test:watch",
"test:watch": "TZ=UTC script/react-scripts test --env=jest-environment-jsdom-sixteen",
"test:coverage": "TZ=UTC script/react-scripts test --coverage --watchAll=false"
},
"husky": {
"hooks": {
"pre-commit": "tsc && lint-staged"
}
"test:coverage": "TZ=UTC script/react-scripts test --coverage --watchAll=false",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
Expand Down Expand Up @@ -135,13 +131,12 @@
"eslint-plugin-react": "^7.18.3",
"eslint-plugin-react-hooks": "^4.0.5",
"eslint-plugin-vx": "workspace:*",
"husky": "^4.2.1",
"is-ci-cli": "^2.1.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"lint-staged": "^10.0.7",
"lint-staged": "^10.5.4",
"prettier": "^2.0.5",
"react-refresh": "^0.9.0",
"sort-package-json": "^1.44.0",
"sort-package-json": "^1.50.0",
"stylelint": "^13.1.0",
"stylelint-config-palantir": "^4.0.1",
"stylelint-config-prettier": "^8.0.1",
Expand All @@ -156,4 +151,4 @@
"../module-smartcards"
]
}
}
}
19 changes: 15 additions & 4 deletions integration-testing/bsd/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
"test": "is-ci test:ci test:watch",
"test:ci": "start-server-and-test start http://localhost:3000 cypress:run",
"test:watch": "cypress open",
"cypress:run": "cypress run --browser chrome"
"cypress:run": "cypress run --browser chrome",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write"
],
"*.+(js|jsx|ts|tsx)": [
"eslint --quiet --fix"
],
"package.json": [
"sort-package-json"
]
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -43,12 +55,11 @@
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-vx": "workspace:*",
"husky": "^4.2.1",
"is-ci-cli": "^2.1.2",
"jest-environment-jsdom-sixteen": "^1.0.3",
"lint-staged": "^10.0.7",
"lint-staged": "^10.5.4",
"prettier": "^2.0.5",
"sort-package-json": "^1.44.0",
"sort-package-json": "^1.50.0",
"start-server-and-test": "^1.12.5",
"typescript": "^4.2.0"
}
Expand Down
17 changes: 15 additions & 2 deletions integration-testing/election-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,19 @@
"test": "is-ci test:ci test:watch",
"test:ci": "start-server-and-test start http://localhost:3000 cypress:run",
"test:watch": "cypress open",
"cypress:run": "cypress run --browser chrome"
"cypress:run": "cypress run --browser chrome",
"pre-commit": "lint-staged"
},
"lint-staged": {
"*.+(css|graphql|json|less|md|mdx|sass|scss|yaml|yml)": [
"prettier --write"
],
"*.+(js|jsx|ts|tsx)": [
"eslint --quiet --fix"
],
"package.json": [
"sort-package-json"
]
},
"browserslist": {
"production": [
Expand Down Expand Up @@ -45,8 +57,9 @@
"eslint-plugin-prettier": "^3.1.2",
"eslint-plugin-vx": "workspace:*",
"is-ci-cli": "^2.1.2",
"lint-staged": "^11.0.0",
"prettier": "^2.0.5",
"sort-package-json": "^1.44.0",
"sort-package-json": "^1.50.0",
"start-server-and-test": "^1.12.5",
"typescript": "^4.2.0"
}
Expand Down
Loading

0 comments on commit c8b5a0f

Please sign in to comment.