Commitlint: [input] is required: supply via stdin, or --env or --edit or --from and --to

Created on 17 Aug 2020  ·  16Comments  ·  Source: conventional-changelog/commitlint

Expected Behavior


Linter should work correctly

Current Behavior


Gives a help message

husky > pre-commit (node v14.8.0)
ℹ No staged files match any configured task.
husky > commit-msg (node v14.8.0)
@commitlint/[email protected] - Lint your commit messages

[input] reads from stdin if --edit, --env, --from and --to are omitted
...
[input] is required: supply via stdin, or --env or --edit or --from and --to
husky > commit-msg hook failed (add --no-verify to bypass)

Affected packages

  • [ ] cli
  • [ ] core
  • [ ] prompt
  • [x] config-angular

Possible Solution


Steps to Reproduce (for bugs)


Played from version @commitlint/[email protected] in version @commitlint/[email protected] works stably


.huskyrc

.huskyrc

{
  "hooks": {
    "commit-msg": "commitlint --extends=@commitlint/config-angular -e"
  }
}

Context


Your Environment

| Executable | Version |
| ---------------------: | :------ |
| commitlint --version | v9.1.2 |
| git --version | v2.25.0 |
| node --version | v14.8.0 |

bug

Most helpful comment

I hope this helps with identifying the issue. If you explicitly specify the default value it works as expected.

commitlint --edit ./.git/COMMIT_EDITMSG

An empty string works as well.

commitlint --edit ''

Therefore my guess is that it is somehow related to the switch from meow to yargs. Maybe yargs handles default arguments a little different.

All 16 comments

Played from version @commitlint/[email protected] in version @commitlint/[email protected] works stably

Is this a typo?

Played from version @commitlint/[email protected] in version @commitlint/[email protected] works stably

Is this a typo?

Yep, changet to 'Played from version @commitlint/[email protected] in version @commitlint/[email protected] works stably'

@escapedcat Any ETA on a fix? This is breaking all of our release pipelines right now. 😬

Sorry, not really. We need to find time to look into this. If this is blocking you please fix your version to 9.1.1 for now till we updated this.

I hope this helps with identifying the issue. If you explicitly specify the default value it works as expected.

commitlint --edit ./.git/COMMIT_EDITMSG

An empty string works as well.

commitlint --edit ''

Therefore my guess is that it is somehow related to the switch from meow to yargs. Maybe yargs handles default arguments a little different.

@chrisguttandin thanks a lot! That is very helpful information!

@chrisguttandin Looks like it's exactly what you guessed :)

./@commitlint/cli/cli.js --edit:

yargs flags:  {
  _: [],
  edit: false,
  e: false,
  color: true,
  c: true,
  cwd: '/Users/foo/src/commitlint',
  d: '/Users/foo/src/commitlint',
  quiet: false,
  q: false,
  '$0': '@commitlint/cli/cli.js'
}

./@commitlint/cli/cli.js --edit '':

yargs flags:  {
  _: [],
  edit: '',
  e: '',
  color: true,
  c: true,
  cwd: '/Users/foo/src/commitlint',
  d: '/Users/foo/src/commitlint',
  quiet: false,
  q: false,
  '$0': '@commitlint/cli/cli.js'
}

How to handle this in a nice way? If there's no way within the code to know if the arg is set maybe just updating the help text will work?:

  --edit, -e           read last commit message from the specified file or use '' as 
                       fallback to ./.git/COMMIT_EDITMSG
                                                    [string] [default: false]

Maybe in combination with requiresArg: true:

edit: {
    alias: 'e',
    default: false,
    description:
        "read last commit message from the specified file or use '' as fallback to ./.git/COMMIT_EDITMSG",
    type: 'string',
    requiresArg: true,
},

Which would add another info to the output

Not enough arguments following: edit

./@commitlint/cli/cli.js --edit

@commitlint/[email protected] - Lint your commit messages

[input] reads from stdin if --edit, --env, --from and --to are omitted

Options:
  --color, -c          toggle colored output           [boolean] [default: true]
  --config, -g         path to the config file                          [string]
  --cwd, -d            directory to execute in
                                         [string] [default: (Working Directory)]
  --edit, -e           read last commit message from the specified file or use
                       '' as fallback to ./.git/COMMIT_EDITMSG
                                                       [string] [default: false]
  --env, -E            check message in the file at path given by environment
                       variable value                                   [string]
  --extends, -x        array of shareable configurations to extend       [array]
  --help-url, -H       help url in error message                        [string]
  --from, -f           lower end of the commit range to lint; applies if
                       edit=false                                       [string]
  --format, -o         output format of the results                     [string]
  --parser-preset, -p  configuration preset to use for
                       conventional-commits-parser                      [string]
  --quiet, -q          toggle console output          [boolean] [default: false]
  --to, -t             upper end of the commit range to lint; applies if
                       edit=false                                       [string]
  --verbose, -V        enable verbose output for reports without problems
                                                                       [boolean]
  -v, --version        display version information                     [boolean]
  -h, --help           Show help                                       [boolean]

Not enough arguments following: edit

I guess this would be a breaking change.

What about removing the default value from the configuration of yargs and setting it in L115 instead?

main({ edit: false, ...cli.argv }).catch((err) => {

It's a bit clunky but I think it will preserve the previous behavior.

Sorry, not really. We need to find time to look into this. If this is blocking you please fix your version to 9.1.1 for now till we updated this.

I use the package version is 9.1.1 recently,only today install this package in new project,I found this's not work. At last,I found the version is updated to 9.1.2... And then,I try to revert the last version is work normal.

I use the package version is 9.1.1 recently,only today install this package in new project,I found this's not work. At last,I found the version is updated to 9.1.2... And then,I try to revert the last version is work normal.

对不起,我真不明白你的意思。你的评论和这个issue有关系吗?我们试一试解决这个issue。

What about removing the default value from the configuration of yargs and setting it in L115 instead?

main({ edit: false, ...cli.argv }).catch((err) => {

It's a bit clunky but I think it will preserve the previous behavior.

Thanks @chrisguttandin! Could it be enough to just remove the default: false from the yargs-config? Not sure why this would need to be explicit false in a way.

@escapedcat I'm very new to this codebase. I haven't had a look at it before encountering this issue. So everything I say could be wrong. However it looks to me that the rest of the code expects edit to be false by default.

I use the package version is 9.1.1 recently,only today install this package in new project,I found this's not work. At last,I found the version is updated to 9.1.2... And then,I try to revert the last version is work normal.

对不起,我真不明白你的意思。你的评论和这个issue有关系吗?我们试一试解决这个issue。

I want to say that I has the same problem.

@chrisguttandin, your suggestion was applied and released v11.0.0 (it's breaking for other reasons) under the next tag.

At everyone here, please give this a try and let us know if this works for you again:
npm i -D @commitlint/config-conventional@next @commitlint/cli@next

I just updated some of my repos and can confirm that it works again. Thanks a lot.

v11.0.0 has been released as @latest

Was this page helpful?
0 / 5 - 0 ratings