Forráskód Böngészése

chore: add pre-push linter hook (#632)

Alvaro Saburido 1 éve
szülő
commit
2605442799
5 módosított fájl, 50 hozzáadás és 1 törlés
  1. 5 0
      .github/workflows/actions/pnpm/action.yml
  2. 8 0
      .husky/install.mjs
  3. 25 0
      .husky/pre-push
  4. 3 1
      package.json
  5. 9 0
      pnpm-lock.yaml

+ 5 - 0
.github/workflows/actions/pnpm/action.yml

@@ -25,3 +25,8 @@ runs:
     - name: install dependencies
       run: pnpm install --shamefully-hoist
       shell: bash
+
+# Avoid running husky hooks on Github
+# http://typicode.github.io/husky/how-to.html
+env:
+  HUSKY: 0

+ 8 - 0
.husky/install.mjs

@@ -0,0 +1,8 @@
+// Skip Husky install in production and CI
+// http://typicode.github.io/husky/how-to.html
+if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') {
+  process.exit(0)
+}
+const husky = (await import('husky')).default
+// eslint-disable-next-line no-console
+console.log(husky())

+ 25 - 0
.husky/pre-push

@@ -0,0 +1,25 @@
+# NOTE: Don't fail immediately after error
+# This allows us to echo messages even if the linter exits with an error.
+set +e  
+
+# NOTE: --silent to keep pnpm from echoing, e.g., "> @tresjs/core[...] lint" 
+# --max-warnings=0 to fail on errors *and* warnings
+pnpm --silent lint --max-warnings=0
+
+# NOTE: Capture linter exit status.
+LINT_STATUS=$?
+
+# NOTE: If linting failed, inform user how to proceed.
+if [[ $LINT_STATUS != 0 ]]; then
+  echo "
+To fix linter problems:
+  pnpm lint --fix  – fix automatically fixable problems
+  pnpm lint        – print a list of problems to fix by hand
+
+To skip this verification and push anyway (not recommended):
+  git push --no-verify <...>
+"
+fi
+
+# NOTE: +e was set, so we have to return an exit status.
+exit $LINT_STATUS

+ 3 - 1
package.json

@@ -59,7 +59,8 @@
     "docs:build": "vitepress build docs",
     "docs:serve": "vitepress serve docs",
     "docs:preview": "vitepress preview docs",
-    "docs:contributors": "esno scripts/update-contributors.ts"
+    "docs:contributors": "esno scripts/update-contributors.ts",
+    "prepare": "node .husky/install.mjs"
   },
   "peerDependencies": {
     "three": ">=0.133",
@@ -87,6 +88,7 @@
     "eslint-plugin-vue": "^9.19.2",
     "esno": "^4.0.0",
     "gsap": "^3.12.3",
+    "husky": "^9.0.11",
     "jsdom": "^24.0.0",
     "kolorist": "^1.8.0",
     "ohmyfetch": "^0.4.21",

+ 9 - 0
pnpm-lock.yaml

@@ -66,6 +66,9 @@ importers:
       gsap:
         specifier: ^3.12.3
         version: 3.12.5
+      husky:
+        specifier: ^9.0.11
+        version: 9.0.11
       jsdom:
         specifier: ^24.0.0
         version: 24.0.0
@@ -6116,6 +6119,12 @@ packages:
     engines: {node: '>=16.17.0'}
     dev: true
 
+  /husky@9.0.11:
+    resolution: {integrity: sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==}
+    engines: {node: '>=18'}
+    hasBin: true
+    dev: true
+
   /iconv-lite@0.4.24:
     resolution: {integrity: sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==}
     engines: {node: '>=0.10.0'}