1
Fork 0
mirror of https://github.com/RGBCube/alejandra synced 2025-08-01 04:57:44 +00:00

feat: run cargo clippy

This commit is contained in:
Kevin Amado 2022-02-06 17:24:24 -05:00
parent 030f965a55
commit 34aeeee544
No known key found for this signature in database
GPG key ID: FFF341057F503148
4 changed files with 22 additions and 27 deletions

View file

@ -131,7 +131,7 @@ fn build_step(
} }
} }
crate::builder::Step::Token(kind, text) => { crate::builder::Step::Token(kind, text) => {
add_token(builder, build_ctx, *kind, &text); add_token(builder, build_ctx, *kind, text);
} }
crate::builder::Step::Whitespace => { crate::builder::Step::Whitespace => {
add_token( add_token(

View file

@ -123,7 +123,7 @@ impl Children {
} }
fn dedent_comment(pos: &crate::position::Position, text: &str) -> String { fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
if text.starts_with("#") { if text.starts_with('#') {
text.to_string() text.to_string()
} else { } else {
let mut lines: Vec<String> = text[2..text.len() - 2] let mut lines: Vec<String> = text[2..text.len() - 2]
@ -132,7 +132,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
.collect(); .collect();
// If all lines are whitespace just return a compact comment // If all lines are whitespace just return a compact comment
if lines.iter().all(|line| line.trim().len() == 0) { if lines.iter().all(|line| line.trim().is_empty()) {
return "/**/".to_string(); return "/**/".to_string();
} }
@ -143,7 +143,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
if lines.len() == 1 { if lines.len() == 1 {
lines.insert(0, "".to_string()); lines.insert(0, "".to_string());
lines[1] = format!("{0:<1$}{2}", "", pos.column + 2, lines[1]); lines[1] = format!("{0:<1$}{2}", "", pos.column + 2, lines[1]);
} else if lines[0].trim().len() == 0 { } else if lines[0].trim().is_empty() {
lines[0] = "".to_string(); lines[0] = "".to_string();
} else { } else {
lines.insert(0, format!("{0:<1$}", "", pos.column + 1)); lines.insert(0, format!("{0:<1$}", "", pos.column + 1));
@ -157,7 +157,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
let len = lines.len(); let len = lines.len();
if len == 2 { if len == 2 {
lines.push(format!("{0:<1$}", "", pos.column + 1)); lines.push(format!("{0:<1$}", "", pos.column + 1));
} else if lines[len - 1].trim().len() == 0 { } else if lines[len - 1].trim().is_empty() {
lines[len - 1] = format!("{0:<1$}", "", pos.column + 1) lines[len - 1] = format!("{0:<1$}", "", pos.column + 1)
} else { } else {
lines.push(format!("{0:<1$}", "", pos.column + 1)); lines.push(format!("{0:<1$}", "", pos.column + 1));
@ -172,7 +172,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
if index != 0 && index + 1 != lines.len() { if index != 0 && index + 1 != lines.len() {
let line = line.trim_end(); let line = line.trim_end();
if line.len() > 0 { if !line.is_empty() {
indentation = usize::min( indentation = usize::min(
indentation, indentation,
line.len() - line.trim_start().len(), line.len() - line.trim_start().len(),
@ -191,20 +191,17 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
.map(|(index, line)| { .map(|(index, line)| {
if index == 0 || index + 1 == lines.len() { if index == 0 || index + 1 == lines.len() {
line.to_string() line.to_string()
} else if pos.column >= indentation {
format!(
"{0:<1$}{2}",
"",
pos.column - indentation + 1,
line,
)
} else if line.len() >= indentation - pos.column {
line[indentation - pos.column - 1..line.len()].to_string()
} else { } else {
if pos.column >= indentation { line.to_string()
format!(
"{0:<1$}{2}",
"",
pos.column - indentation + 1,
line,
)
} else if line.len() >= indentation - pos.column {
line[indentation - pos.column - 1..line.len()]
.to_string()
} else {
line.to_string()
}
} }
}) })
.collect(); .collect();
@ -221,7 +218,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
.map(|(index, line)| { .map(|(index, line)| {
if index == 0 { if index == 0 {
line.to_string() line.to_string()
} else if line.len() >= pos.column + 1 { } else if line.len() > pos.column {
line[pos.column + 1..line.len()].to_string() line[pos.column + 1..line.len()].to_string()
} else { } else {
line.to_string() line.to_string()

View file

@ -60,7 +60,6 @@ pub fn rule(
| rnix::SyntaxKind::NODE_PAREN | rnix::SyntaxKind::NODE_PAREN
| rnix::SyntaxKind::NODE_STRING = next | rnix::SyntaxKind::NODE_STRING = next
.element .element
.clone()
.into_node() .into_node()
.unwrap() .unwrap()
.children() .children()
@ -81,7 +80,6 @@ pub fn rule(
} else if let rnix::SyntaxKind::NODE_LAMBDA = next_kind { } else if let rnix::SyntaxKind::NODE_LAMBDA = next_kind {
if let rnix::SyntaxKind::NODE_PATTERN = next if let rnix::SyntaxKind::NODE_PATTERN = next
.element .element
.clone()
.into_node() .into_node()
.unwrap() .unwrap()
.children() .children()

View file

@ -53,7 +53,7 @@ pub fn rule(
content.split('\n').map(|line| line.to_string()).collect(); content.split('\n').map(|line| line.to_string()).collect();
let should_trim_end: bool = let should_trim_end: bool =
lines.len() >= 1 && lines[lines.len() - 1].trim().len() == 0; !lines.is_empty() && lines[lines.len() - 1].trim().is_empty();
let mut lines: Vec<String> = lines let mut lines: Vec<String> = lines
.iter() .iter()
@ -72,7 +72,7 @@ pub fn rule(
for line in lines.iter() { for line in lines.iter() {
let line = line.trim_end(); let line = line.trim_end();
if line.len() > 0 { if !line.is_empty() {
indentation = usize::min( indentation = usize::min(
indentation, indentation,
line.len() - line.trim_start().len(), line.len() - line.trim_start().len(),
@ -97,12 +97,12 @@ pub fn rule(
// Indent everything 2 spaces // Indent everything 2 spaces
if lines.len() > 1 if lines.len() > 1
&& lines.iter().filter(|line| line.trim().len() > 0).count() >= 1 && lines.iter().filter(|line| !line.trim().is_empty()).count() >= 1
{ {
lines = lines lines = lines
.iter() .iter()
.map(|line| { .map(|line| {
if line.trim().len() > 0 { if !line.trim().is_empty() {
format!(" {}", line) format!(" {}", line)
} else { } else {
line.to_string() line.to_string()
@ -121,7 +121,7 @@ pub fn rule(
.collect(); .collect();
if portions.len() == 1 { if portions.len() == 1 {
if portions[0].len() > 0 || index + 1 == lines.len() { if !portions[0].is_empty() || index + 1 == lines.len() {
if lines.len() > 1 { if lines.len() > 1 {
steps.push_back(crate::builder::Step::Pad); steps.push_back(crate::builder::Step::Pad);
} }