Skip to content

Commit

Permalink
chore: set up commit hooks (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk authored Sep 16, 2023
1 parent ce21d87 commit 48638ab
Show file tree
Hide file tree
Showing 6 changed files with 2,211 additions and 47 deletions.
1 change: 1 addition & 0 deletions .husky/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit "$1"
16 changes: 16 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# copied from: https://prettier.io/docs/en/precommit.html#option-5-shell-script

FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0

# Prettify all selected files
echo "$FILES" | xargs ./node_modules/.bin/prettier --ignore-unknown --write

# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add

exit 0

22 changes: 22 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { RuleConfigSeverity } = require('@commitlint/types');
const {
utils: { getProjects },
} = require('@commitlint/config-nx-scopes');

/** @type {import('@commitlint/types').UserConfig} */
const configuration = {
extends: ['@commitlint/config-conventional'],
rules: {
'scope-enum': async ctx => {
const projects = await getProjects(
ctx,
({ name, projectType, tags }) =>
projectType === 'library' || projectType === 'application',
);
const scopes = [...projects, 'tools', 'workflows', 'testing'].sort();
return [RuleConfigSeverity.Error, 'always', scopes];
},
},
};

module.exports = configuration;
Loading

0 comments on commit 48638ab

Please sign in to comment.