Skip to content

Commit b54bd1c

Browse files
chore: add lint-staged with pre-commit hooks for src/ directory
- Upgrade husky from 8.0.3 to 9.1.7 - Add lint-staged 16.2.3 for automated code quality checks - Configure lint-staged to run eslint and prettier on src/**/*.{ts,tsx} - Update pre-commit hook to use lint-staged - Add post-checkout hook for automatic dependency installation - Add pre-push hook to prevent direct pushes to main branch This matches the setup in jupyterlab-deepnote for consistency.
1 parent f59e68f commit b54bd1c

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

.husky/post-checkout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm install

.husky/pre-commit

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1 @@
1-
#!/bin/sh
2-
if npm list prettier | grep -q prettier@ ; then
3-
echo husky - prettier is installed
4-
else
5-
echo husky - prettier is not installed, skipping format check
6-
exit 0
7-
fi
8-
9-
# run prettier on all .ts files that are in the commit
10-
changed=$(git diff --diff-filter=ACM --cached --name-only | grep .ts$ | tr '\n' ' ')
11-
12-
if [ -z "$changed" ]; then
13-
echo husky - No modified files to check
14-
exit 0
15-
fi
16-
17-
npx prettier $changed --check
1+
npm exec lint-staged

.husky/pre-push

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
branch_name="$(git symbolic-ref --short HEAD)"
2+
if [ "$branch_name" = "main" ]; then
3+
echo "Pushing directly to main is not allowed."
4+
exit 1
5+
fi

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,6 +2075,7 @@
20752075
"package": "gulp clean && npm run build && vsce package -o ms-toolsai-jupyter-insiders.vsix",
20762076
"postdownload-api": "npx vscode-dts main",
20772077
"postinstall": "npm run download-api && node ./build/ci/postInstall.js",
2078+
"prepare": "husky",
20782079
"pretest:integration:nonpython": "cross-env VSC_JUPYTER_CI_TEST_VSC_CHANNEL=insiders node ./out/test/datascience/dsTestSetup.js",
20792080
"pretest:integration": "node ./out/test/datascience/dsTestSetup.js",
20802081
"pretest:performance:execution": "cross-env VSC_JUPYTER_CI_TEST_GREP=@executionPerformance node ./out/test/datascience/dsTestSetup.js",
@@ -2258,12 +2259,13 @@
22582259
"gulp": "^5.0.0",
22592260
"gulp-filter": "^7.0.0",
22602261
"gulp-rename": "^2.0.0",
2261-
"husky": "^8.0.3",
2262+
"husky": "9.1.7",
22622263
"json2csv": "^5.0.7",
22632264
"jsonschema": "^1.4.1",
22642265
"keyv": "^4.1.0",
22652266
"less": "^4.1.3",
22662267
"less-plugin-inline-urls": "^1.2.0",
2268+
"lint-staged": "16.2.3",
22672269
"lolex": "^6.0.0",
22682270
"lru-cache": "^10.0.0",
22692271
"mocha": "^11.0.1",
@@ -2290,6 +2292,12 @@
22902292
"utf-8-validate": "^5.0.8",
22912293
"util": "^0.12.4"
22922294
},
2295+
"lint-staged": {
2296+
"src/**/*.{ts,tsx}": [
2297+
"eslint --cache --fix",
2298+
"prettier --write"
2299+
]
2300+
},
22932301
"optionalDependencies": {
22942302
"fsevents": "^2.3.2"
22952303
},

0 commit comments

Comments
 (0)