Skip to content

Commit

Permalink
👩‍💻 dx: Set up commitlint.
Browse files Browse the repository at this point in the history
Fixes #805.
  • Loading branch information
make-github-pseudonymous-again committed Mar 17, 2024
1 parent 01d1c40 commit 6a251fc
Show file tree
Hide file tree
Showing 4 changed files with 849 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

function ask () {

# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.

# http://djm.me/ask

if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi

while true; do

# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "

# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read REPLY </dev/tty

# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi

# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac

done

}

while ! npm run commit-msg -- "$1" ; do
if [ -t 1 ] && ask 'There was an error. Do you wish to amend your commit message?' Y ; then
${GIT_EDITOR:-$EDITOR} "$1" < /dev/tty
else
exit 1
fi
done
76 changes: 76 additions & 0 deletions commitlint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* Commit Lint
*
* Rules are made up by a name and a configuration array.
* The configuration array contains:
* 1. Level: | [0..2] | 0 = disables | 1 = considered a warning | 2 an error for the rule.
* 2. Applicable: | always/never | never inverts the rule.
* 3. Value: | value to use for this rule.
*
* @link https://github.com/conventional-changelog/commitlint/blob/master/docs/reference/rules-configuration.md
*/

export default {
parserPreset: {
parserOpts: {
headerPattern: /^:[a-z\d_]+: (\w+)(?:\((.+)\))?!?: (.+)$/,
breakingHeaderPattern: /^:boom: (\w+)(?:\((.+)\))?!: (.+)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING CHANGE'],
revertPattern:
/^:wastebasket: revert:\s"?([\s\S]+?)"?\s*this reverts commit (\w+)\./i,
revertCorrespondence: ['header', 'hash'],
issuePrefixes: ['#'],
},
},
rules: {
'header-max-length': [2, 'always', 79],
'body-max-line-length': [2, 'always', 79],
'footer-max-line-length': [2, 'always', 79],
'type-empty': [2, 'never'],
'type-case': [2, 'always', 'lower-case'],
'type-enum': [
2,
'always',
[
'a11y',
'bug',
'chore',
'cleaning',
'config',
'deprecate',
'deps',
'docs',
'dx',
'experiment',
'feat',
'fix',
'i18n',
'idea',
'initial',
'license',
'merge',
'perf',
'progress',
'refactor',
'release',
'revert',
'security',
'style',
'test',
'trash',
'typo',
'ui',
'ux',
],
],
'scope-case': [0, 'always', 'lower-case'],
'subject-empty': [2, 'never'],
'subject-case': [2, 'always', 'sentence-case'],
'subject-full-stop': [2, 'always', '.'],
'body-leading-blank': [2, 'always'],
'body-empty': [0, 'never'],
'body-full-stop': [2, 'always', '.'],
'footer-leading-blank': [2, 'always'],
},
};
Loading

0 comments on commit 6a251fc

Please sign in to comment.