commitlint: Windows line endings in config breaks CLI

Expected Behavior

If you have windows line endings in your config file, things should run as normal

Current Behavior

If you run the recommended echo command on Windows, it will break things as it will output Windows Line Endings.

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

Add support for windows line endings in CLI

Steps to Reproduce (for bugs)

  1. Open Windows machine
  2. Run echo "module.exports = {extends: ['@commitlint/config-angular']};" > commitlint.config.js
  3. Run commitlint

Context

Trying to setup commitlint in my project on Windows

Your Environment

Executable Version
commitlint --version 5.6.0
git --version git version 2.16.0.windows.2
node --version v8.9.1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (4 by maintainers)

Most upvoted comments

On Windows, must through the notepad to open the file,Through the save as, change document character set!

1644603589(1)

for anyone still coming back after this long, i had the issue and i fixed it after 30m of head smashing

Get-Content commitlint.config.js | Set-Content -Encoding utf8 commitlint.config-utf8.js

for windows then delete original and rename new (so it doesnt say used by another process)

The default config of encoding of VSCode in my machine is UTF-16 LE. I met the same problem when executing scripts in the VSCode terminal (powershell) as @crutchcorn did. It was just solved after I changed the encoding to UTF-8.

I fumbled around with the file (thanks for providing it!) and my tests indicate this is not caused by \r\n line endings.

It is the encoding, which is UTF-16 LE. cosmiconfig assumes config files are encoded in UTF-8 and consequently feeds a string with invalid characters to require-from-string.

There is nothing commitlint can do to support UTF-16 LE encoded files. I guess the cosmiconfig won’t add support for other encodings, so your best bet will be to ensure config files are UTF-8 encoded.