Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add pre-commit hook for conventional commits and linting #127

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = {
ecmaVersion: 2020,
project: "./tsconfig.json",
},
ignorePatterns: ["*.cjs"],
ignorePatterns: ["*.cjs", "!.lintstagedrc.js", ".lintstagedrc.js"],
plugins: ["@typescript-eslint"],
root: true,
env: {
Expand Down
3 changes: 3 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npx commitlint --edit $1
3 changes: 3 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

npx lint-staged
14 changes: 14 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Check if commit message is provided with -m flag
COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2

# Check if commit is being created from the message source (e.g., with `git commit -m`)
if echo "$HUSKY_GIT_PARAMS" | grep -qE '^-m\s'; then
if [ "$COMMIT_SOURCE" = "message" ]; then
exit 0
fi
fi

exec < /dev/tty && npx git-cz --hook || true
8 changes: 8 additions & 0 deletions .lintstagedrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("path");
const buildEslintCommand = (filenames) =>
`next lint --fix --file ${filenames
.map((f) => path.relative(process.cwd(), f))
.join(" --file ")}`;
module.exports = {
"*.{js,jsx,ts,tsx}": [buildEslintCommand],
};
47 changes: 47 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import type { UserConfig } from '@commitlint/types';

const Configuration: UserConfig = {
extends: ['@commitlint/config-conventional'],
parserPreset: 'conventional-changelog-atom',
formatter: '@commitlint/format',
rules: {
'type-enum': [
2,
'always',
[
'feat', // New feature
'fix', // Bug fix
'docs', // Documentation changes
'style', // Changes that do not affect the meaning of the code (white-space, formatting, etc.)
'refactor', // Code changes that neither fix a bug nor add a feature
'perf', // Performance improvement
'test', // Adding missing tests or correcting existing tests
'build', // Changes that affect the build system or external dependencies (example scopes: npm)
'ci', // Changes to CI configuration files and scripts
'chore', // Other changes that don't modify src or test files
'revert', // Reverts a previous commit
],
],
'scope-enum': [
2,
'always',
[
'setup', // Project setup
'config', // Configuration files
'deps', // Dependency updates
'feature', // Feature-specific changes
'bug', // Bug fixes
'docs', // Documentation
'style', // Code style/formatting
'refactor', // Code refactoring
'test', // Tests
'build', // Build scripts or configuration
'ci', // Continuous integration
'release', // Release related changes
'other', // Other changes
],
],
},
};

export default Configuration;
Loading
Loading