Skip to content

Commit

Permalink
feat(sage-monorepo): configure pre-commit hooks to format and lint fi…
Browse files Browse the repository at this point in the history
…les (#2801)
  • Loading branch information
tschaffter authored Sep 11, 2024
1 parent 3291185 commit 5c6b163
Show file tree
Hide file tree
Showing 8 changed files with 237 additions and 50 deletions.
3 changes: 0 additions & 3 deletions .husky/post-checkout
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

node tools/prepare-nodejs-envs.js
node tools/prepare-java-envs.js
node tools/prepare-python-envs.js
Expand Down
3 changes: 0 additions & 3 deletions .husky/post-merge
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Install the Node.js dependencies.
# rm -rf node_modules && yarn install --immutable
node tools/prepare-nodejs-envs.js
Expand Down
3 changes: 0 additions & 3 deletions .husky/post-rewrite
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

node tools/prepare-nodejs-envs.js
node tools/prepare-java-envs.js
node tools/prepare-python-envs.js
Expand Down
7 changes: 3 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
# Run formatters and linters against staged git files
pnpm dlx lint-staged --relative

nx affected --uncommitted --target=format
nx affected --uncommitted --target=lint
# nx affected --uncommitted --target=lint

# Re-index the staged files after they have been formatted
# git diff --name-only --cached | xargs -l git add
3 changes: 0 additions & 3 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# yarn nx affected --target=test
# yarn nx affected --target=integration-test
14 changes: 14 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// lint-staged.config.js

module.exports = {
// Format JavaScript, TypeScript, and JSX/TSX files first, then lint
'**/*.{js,jsx,ts,tsx}': (filenames) => [
// Format files with Prettier first
`prettier --write ${filenames.join(' ')}`,
// Then run ESLint on the formatted files
`nx affected --target=lint --files=${filenames.join(',')}`,
],

// Format JSON, Markdown, and YAML files
'**/*.{json,md,yaml,yml}': (filenames) => [`nx format:write --files=${filenames.join(',')}`],
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@
"eslint-plugin-playwright": "^0.15.3",
"eslint-plugin-promise": "6.1.1",
"glob": "8.0.3",
"google-java-format": "1.1.0",
"hint": "7.1.3",
"husky": "8.0.2",
"husky": "9.1.5",
"ibm-openapi-validator": "1.7.0",
"jest": "29.4.3",
"jest-environment-jsdom": "29.4.3",
"jest-preset-angular": "14.1.1",
"lint-staged": "15.2.10",
"ng-packagr": "18.0.0",
"ngx-echarts": "16.0.0",
"nock": "13.2.9",
Expand Down
Loading

0 comments on commit 5c6b163

Please sign in to comment.