Skip to content
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

fix: enforce a lower case letter at the beginning of the summary content #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}