From 5ecc2bccb73e8b676190268b932dc686e61ce2b8 Mon Sep 17 00:00:00 2001 From: Iaroslav Gryshaiev Date: Sat, 20 Apr 2024 16:12:12 +0200 Subject: [PATCH] fix(ts): does not add ts hooks by default (#152) feat(code-style): adds staged make code style targets Co-authored-by: Artur Troian --- Makefile | 1 + make/code-style.mk | 13 +++++++++++++ script/gofmt-staged.sh | 8 ++++++++ ts/.husky/pre-commit | 1 - ts/package-lock.json | 16 ---------------- ts/package.json | 13 +++---------- 6 files changed, 25 insertions(+), 27 deletions(-) create mode 100644 make/code-style.mk create mode 100755 script/gofmt-staged.sh delete mode 100644 ts/.husky/pre-commit diff --git a/Makefile b/Makefile index eaad4f1c..3f7ca8e1 100644 --- a/Makefile +++ b/Makefile @@ -83,6 +83,7 @@ include $(AKASH_ROOT)/make/test.mk include $(AKASH_ROOT)/make/codegen.mk include $(AKASH_ROOT)/make/lint.mk include $(AKASH_ROOT)/make/release-ts.mk +include $(AKASH_ROOT)/make/code-style.mk .PHONY: clean clean: diff --git a/make/code-style.mk b/make/code-style.mk new file mode 100644 index 00000000..5557c3a2 --- /dev/null +++ b/make/code-style.mk @@ -0,0 +1,13 @@ +MODULES ?= go \ +ts + +.PHONY: code-style-staged +code-style-staged: $(patsubst %, code-style-staged-%,$(MODULES)) + +.PHONY: code-style-staged-ts +code-style-staged-ts: $(AKASH_TS_NODE_MODULES) + ts/node_modules/.bin/lint-staged --cwd ts + +.PHONY: code-style-staged-go +code-style-staged-go: + script/gofmt-staged.sh diff --git a/script/gofmt-staged.sh b/script/gofmt-staged.sh new file mode 100755 index 00000000..08785df9 --- /dev/null +++ b/script/gofmt-staged.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +for file in $(git diff --cached --name-only --diff-filter=ACMRTUXB | grep "\.go$") +do + echo "(gofmt) $file" + gofmt -w "$file" + git add "$file" +done \ No newline at end of file diff --git a/ts/.husky/pre-commit b/ts/.husky/pre-commit deleted file mode 100644 index 510ae0b2..00000000 --- a/ts/.husky/pre-commit +++ /dev/null @@ -1 +0,0 @@ -ts/node_modules/.bin/lint-staged --cwd ts diff --git a/ts/package-lock.json b/ts/package-lock.json index cf390b95..3bbfc1d6 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -20,7 +20,6 @@ "conventional-changelog-conventionalcommits": "^7.0.2", "eslint": "^8.57.0", "eslint-plugin-simple-import-sort": "^12.0.0", - "husky": "^9.0.11", "jest": "^29.7.0", "lint-staged": "^15.2.2", "prettier": "^3.2.5", @@ -4870,21 +4869,6 @@ "node": ">=16.17.0" } }, - "node_modules/husky": { - "version": "9.0.11", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", - "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", - "dev": true, - "bin": { - "husky": "bin.mjs" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/ignore": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", diff --git a/ts/package.json b/ts/package.json index 4910470d..3beda469 100644 --- a/ts/package.json +++ b/ts/package.json @@ -13,7 +13,6 @@ "conventional-changelog-conventionalcommits": "^7.0.2", "eslint": "^8.57.0", "eslint-plugin-simple-import-sort": "^12.0.0", - "husky": "^9.0.11", "jest": "^29.7.0", "lint-staged": "^15.2.2", "prettier": "^3.2.5", @@ -28,19 +27,14 @@ "license": "Apache-2.0", "lint-staged": { "*.{js,jsx,ts,tsx}": [ - "npm run test", "npm run lint:fix", "npm run format" ], "package.json": [ - "script/remove-exports.js", - "sort-json package.json" + "script/remove-exports.js" ], - "tsconfig.build.json": [ - "sort-json tsconfig.build.json" - ], - "tsconfig.json": [ - "sort-json tsconfig.json" + "*.json": [ + "sort-json" ] }, "main": "dist/index.js", @@ -56,7 +50,6 @@ "lint": "eslint src", "lint:fix": "npm run lint -- --fix", "postbuild": "script/generate-exports.js", - "prepare": "cd .. && husky ts/.husky", "test": "jest --selectProjects unit functional", "test:cov": "jest --selectProjects unit functional --coverage", "test:functional": "jest --selectProjects functional",