-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
chore: add pre commit husky setup #2195
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
base: redesign
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| cd astro | ||
| npx lint-staged | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ | |
| "format": "prettier --write .", | ||
| "format:check": "prettier --check .", | ||
| "check": "npm run format:check && npm run lint", | ||
| "fix": "npm run format && npm run lint:fix" | ||
| "fix": "npm run format && npm run lint:fix", | ||
| "prepare": "cd .. && husky astro/.husky" | ||
|
||
| }, | ||
| "dependencies": { | ||
| "@astrojs/mdx": "^4.3.13", | ||
|
|
@@ -39,12 +40,22 @@ | |
| "eslint-config-prettier": "^10.1.8", | ||
| "eslint-plugin-astro": "^1.5.0", | ||
| "eslint-plugin-jsx-a11y": "^6.10.2", | ||
| "husky": "^9.1.7", | ||
| "lint-staged": "^16.2.7", | ||
| "postcss-custom-media": "^12.0.0", | ||
| "postcss-nested": "^7.0.2", | ||
| "prettier": "^3.8.1", | ||
| "prettier-plugin-astro": "^0.14.1", | ||
| "typescript": "^5.9.3", | ||
| "typescript-eslint": "^8.53.1" | ||
| }, | ||
| "lint-staged": { | ||
| "*.{js,jsx,ts,tsx,astro}": [ | ||
| "eslint --fix", | ||
| "prettier --write" | ||
| ], | ||
| "*.{json,md,css}": [ | ||
| "prettier --write" | ||
| ] | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
node --run.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimised in 2574c92
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bjohansebas was the goal to avoid using npm? this approach requires we add a passthrough
"lint-staged": "lint-staged"script, which isnt something Im used to seeing.I wanted to suggest using the --cwd arg to lint-staged and dropping the
lint-stagedscript, but npm exec (npx replacement) wont be able to detect the installed bin if we don't help it discover a package.jsonnpm exec lint-staged --cwd astroIm being pedantic here a bit, but we could instead drop the cd and the script by setting the npm prefix, which is how you tell npm to act as if it is in that dir and do its resolution from there:
npm exec --prefix astro lint-stagedbut lint-staged does care about cwd for its config lookup, so to avoid cd we'd need...
npm exec --prefix astro lint-staged -- --cwd astroThat sucks though and is cursed lol, so cd is fine for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I accepted this because of performance. Since we are on Node 24, it is significantly faster than npx or npm run (it avoids the npm CLI startup overhead).
You're right that it requires the 'passthrough' script in package.json which is the trade off for that speed boost. I agree that the --prefix and --cwd alternatives feel a bit 'cursed' the current cd approach keeps it readable while staying fast. Once we move everything to the root, we can simplify this even further.