chore: added linting and license checking
This commit is contained in:
parent
ab7952af02
commit
1fd32f4b36
19
.git-hooks/commit-msg
Executable file
19
.git-hooks/commit-msg
Executable file
@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# Get the commit message (the parameter we're given is just the path to the
|
||||||
|
# temporary file which holds the message).
|
||||||
|
commit_message=$(cat "$1")
|
||||||
|
|
||||||
|
if (echo "$commit_message" | grep -Eq "^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z0-9 \-]+\))?!?: .+$") then
|
||||||
|
tput setaf 2;
|
||||||
|
echo "✔ Commit message meets Conventional Commit standards"
|
||||||
|
tput sgr0;
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
tput setaf 1;
|
||||||
|
echo "❌ Commit message does not meet the Conventional Commit standard!"
|
||||||
|
tput sgr0;
|
||||||
|
echo "An example of a valid message is:"
|
||||||
|
echo " feat(login): add the 'remember me' button"
|
||||||
|
echo "📝 More details at: https://www.conventionalcommits.org/en/v1.0.0/#summary"
|
||||||
|
exit 1
|
17
.git-hooks/pre-commit
Executable file
17
.git-hooks/pre-commit
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Avoid commits to the master branch
|
||||||
|
BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
|
REGEX="^(master|main|staging|development)$"
|
||||||
|
|
||||||
|
if [[ "$BRANCH" =~ $REGEX ]]; then
|
||||||
|
echo "You are on branch $BRANCH. Are you sure you want to commit to this branch?"
|
||||||
|
echo "If so, commit with -n to bypass the pre-commit hook."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Lint staged files
|
||||||
|
npm run lint-staged
|
||||||
|
|
||||||
|
# Run license-checker
|
||||||
|
npm run license-checker
|
@ -23,6 +23,12 @@ jobs:
|
|||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
|
|
||||||
|
- name: License check
|
||||||
|
run: npm run license-checker
|
||||||
|
|
||||||
|
- name: Lint check
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
- name: Formatter check
|
- name: Formatter check
|
||||||
run: npm run formatter:check
|
run: npm run formatter:check
|
||||||
|
|
||||||
|
12
eslint.config.mjs
Normal file
12
eslint.config.mjs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { defineConfig } from "eslint/config";
|
||||||
|
import globals from "globals";
|
||||||
|
import js from "@eslint/js";
|
||||||
|
import tseslint from "typescript-eslint";
|
||||||
|
|
||||||
|
|
||||||
|
export default defineConfig([
|
||||||
|
{ files: ["**/*.{js,mjs,cjs,ts}"] },
|
||||||
|
{ files: ["**/*.{js,mjs,cjs,ts}"], languageOptions: { globals: globals.node } },
|
||||||
|
{ files: ["**/*.{js,mjs,cjs,ts}"], plugins: { js }, extends: ["js/recommended"] },
|
||||||
|
tseslint.configs.recommended,
|
||||||
|
]);
|
28
licenseChecker.cjs
Normal file
28
licenseChecker.cjs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
const process = require('node:process')
|
||||||
|
const licenseChecker = require('license-checker')
|
||||||
|
|
||||||
|
const check = (cwd) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
licenseChecker.init(
|
||||||
|
{
|
||||||
|
production: true,
|
||||||
|
start: cwd,
|
||||||
|
excludePrivatePackages: true,
|
||||||
|
onlyAllow:
|
||||||
|
'AFLv2.1;Apache 2.0;Apache-2.0;Apache*;Artistic-2.0;0BSD;BSD*;BSD-2-Clause;BSD-3-Clause;BSD 3-Clause;CC0-1.0;CC-BY-3.0;CC-BY-4.0;ISC;MIT;MPL-2.0;ODC-By-1.0;Python-2.0;Unlicense;',
|
||||||
|
excludePackages: ''
|
||||||
|
},
|
||||||
|
(error, json) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error)
|
||||||
|
} else {
|
||||||
|
resolve(json)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
check(process.cwd(), true)
|
||||||
|
.then(() => console.log('All packages are licensed properly'))
|
||||||
|
.catch((err) => console.log('license checker err', err))
|
2279
package-lock.json
generated
2279
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
19
package.json
19
package.json
@ -9,7 +9,10 @@
|
|||||||
"test": "echo \"Error: no test specified\" && exit 1",
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
"formatter:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"formatter:check": "prettier --check \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
"formatter:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
"formatter:fix": "prettier --write \"src/**/*.{ts,tsx,js,jsx,html,css,sass,less,yml,md,graphql}\"",
|
||||||
"release": "commit-and-tag-version"
|
"formatter:staged": "prettier --write --ignore-unknown",
|
||||||
|
"release": "commit-and-tag-version",
|
||||||
|
"license-checker": "node licenseChecker.cjs",
|
||||||
|
"lint-staged": "lint-staged"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@ -23,6 +26,7 @@
|
|||||||
"express": "^4.21.2"
|
"express": "^4.21.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.23.0",
|
||||||
"@saithodev/semantic-release-gitea": "^2.1.0",
|
"@saithodev/semantic-release-gitea": "^2.1.0",
|
||||||
"@semantic-release/changelog": "^6.0.3",
|
"@semantic-release/changelog": "^6.0.3",
|
||||||
"@semantic-release/commit-analyzer": "^13.0.1",
|
"@semantic-release/commit-analyzer": "^13.0.1",
|
||||||
@ -32,9 +36,20 @@
|
|||||||
"@types/express": "^5.0.1",
|
"@types/express": "^5.0.1",
|
||||||
"@types/node": "^22.13.12",
|
"@types/node": "^22.13.12",
|
||||||
"concurrently": "^9.1.2",
|
"concurrently": "^9.1.2",
|
||||||
|
"eslint": "^9.23.0",
|
||||||
|
"globals": "^16.0.0",
|
||||||
|
"license-checker": "^25.0.1",
|
||||||
|
"lint-staged": "^15.5.0",
|
||||||
"nodemon": "^3.1.9",
|
"nodemon": "^3.1.9",
|
||||||
"prettier": "^3.5.3",
|
"prettier": "^3.5.3",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"typescript": "^5.8.2"
|
"typescript": "^5.8.2",
|
||||||
|
"typescript-eslint": "^8.28.0"
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{js,ts}": [
|
||||||
|
"npm run lint:staged"
|
||||||
|
],
|
||||||
|
"*.{ts,js,yml,md}": "npm run formatter:staged"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user