Fix clippy::if_not_else (pedantic)

https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg 2022-11-21 17:55:13 -08:00 committed by Charlie Marsh
parent 9462335371
commit 68668c20e8
6 changed files with 63 additions and 63 deletions

View file

@ -208,10 +208,10 @@ pub fn check_lines(
let mut invalid_codes = vec![];
let mut valid_codes = vec![];
for code in codes {
if !matches.contains(&code) {
invalid_codes.push(code.to_string());
} else {
if matches.contains(&code) {
valid_codes.push(code.to_string());
} else {
invalid_codes.push(code.to_string());
}
}

View file

@ -428,10 +428,10 @@ pub fn format_imports(
let import_block = sort_imports(import_block);
// Add a blank line between every section.
if !is_first_block {
output.append("\n");
} else {
if is_first_block {
is_first_block = false;
} else {
output.append("\n");
}
let mut is_first_statement = true;

View file

@ -90,7 +90,9 @@ pub fn check_imports(
end_location: Location::new(range.end_location.row() + 1, 0),
};
let actual = dedent(&locator.slice_source_code_range(&range));
if actual != expected {
if actual == expected {
None
} else {
let mut check = Check::new(CheckKind::UnsortedImports, range);
if autofix.patch() && settings.fixable.contains(check.kind.code()) {
check.amend(Fix::replacement(
@ -100,8 +102,6 @@ pub fn check_imports(
));
}
Some(check)
} else {
None
}
}
}

View file

@ -945,51 +945,7 @@ fn blanks_and_section_underline(
.chars()
.all(|char| char.is_whitespace() || char == '-');
if !dash_line_found {
if checker.settings.enabled.contains(&CheckCode::D407) {
let mut check = Check::new(
CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()),
Range::from_located(docstring),
);
if checker.patch(check.kind.code()) {
// Add a dashed line (of the appropriate length) under the section header.
let content = format!(
"{}{}\n",
whitespace::clean(&whitespace::indentation(checker, docstring)),
"-".repeat(context.section_name.len())
);
check.amend(Fix::insertion(
content,
Location::new(docstring.location.row() + context.original_index + 1, 0),
));
}
checker.add_check(check);
}
if blank_lines_after_header > 0 {
if checker.settings.enabled.contains(&CheckCode::D412) {
let mut check = Check::new(
CheckKind::NoBlankLinesBetweenHeaderAndContent(
context.section_name.to_string(),
),
Range::from_located(docstring),
);
if checker.patch(check.kind.code()) {
// Delete any blank lines between the header and content.
check.amend(Fix::deletion(
Location::new(docstring.location.row() + context.original_index + 1, 0),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
0,
),
));
}
checker.add_check(check);
}
}
} else {
if dash_line_found {
if blank_lines_after_header > 0 {
if checker.settings.enabled.contains(&CheckCode::D408) {
let mut check = Check::new(
@ -1146,6 +1102,50 @@ fn blanks_and_section_underline(
));
}
}
} else {
if checker.settings.enabled.contains(&CheckCode::D407) {
let mut check = Check::new(
CheckKind::DashedUnderlineAfterSection(context.section_name.to_string()),
Range::from_located(docstring),
);
if checker.patch(check.kind.code()) {
// Add a dashed line (of the appropriate length) under the section header.
let content = format!(
"{}{}\n",
whitespace::clean(&whitespace::indentation(checker, docstring)),
"-".repeat(context.section_name.len())
);
check.amend(Fix::insertion(
content,
Location::new(docstring.location.row() + context.original_index + 1, 0),
));
}
checker.add_check(check);
}
if blank_lines_after_header > 0 {
if checker.settings.enabled.contains(&CheckCode::D412) {
let mut check = Check::new(
CheckKind::NoBlankLinesBetweenHeaderAndContent(
context.section_name.to_string(),
),
Range::from_located(docstring),
);
if checker.patch(check.kind.code()) {
// Delete any blank lines between the header and content.
check.amend(Fix::deletion(
Location::new(docstring.location.row() + context.original_index + 1, 0),
Location::new(
docstring.location.row()
+ context.original_index
+ 1
+ blank_lines_after_header,
0,
),
));
}
checker.add_check(check);
}
}
}
}

View file

@ -239,13 +239,13 @@ pub fn break_outside_loop(stmt: &Stmt, parents: &[&Stmt], parent_stack: &[usize]
}
}
if !allowed {
if allowed {
None
} else {
Some(Check::new(
CheckKind::BreakOutsideLoop,
Range::from_located(stmt),
))
} else {
None
}
}
@ -279,12 +279,12 @@ pub fn continue_outside_loop(
}
}
if !allowed {
if allowed {
None
} else {
Some(Check::new(
CheckKind::ContinueOutsideLoop,
Range::from_located(stmt),
))
} else {
None
}
}

View file

@ -59,10 +59,10 @@ impl FilePattern {
};
let absolute = Pattern::new(&absolute_path.to_string_lossy())?;
let basename = if !pattern.contains(std::path::MAIN_SEPARATOR) {
Some(Pattern::new(pattern)?)
} else {
let basename = if pattern.contains(std::path::MAIN_SEPARATOR) {
None
} else {
Some(Pattern::new(pattern)?)
};
Ok(FilePattern::Complex(absolute, basename))