Skip to content

Commit ee953b0

Browse files
committed
Merge branch 'lint' into 'master'
Lint See merge request mkjeldsen/commitmsgfmt!85
2 parents dd54b92 + 1398bc3 commit ee953b0

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

src/main.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ impl<'a> From<io::Error> for CliError<'a> {
8888
impl fmt::Display for CliError<'_> {
8989
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9090
match *self {
91-
CliError::ArgUnrecognized(ref s) => write!(f, "Found argument '{}'", s),
91+
CliError::ArgUnrecognized(ref s) => write!(f, "Found argument '{s}'"),
9292
CliError::ArgWidthNaN(ref w) => {
93-
write!(f, "--width: must be a positive integer, was: '{}'", w)
93+
write!(f, "--width: must be a positive integer, was: '{w}'")
9494
}
9595
CliError::ArgWidthOutOfBounds(ref w) => {
96-
write!(f, "--width: must be greater than 0, was: '{}'", w)
96+
write!(f, "--width: must be greater than 0, was: '{w}'")
9797
}
9898
CliError::EarlyExit(ref s) => s.fmt(f),
9999
CliError::Io(ref err) => err.fmt(f),
@@ -119,7 +119,7 @@ impl Termination for CliError<'_> {
119119
fn report(self) -> ExitCode {
120120
match self {
121121
CliError::EarlyExit(s) => {
122-
println!("{}", s);
122+
println!("{s}");
123123
ExitCode::SUCCESS
124124
}
125125
CliError::Io(ref e) if e.kind() == io::ErrorKind::BrokenPipe => {
@@ -128,7 +128,7 @@ impl Termination for CliError<'_> {
128128
ExitCode::from(ret)
129129
}
130130
_ => {
131-
eprintln!("fatal: {}", self);
131+
eprintln!("fatal: {self}");
132132
ExitCode::FAILURE
133133
}
134134
}

src/parser.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,10 @@ pub fn parse<'a>(input: &'a str, comment_string: &str) -> Vec<Token<'a>> {
6565
} else if let Some(fence) = line_as_code_fence(line) {
6666
toks.push(Token::FencedCodeBlock(line));
6767
in_code_fence = Some(fence);
68-
} else if line.starts_with(comment_string) {
69-
let index = comment_string.len();
70-
let t = if &line[index..] == " ------------------------ >8 ------------------------" {
68+
} else if let Some(t) = line_as_comment_or_scissor(line, comment_string) {
69+
if let Token::Scissored(_) = t {
7170
has_scissors = true;
72-
Token::Scissored(line)
73-
} else if line[index..].starts_with(" ignore-rest") {
74-
has_scissors = true;
75-
Token::Scissored(line)
76-
} else {
77-
Token::Comment(line)
78-
};
71+
}
7972
toks.push(t);
8073
} else if is_line_blank_or_whitespace(line) {
8174
if toks.last() != Some(&Token::VerticalSpace) {
@@ -179,6 +172,22 @@ fn extend_prose_buffer_with_line<'input>(
179172
None
180173
}
181174

175+
fn line_as_comment_or_scissor<'a>(line: &'a str, comment_string: &str) -> Option<Token<'a>> {
176+
line.strip_prefix(comment_string).map(|comment_suffix| {
177+
match is_comment_suffix_scissor_marker(comment_suffix) {
178+
true => Token::Scissored(line),
179+
false => Token::Comment(line),
180+
}
181+
})
182+
}
183+
184+
fn is_comment_suffix_scissor_marker(comment_suffix: &str) -> bool {
185+
// https://git-scm.com/docs/git-commit#Documentation/git-commit.txt-scissors
186+
// https://github.com/jj-vcs/jj/blob/v0.31.0/cli/src/description_util.rs#L162
187+
comment_suffix == " ------------------------ >8 ------------------------"
188+
|| comment_suffix.starts_with(" ignore-rest")
189+
}
190+
182191
fn is_line_blank_or_whitespace(line: &str) -> bool {
183192
line.chars().all(char::is_whitespace)
184193
}
@@ -260,7 +269,7 @@ fn is_line_trailer(line: &str) -> bool {
260269
}
261270
}
262271

263-
fn line_as_list_item(line: &str) -> Option<Token> {
272+
fn line_as_list_item(line: &str) -> Option<Token<'_>> {
264273
enum LiState {
265274
New,
266275
IndentSp1,
@@ -349,7 +358,7 @@ fn line_as_list_item(line: &str) -> Option<Token> {
349358
})
350359
}
351360

352-
fn line_as_code_fence(line: &'_ str) -> Option<CodeFence> {
361+
fn line_as_code_fence(line: &str) -> Option<CodeFence<'_>> {
353362
enum FenceState {
354363
New,
355364
IndentSp1,
@@ -407,7 +416,7 @@ fn line_as_code_fence(line: &'_ str) -> Option<CodeFence> {
407416
}
408417
}
409418

410-
fn line_as_line_block_quote(line: &str) -> Option<Token> {
419+
fn line_as_line_block_quote(line: &str) -> Option<Token<'_>> {
411420
if line.starts_with('>') {
412421
Some(Token::BlockQuote(line))
413422
} else {
@@ -422,7 +431,7 @@ mod tests {
422431

423432
use pretty_assertions::assert_eq;
424433

425-
fn parse(s: &str) -> Vec<Token> {
434+
fn parse(s: &str) -> Vec<Token<'_>> {
426435
super::parse(s, "#")
427436
}
428437

src/worditer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ mod tests {
120120

121121
type Item<'text> = <WordIter<'text> as Iterator>::Item;
122122

123-
fn iter(text: &str) -> WordIter {
123+
fn iter(text: &str) -> WordIter<'_> {
124124
WordIter::new(text, "#")
125125
}
126126

127127
fn collect(it: WordIter) -> Vec<Item> {
128128
it.collect()
129129
}
130130

131-
fn iter_collect(text: &str) -> Vec<Item> {
131+
fn iter_collect(text: &str) -> Vec<Item<'_>> {
132132
collect(iter(text))
133133
}
134134

0 commit comments

Comments
 (0)