feat(lint): allow for custom commit parser function#4829
Conversation
Code Review by Qodo
Context used 1. Custom parser crashes rules
|
PR Summary by Qodofeat(lint): allow custom commit parser function in lint options WalkthroughsDescription• Add optional custom parser function to lint options • Forward custom parser into @commitlint/parse for message parsing • Add tests to verify rule evaluation uses custom parser output Diagramgraph TD
A["Consumer config"] --> B["lint(message, rules, opts)"] --> C["@commitlint/parse"] --> D{{"conventional-commits-parser"}} --> E["parsed commit object"] --> F["rules engine"]
A --> G["custom parser (optional)"] --> C
subgraph Legend
direction LR
_cfg["Config/Input"] ~~~ _mod["Module"] ~~~ _ext{{"External"}}
end
High-Level AssessmentThe following are alternative approaches to this PR: 1. Support a custom conventional-commits-parser instance/options only
2. Introduce a commit AST schema + adapter layer
3. Add a dedicated 'parse' hook at rule-evaluation boundary
Recommendation: The chosen approach (optional custom parser function passed through lint → parse) is the best incremental solution: it unblocks users immediately while preserving the existing default path. To keep this safe long-term, ensure the Parser type clearly documents required/optional fields (e.g., header/body/footer nullability) and consider validating/normalizing custom parser output before rules run. File ChangesEnhancement (2)
Tests (1)
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan |
47c6498 to
97c5cf3
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds support for supplying a custom commit parser function to @commitlint/lint, passing it through to @commitlint/parse so commit messages can be parsed with higher fidelity before rule evaluation.
Changes:
- Extend
LintOptionsto accept an optionalparserfunction (typed via@commitlint/types). - Pass the custom parser from
@commitlint/lintinto@commitlint/parse. - Add documentation and tests covering custom parser usage.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| docs/reference/configuration.md | Documents configuring a custom parser function (plus related parser expectations). |
| @commitlint/types/src/lint.ts | Adds parser?: Parser to LintOptions type. |
| @commitlint/lint/src/lint.ts | Forwards opts.parser into parse(message, parser, parserOpts). |
| @commitlint/lint/src/lint.test.ts | Adds tests validating that a provided custom parser affects lint results. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks, could you adjust this to multiple commits to follow a TDD approach?
Further feedback from Claude:
Please also check if the feedback from copilot is valid and should be tackled or comment on it |
😕 do you think it should be tackled as the maintainer? Given that typescript has no runtime benefit, it makes no difference to me |
|
Please adjust the comments in TDD way first. Regarding the AI feedback. I don't want you to tackle every one of them. I first want you to evaluate and either fix or comment on each why it's not worth it/needed. Once we have this out of the way I take a look. |
97c5cf3 to
d207ae9
Compare
|
We first need the test commit to fail the CI then you can push the "fix" |
8d4e2bd to
b94fa9d
Compare
|
Is this the expected error?: Run pnpm build
$ tsc -b
Error: @commitlint/lint/src/lint.test.ts(328,5): error TS2353: Object literal may only specify known properties, and 'parser' does not exist in type 'LintOptions'.
Error: @commitlint/lint/src/lint.test.ts(350,5): error TS2353: Object literal may only specify known properties, and 'parser' does not exist in type 'LintOptions'.
Error: @commitlint/lint/src/lint.test.ts(384,5): error TS2353: Object literal may only specify known properties, and 'parser' does not exist in type 'LintOptions'.
[ELIFECYCLE] Command failed with exit code 2.
Error: Process completed with exit code 2. |
At this point, yes it would be. just added the tests. no implementation changes |
|
Can you the if the build works with adding just the type signature
|
That is the only code change. So it would kind of defeat the purpose of having two commits |
|
If you don't mind I can give it a try tomorrow. Would be nice to achieve a state where we have failing tests without your later fix. |
|
I don't mind at all. To me this isn't really a fix to anything - its a new feature. proving that it doesn't work seems odd to me |
b94fa9d to
1d4963d
Compare
|
Adjusted minimal and force-pushed. Build is green and tests are running. Would be nice to see all 3 tests failing. Further feedback in cooperation with Claude:
|
|
what is it that we're trying to accomplish here? |
This adds tests to confirm that functionality for conventional-changelog#4816 doesn't exist and doesn't work
This change makes it possible to pass a custom function to the top level lint function, which is passed through to the parse function and consequently passed through to the parser exposed by convential-commits-parser. In linting it is important to parse content to be linted with a high level of fidelity so linting can be applied accurately. The default parser the is used, conventional-commits-parser makes many assumptions about the format of the commit to perform its parsing which leads to parsing errors and inaccuracies which in turn lead to many false positives in linting, and incorrect or invalid errors in additional confusing error messages. This change will allow end users utilize a more accurate parser for their linting purposes in the short term while issues with the default parser are reconciled Resolves: conventional-changelog#4816
e35f798 to
7c6fa59
Compare
|
In cooperation with Claude:
|
This change makes it possible to pass a custom function to the top level lint function, which is passed through to the parse function and consequently passed through to the parser exposed by convential-commits-parser. In linting it is important to parse content to be linted with a high level of fidelity so linting can be applied accurately. The default parser the is used, conventional-commits-parser makes many assumptions about the format of the commit to perform its parsing which leads to parsing errors and inaccuracies which in turn lead to many false positives in linting, and incorrect or invalid errors in additional confusing error messages.
This change will allow end users utilize a more accurate parser for their linting purposes in the short term while issues with the default parser are reconciled
Resolves: #4816
Description
Motivation and Context
Usage examples
How Has This Been Tested?
Added additional tests in the lint module passing a custom parser
Types of changes
allows a custom parse function to be passed in via lint through to >
@commitlint/parse>conventional-commits-parserChecklist: