diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 000000000..c1122febe --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1 @@ +node tools/validate-eslint.js \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 12cc21d8e..1b7de5be2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -39,6 +39,7 @@ "globals": "^15.0.0", "html-entities": "^2.3.3", "html-webpack-plugin": "^5.6.0", + "husky": "^9.1.7", "license-check-and-add": "^4.0.5", "mocha": "^10.6.0", "nodemon": "^3.1.0", @@ -12159,6 +12160,22 @@ "ms": "^2.0.0" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/ico-endec": { "version": "0.1.6", "resolved": "https://registry.npmjs.org/ico-endec/-/ico-endec-0.1.6.tgz", @@ -20377,7 +20394,7 @@ }, "src/puter-js": { "name": "@heyputer/puter.js", - "version": "2.0.12", + "version": "2.0.13", "license": "Apache-2.0", "dependencies": { "@heyputer/kv.js": "^0.1.92", diff --git a/package.json b/package.json index 128534d54..f9bcbc732 100644 --- a/package.json +++ b/package.json @@ -21,6 +21,7 @@ "globals": "^15.0.0", "html-entities": "^2.3.3", "html-webpack-plugin": "^5.6.0", + "husky": "^9.1.7", "license-check-and-add": "^4.0.5", "mocha": "^10.6.0", "nodemon": "^3.1.0", @@ -33,7 +34,8 @@ "start=gui": "nodemon --exec \"node dev-server.js\" ", "start": "node ./tools/run-selfhosted.js", "build": "cd src/gui; node ./build.js", - "check-translations": "node tools/check-translations.js" + "check-translations": "node tools/check-translations.js", + "prepare": "husky" }, "workspaces": [ "src/*", @@ -70,4 +72,4 @@ "engines": { "node": ">=20.0.0" } -} \ No newline at end of file +} diff --git a/tools/validate-eslint.js b/tools/validate-eslint.js new file mode 100644 index 000000000..79207b8ca --- /dev/null +++ b/tools/validate-eslint.js @@ -0,0 +1,36 @@ +// This script does not validate that eslint rules are followed; it only +// ensures that the eslint configuration is valid. When there are errors +// present in the eslint configuration, vscode pretends everything is +// fine and that there are no linter errors in any files. + +import { ESLint } from 'eslint'; + +async function validateConfig() { + let exitWithError = false; + + try { + const eslint = new ESLint(); + await eslint.lintText('', { filePath: 'src/gui/**/*.js' }); + } catch (error) { + console.error('❌ ESLint configuration error (general):', error.message); + exitWithError = true; + } + + try { + const eslint = new ESLint(); + await eslint.lintText('', { filePath: 'src/backend/**/*.js' }); + } catch (error) { + console.error('❌ ESLint configuration error (backend):', error.message); + exitWithError = true; + } + + if ( exitWithError ) { + console.log('\x1B[36;1mYou should edit eslint.config.js to resolve this issue.\x1B[0m'); + console.log('\x1B[31;1mIf this is an emergency, use `git commit --no-verify`.\x1B[0m'); + process.exit(1); + } + + console.log('✅ ESLint configuration is valid'); +} + +validateConfig();