Skip to content

Commit

Permalink
fix: enforce a lower case letter at the beginning of the summary content
Browse files Browse the repository at this point in the history
  • Loading branch information
aeyoll committed Jan 3, 2022
1 parent 43128d9 commit f9a6fc6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum ParseErrorKind {
UnexpectedWhitespaceOrNewLine,
MalformedScope,
MalformedOrUnexpectedFooterSeparator,
DescriptionStartingWithUppercase,
Other,
}

Expand All @@ -39,6 +40,9 @@ impl AsRef<str> 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",
}
}
Expand Down Expand Up @@ -72,6 +76,8 @@ impl From<PestError<Rule>> 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
}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.pest
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down
12 changes: 12 additions & 0 deletions tests/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit f9a6fc6

Please sign in to comment.