Skip to content

Commit a08cbc1

Browse files
committed
feat(scripts/commit-msg): support Husky 6 out of the box
Defaults to passing `--edit` with no value to **commitlint** when no arguments are passed.
1 parent cbae039 commit a08cbc1

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/scripts/__tests__/__snapshots__/commit-msg.js.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
exports[`commit-msg adds env flag with HUSKY_GIT_PARAMS when available 1`] = `commitlint --env HUSKY_GIT_PARAMS --config ./src/config/commitlint.config.js`;
44

5-
exports[`commit-msg calls @commitlint/cli with default args 1`] = `commitlint --config ./src/config/commitlint.config.js`;
5+
exports[`commit-msg calls @commitlint/cli with default args 1`] = `commitlint --config ./src/config/commitlint.config.js --edit`;
6+
7+
exports[`commit-msg defaults to \`--edit\` when no args are passed and HUSKY_GIT_PARAMS is not available 1`] = `commitlint --config ./src/config/commitlint.config.js --edit`;
68

79
exports[`commit-msg does not use built-in config with --config 1`] = `commitlint --config ./custom-config.js`;
810

9-
exports[`commit-msg does not use built-in config with commitlint.config.js file 1`] = `commitlint`;
11+
exports[`commit-msg does not use built-in config with commitlint.config.js file 1`] = `commitlint --edit`;
1012

1113
exports[`commit-msg forwards args 1`] = `commitlint --config ./src/config/commitlint.config.js --edit .git/COMMIT_EDITMSG`;

src/scripts/__tests__/commit-msg.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,8 @@ cases(
6262
'adds env flag with HUSKY_GIT_PARAMS when available': {
6363
env: {HUSKY_GIT_PARAMS: 'husky-git-params'},
6464
},
65+
'defaults to `--edit` when no args are passed and HUSKY_GIT_PARAMS is not available': {
66+
env: {HUSKY_GIT_PARAMS: undefined, args: []},
67+
},
6568
},
6669
)

src/scripts/commit-msg.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const useBuiltinConfig =
1414
!hasFile('commitlint.config.js')
1515

1616
const env = huskyGitParams ? ['--env', 'HUSKY_GIT_PARAMS'] : []
17+
const defaultEdit = !huskyGitParams && args.length === 0 ? ['--edit'] : []
1718

1819
const config = useBuiltinConfig
1920
? ['--config', hereRelative('../config/commitlint.config.js')]
2021
: []
2122

2223
const result = spawn.sync(
2324
resolveBin('@commitlint/cli', {executable: 'commitlint'}),
24-
[...env, ...config, ...args],
25+
[...env, ...config, ...args, ...defaultEdit],
2526
{
2627
stdio: 'inherit',
2728
},

0 commit comments

Comments
 (0)