From 1e5859425f7f5cf49c56197a49c09437e335c706 Mon Sep 17 00:00:00 2001 From: olav Date: Thu, 2 Jun 2022 08:08:53 +0200 Subject: [PATCH] refactor: fix husky and lint-staged setup (#1654) --- .eslintrc | 12 +++--------- .husky/pre-commit | 4 ++++ package.json | 11 +++-------- scripts/husky-install.js | 3 +++ 4 files changed, 13 insertions(+), 17 deletions(-) create mode 100755 .husky/pre-commit create mode 100644 scripts/husky-install.js diff --git a/.eslintrc b/.eslintrc index c3a408f32a..8988e889d5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,10 +3,7 @@ "node": true, "jest": true }, - "extends": [ - "airbnb-typescript/base", - "plugin:prettier/recommended" - ], + "extends": ["airbnb-typescript/base", "plugin:prettier/recommended"], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2019, @@ -32,10 +29,7 @@ "new-cap": [ "error", { - "capIsNewExceptions": [ - "Router", - "Mitm" - ] + "capIsNewExceptions": ["Router", "Mitm"] } ] }, @@ -56,5 +50,5 @@ } } ], - "ignorePatterns": ["**/docs/api/oas/", "examples/**"] + "ignorePatterns": ["**/docs/api/oas/", "examples/**", "scripts/**"] } diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000000..d24fdfc601 --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx lint-staged diff --git a/package.json b/package.json index 91e4169c65..7d1a707f53 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "build:watch": "tsc -w", "prebuild": "yarn run clean", "build": "yarn run copy-templates && tsc --pretty", - "prepare": "yarn run build", + "prepare": "node scripts/husky-install && yarn run build", "test": "NODE_ENV=test PORT=4243 jest", "test:unit": "NODE_ENV=test PORT=4243 jest --testPathIgnorePatterns=src/test/e2e/**", "test:docker": "./scripts/docker-postgres.sh", @@ -180,18 +180,13 @@ "json-schema": "^0.4.0" }, "lint-staged": { - "*.js": [ + "*.{js,ts}": [ "eslint --fix" ], - "*.{json,css,md}": [ + "*.{json,yaml,md}": [ "prettier --write" ] }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, "prettier": { "proseWrap": "never", "singleQuote": true, diff --git a/scripts/husky-install.js b/scripts/husky-install.js new file mode 100644 index 0000000000..d6b5e76ee8 --- /dev/null +++ b/scripts/husky-install.js @@ -0,0 +1,3 @@ +if (!process.env.CI) { + require('husky').install(); +}