diff --git a/src/error.rs b/src/error.rs index b62e58d..304639d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -18,6 +18,7 @@ pub enum ParseErrorKind { UnexpectedWhitespaceOrNewLine, MalformedScope, MalformedOrUnexpectedFooterSeparator, + DescriptionStartingWithUppercase, Other, } @@ -39,6 +40,9 @@ impl AsRef for ParseErrorKind { "Either token separator (` #` or `: `) \ \nis missing from the footer or a footer was not expected at this point" } + ParseErrorKind::DescriptionStartingWithUppercase => { + "Malformed commit description: message should start with a lowercase letter" + } ParseErrorKind::Other => "Parse error", } } @@ -72,6 +76,8 @@ impl From> for ParseError { ParseErrorKind::MalformedScope } else if positives.contains(&Rule::token_separator) { ParseErrorKind::MalformedOrUnexpectedFooterSeparator + } else if positives.contains(&Rule::summary_content) { + ParseErrorKind::DescriptionStartingWithUppercase } else { ParseErrorKind::Other } diff --git a/src/grammar.pest b/src/grammar.pest index 8af44f9..ec27e4e 100644 --- a/src/grammar.pest +++ b/src/grammar.pest @@ -1,4 +1,4 @@ -summary_content = { (!NEWLINE ~ ANY)+ } +summary_content = { LOWERCASE ~ (!NEWLINE ~ ANY)+ } message = { SOI ~ summary ~ (blank_line* ~ (footers | (body ~ blank_line+ ~ footers) | body))? ~ EOI } diff --git a/tests/specification.rs b/tests/specification.rs index ac92383..553bdaa 100644 --- a/tests/specification.rs +++ b/tests/specification.rs @@ -535,3 +535,15 @@ fn should_parse_interactively_rebased_commit() { }, ); } + +#[test] +fn description_with_sentence_case_should_fail() { + // Arrange + let commit_message = "feat: Toto va à la plage"; + + // Act + let parsed = parse(commit_message); + + // Assert + assert_error(&parsed, ParseErrorKind::DescriptionStartingWithUppercase); +}