Skip to content

Commit

Permalink
chore: initial setup for pre-commit, commitlinting (#67)
Browse files Browse the repository at this point in the history
* chore(lint): install githook, commit linting related packages

* chore(husky): add commit related githook for linting

* chore(lint): overide rules based on commit convention of side

* chore(lint): add custom english rule

* chore(husky): convert error message from korean into english
  • Loading branch information
froggy1014 authored Jan 2, 2025
1 parent 3d622d5 commit dd315c0
Show file tree
Hide file tree
Showing 6 changed files with 1,497 additions and 21 deletions.
1 change: 1 addition & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm commitlint --edit ${1}
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pnpm lint-staged
7 changes: 7 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# git commit -m 명령어를 사용할 때는 스킵
if [ -z "${2}" ]; then
exec < /dev/tty && pnpm cz --hook || {
echo "\nCommit has been cancelled."
exit 1
}
fi
39 changes: 39 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const englishOnly = /^[A-Za-z0-9\s!@#$%^&*(),.?":{}|<>_-]+$/;

// https://commitlint.js.org/reference/configuration.html#typescript-configuration
import { RuleConfigSeverity, type UserConfig } from '@commitlint/types';
const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
// parserPreset: '',
// formatter: '',
// https://commitlint.js.org/reference/plugins.html#working-with-plugins
plugins: [
{
rules: {
'subject-english-only': ({ subject }) => {
if (!subject) return [true, ''];
const valid = englishOnly.test(subject);
return [valid, 'Commit subject must contain only English characters'];
},
},
},
],
rules: {
// https://commitlint.js.org/reference/rules.html
'type-empty': [RuleConfigSeverity.Error, 'never'],
'subject-empty': [RuleConfigSeverity.Error, 'never'],
'subject-max-length': [RuleConfigSeverity.Error, 'always', 50],
'scope-max-length': [RuleConfigSeverity.Error, 'always', 20],

// custom rules
'subject-english-only': [RuleConfigSeverity.Error, 'always'],
},

prompt: {
settings: {},
messages: {},
questions: {},
},
};

export default Configuration;
22 changes: 21 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"private": true,
"type": "module",
"scripts": {
"prepare": "husky",
"cz": "cz",
"build:storybook": "storybook build",
"dev:storybook": "storybook dev -p 6006",
"create:component": "tsx scripts/createComponent.ts create",
Expand All @@ -11,6 +13,10 @@
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@changesets/cli": "^2.27.9",
"@commitlint/cli": "^19.6.1",
"@commitlint/config-conventional": "^19.6.0",
"@commitlint/cz-commitlint": "^19.6.1",
"@commitlint/types": "^19.5.0",
"@clack/prompts": "^0.9.0",
"@storybook/addon-essentials": "catalog:",
"@storybook/addon-interactions": "catalog:",
Expand All @@ -24,15 +30,29 @@
"@typescript-eslint/parser": "^8.19.0",
"@vitest/coverage-v8": "catalog:",
"chromatic": "^11.19.0",
"commitizen": "^4.3.1",
"clipanion": "4.0.0-rc.4",
"eslint": "^9.17.0",
"husky": "^9.1.7",
"knip": "catalog:",
"lint-staged": "^15.3.0",
"sanitize.css": "^13.0.0",
"storybook": "catalog:",
"tsx": "^4.19.2",
"tsup": "catalog:",
"typescript": "catalog:",
"vitest": "catalog:"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"lint-staged": {
"packages/*/src/**/*.{ts,tsx}": [
"biome lint --apply",
"eslint --fix --flag unstable_ts_config"
]
},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
}
}
Loading

0 comments on commit dd315c0

Please sign in to comment.