commitlint: Can't run commitlint on project with tsconfig.json
When running commitlint
on a typeScript project, I have an error because commitlint
use the project tsconfig.json
.
Expected Behavior
commitlint
should not use the project typeScript configuration.
Current Behavior
commitlint
produce the following traceback:
/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:843
return new TSError(diagnosticText, diagnosticCodes, diagnostics);
^
TSError: ⨯ Unable to compile TypeScript:
error TS6053: File '@loopback/build/config/tsconfig.common.json' not found.
at createTSError (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:843:12)
at reportTSError (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:847:19)
at createFromPreloadedConfig (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:858:36)
at create (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:613:10)
at register (/usr/local/lib/node_modules/commitlint/node_modules/ts-node/src/index.ts:580:15)
at TypeScriptLoader (/usr/local/lib/node_modules/commitlint/node_modules/cosmiconfig-typescript-loader/dist/loader.js:7:51)
at loadConfig (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/load/src/utils/load-config.ts:35:27)
at load (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/load/src/load.ts:25:33)
at main (/usr/local/lib/node_modules/commitlint/node_modules/@commitlint/cli/src/cli.ts:199:27)
at processTicksAndRejections (node:internal/process/task_queues:95:5) {
diagnosticCodes: [ 6053 ]
}
Affected packages
- cli
- core
- prompt
- config-angular
Possible Solution
Steps to Reproduce (for bugs)
- clone the repository https://gitlab.mim-libre.fr/alphabet/laboite-blog-api.git
- execute
commitlint --from HEAD~2 --to HEAD
commitlint.config.js
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [2, 'always', 120],
'footer-max-line-length': [2, 'always', 120],
'header-max-length': [2, 'always', 72],
},
};
Context
We upgraded our commitlint
container for our CI and now all typeScript project are failling.
Your Environment
Executable | Version |
---|---|
commitlint --version |
16.3.0 |
git --version |
2.36.1 |
node --version |
18.4.0 |
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 25
- Comments: 19 (5 by maintainers)
Commits related to this issue
- fix(scripts/commit-msg): prevent commitlint from ever type-checking configuration **@commitlint/cli** added support for TypeScript-based configurations via `ts-node`, and that has caused a good deal ... — committed to hoverinc/hover-javascript by jrolfs a year ago
- ci: fix commitlint issue Refs: conventional-changelog/commitlint#3256 — committed to phnx47/hvst-cli by phnx47 a year ago
I’m getting the same UTF-16 file after following docs https://commitlint.js.org/#/guides-local-setup?id=install-commitlint with command
Error log:
The problem is solved after changing the file encoding to UTF-8 manually.
Just check the encoding of index.ts. In my case, somehow it was UTF-16. Once I changed it to UTF-8 (in Notepad++) - the problem is gone.
Reopening because of #3641 This will then hopefully be fixed with a new mayor version. yolo
@TimeCoder Can you be a little more specific? Which index.ts file has this problem? I badly need to resolve this conflict
My error message still is:
When I use the latest array values in my tsconfig/extends, I encounter this error. However, when I change it to a string, the error disappears. Therefore, I believe it’s an issue with ts-node not supporting parsing of the latest ts configuration. Perhaps upgrading ts-node version could resolve this problem?
🤔 It seems that we suffer from the same problem for the okp4/team-wiki project. The temporary solution was to delete the
tsconfig.json
file while linting the github action.I managed to work around this issue by
cd /tmp
and executecommitlint --cwd /my/sources
It looks like yes, I’m not sure it’s a good idea for
commitlint
to load the project configuration but I don’t know how to prevent that.