-
Notifications
You must be signed in to change notification settings - Fork 908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: footer-leading-blank complains with the number sign in the commit body #896
Comments
a\na#1
in commit body#
in commit body
#
in commit body
Thanks for reporting! I can see it's something related to parsing the commit. I think both Currently it's parsed to:
|
I also confirm this bug. |
Since this concerns the parser, I think there's also an issue with the parser not stripping out comments in the footer, see #846. |
Confirmed with the following spec complaint commit message:
|
I confirm this bug too with this commit message : chore(release): fix bug with npm and commitlint
Error: Cannot find module "@commitlint/config-conventional"
See: https://github.com/conventional-changelog/commitlint/issues/613#issuecomment-482794295 |
I can also confirm this with the message:
|
Maybe the following ANTLR grammar can be used to parse the commit message. ANTLR can generate code to parse the commit message. JavaScript is officially supported and a community driven generator for TypeScript also exists. The grammar below is strongly based upon the conventional commits specification. grammar ConventionalCommits;
// needed to allow carriage returns not followed by a line feed
CARRIAGE_RETURN
: '\r'
;
NEWLINE
: CARRIAGE_RETURN? '\n'
;
BREAKING_CHANGE_HEADER_INDICATOR
: '!'
;
// needed to allow hyphen which follows word(s) but has no trailing word (e.g. abc-def-)
INCOMPLETE_FOOTER_TOKEN
: (WORD '-')+
;
FOOTER_TOKEN
: INCOMPLETE_FOOTER_TOKEN WORD
| BREAKING_CHANGE_TOKEN
;
BREAKING_CHANGE_TOKEN
: 'BREAKING' (' ' | '-') 'CHANGE'
;
WORD
: [a-zA-Z][a-zA-Z0-9]*
;
// needed to allow colons not followed by a space
COLON
: ':'
;
// needed to allow spaces not followed by a hashtag
SPACE
: ' '
;
COLON_SPACE
: COLON SPACE
;
SPACE_HASHTAG
: SPACE '#'
;
commit
: header (NEWLINE body)? (NEWLINE footer)? EOF
;
header
: type enclosedScope? BREAKING_CHANGE_HEADER_INDICATOR? COLON_SPACE summary
;
type
: WORD
;
scope
: WORD
;
enclosedScope
: '(' scope ')'
;
summary
: nonEmptyLine
;
body
: nonEmptyNonFooterLine (NEWLINE* nonEmptyNonFooterLine)*?
;
line
: (~NEWLINE)*? NEWLINE
;
nonEmptyLine
: ~NEWLINE line
;
// a line which does not match a footer line (line != footer-token + footer-separator + footer-value)
nonEmptyNonFooterLine
: ~(FOOTER_TOKEN | WORD | NEWLINE) line
| (FOOTER_TOKEN | WORD) NEWLINE
| (FOOTER_TOKEN | WORD) ~(COLON_SPACE | SPACE_HASHTAG | NEWLINE) line
| (FOOTER_TOKEN | WORD) (COLON_SPACE | SPACE_HASHTAG) NEWLINE
;
footer
: footerEntry+?
;
footerEntry
: (FOOTER_TOKEN | WORD) (COLON_SPACE | SPACE_HASHTAG) footerValue
;
footerValue
: nonEmptyLine (NEWLINE* nonEmptyNonFooterLine)*?
; |
Since commitlint doesn't properly detect footers and max line lengths are an antipattern, this change will reduce false positive noise for no cost. See conventional-changelog/commitlint/issues/896
I think the idea in #896 (comment) is a good idea since it is very explicit about the grammar. Of course, I think a similar less explicit solution could also be built using regex directly. Do the maintainers have any opinion in case someone wants to submit a PR? |
I think this would need to be fixed in https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-commits-parser but they've not been that open about matching the conventional commit spec. I had forgotten but looked into this as part of conventional-changelog/conventional-changelog#415 (comment) If commitlint passes through a config to the parser then the work around there would work though ideally the parser would be updated to implement the spec as written (or maybe that's the job of an extension?) |
Parser Opts can be passed via the parser preset configuration: https://commitlint.js.org/#/reference-configuration?id=parser-presets |
Yeah, I agree. I think some of our issues are related to missing features in the parser. That's where they should be applied and fixed. Intead of trying to fix those in commitlint. But it feels like the bigger issue is that conventional-changelog is that the maintainers don't have much time atm. Last updates have been done in Dec 2021. |
Edit: This is now described in an own issue: #3120 Just in case someone tackles this at some point in the future: This message also fails (due to the comment in the body, not because it is a number sign):
|
This case might have a different root cause (though similar) since it complains about a leading blank line even if you add leading blank lines everywhere. It also correctly identifies the footer (in that demo app at least) even though it incorrectly says it's missing a leading line. If someone looks closer and root causes it, they may want to open a new issue if the root cause is not the same! |
Alright, I opened a new issue for the body-comment bug #3120 |
It is problematic to lint commits on upstream branches in case a commit with wrong format was pushed. Or when there is some bug in the linter, what is currently the case, see [1][2]. Make sure the linter is only always run on merge requests and for other branches. [1] conventional-changelog/commitlint#896 [2] https://gitlab.com/kwinft/wrapland/-/jobs/495110391 (cherry picked from commit 9980354)
Expected Behavior
The following commit message should pass the
footer-leading-blank
rule:Current Behavior
The above commit message, however, fails with the following:
This happens when the following conditions are true:
#
symbol is present in the commit bodyFor instance, the following example, taken from the spec, also triggers this bug:
Affected packages
Steps to Reproduce
commitlint --edit
commitlint.config.js
Context
I was referencing a GitHub issue in the standard GitHub format, which is #1234. This was inside a very detailed commit message with multiple lines.
Your Environment
commitlint --version
git --version
node --version
The text was updated successfully, but these errors were encountered: