diff --git a/docs/3.-Contributing-to-JPlag.md b/docs/3.-Contributing-to-JPlag.md index dc967f659e..de0647876f 100644 --- a/docs/3.-Contributing-to-JPlag.md +++ b/docs/3.-Contributing-to-JPlag.md @@ -20,3 +20,8 @@ Please try to make well-documented and clear structured submissions: Run `mvn clean package assembly:single` instead if you need the full jar which includes all dependencies. 5. You will find the generated JARs in the subdirectory `jplag.cli/target`. +### Git hooks + +The repository contains a pre-commit hook, that prevents commits if fail spotless. +To set up the hooks, call `git config --local core.hooksPath gitHooks/hooks` once within your local repository. + diff --git a/gitHooks/hooks/pre-commit b/gitHooks/hooks/pre-commit new file mode 100755 index 0000000000..7796838649 --- /dev/null +++ b/gitHooks/hooks/pre-commit @@ -0,0 +1,42 @@ +#!/bin/sh + +echo "Running pre commit checks" + +hasJavaFiles=0 +hasJsFiles=0 + +files=`git diff --name-only --cached` +while read name +do + if [[ $name == report-viewer* ]] + then + hasJsFiles=1 + fi + + if [[ $name == *.java ]] + then + hasJavaFiles=1 + fi +done <<< "$files" + +if [[ $hasJsFiles -gt 0 ]] +then + echo "Running report viewer pre commit checks" + cd report-viewer + ../gitHooks/scripts/reportViewerPreCommit + if [ $? -gt 0 ] + then + exit 1 + fi + cd .. +fi + +if [[ $hasJavaFiles -gt 0 ]] +then + echo "Running java pre commit checks" + gitHooks/scripts/javaPreCommit + if [ $? -gt 0 ] + then + exit 1 + fi +fi diff --git a/gitHooks/scripts/javaPreCommit b/gitHooks/scripts/javaPreCommit new file mode 100755 index 0000000000..19076694d7 --- /dev/null +++ b/gitHooks/scripts/javaPreCommit @@ -0,0 +1,19 @@ +#!/bin/bash + +if ! command -v mvn &> /dev/null #checks if maven is installed +then + echo "Maven is not installed. Spotless will not be checked" + exit 0 +fi + +#prevents the shell from aborting if maven returns a non zero exit code +set +e +echo Checking spotless +mvn spotless:check &> /dev/null +exitCode=$? + +if [ $exitCode -gt 0 ] +then + echo "Spotless failed. Please run 'mvn spotless:apply' to fix." +fi +exit $exitCode diff --git a/gitHooks/scripts/reportViewerPreCommit b/gitHooks/scripts/reportViewerPreCommit new file mode 100755 index 0000000000..502b47cb33 --- /dev/null +++ b/gitHooks/scripts/reportViewerPreCommit @@ -0,0 +1,9 @@ +#!/bin/bash + +if ! command -v npm &> /dev/null #checks if npm is installed +then + echo "Npm is not installed. Linter check will be skipped" + exit 0 +fi + +npx lint-staged diff --git a/report-viewer/.husky/pre-commit b/report-viewer/.husky/pre-commit deleted file mode 100644 index b4eb63f65d..0000000000 --- a/report-viewer/.husky/pre-commit +++ /dev/null @@ -1,2 +0,0 @@ -cd ./report-viewer -npx lint-staged \ No newline at end of file diff --git a/report-viewer/package-lock.json b/report-viewer/package-lock.json index 2e8f0da621..e328ce47b5 100644 --- a/report-viewer/package-lock.json +++ b/report-viewer/package-lock.json @@ -38,7 +38,6 @@ "autoprefixer": "^10.4.20", "eslint": "^8.57.0", "eslint-plugin-vue": "^9.27.0", - "husky": "^9.1.5", "jsdom": "^24.1.1", "lint-staged": "^15.2.9", "npm-run-all": "^4.1.5", @@ -6115,12 +6114,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/sortablejs": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.2.tgz", - "integrity": "sha512-FJF5jgdfvoKn1MAKSdGs33bIqLi3LmsgVTliuX6iITj834F+JRQZN90Z93yql8h0K2t0RwDPBmxwlbZfDcxNZA==", - "peer": true - }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -6731,7 +6724,7 @@ "version": "5.5.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", - "devOptional": true, + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/report-viewer/package.json b/report-viewer/package.json index 98e85a0d04..2b8648b064 100644 --- a/report-viewer/package.json +++ b/report-viewer/package.json @@ -16,7 +16,7 @@ "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --max-warnings 0", "format": "prettier --write src/", - "prepare": "cd .. && husky report-viewer/.husky" + "prepare": "git config --local core.hooksPath gitHooks/hooks" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.6.0", @@ -49,7 +49,6 @@ "autoprefixer": "^10.4.20", "eslint": "^8.57.0", "eslint-plugin-vue": "^9.27.0", - "husky": "^9.1.5", "jsdom": "^24.1.1", "lint-staged": "^15.2.9", "npm-run-all": "^4.1.5",