mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
feat: run cargo clippy
This commit is contained in:
parent
030f965a55
commit
34aeeee544
4 changed files with 22 additions and 27 deletions
|
@ -131,7 +131,7 @@ fn build_step(
|
|||
}
|
||||
}
|
||||
crate::builder::Step::Token(kind, text) => {
|
||||
add_token(builder, build_ctx, *kind, &text);
|
||||
add_token(builder, build_ctx, *kind, text);
|
||||
}
|
||||
crate::builder::Step::Whitespace => {
|
||||
add_token(
|
||||
|
|
|
@ -123,7 +123,7 @@ impl Children {
|
|||
}
|
||||
|
||||
fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
||||
if text.starts_with("#") {
|
||||
if text.starts_with('#') {
|
||||
text.to_string()
|
||||
} else {
|
||||
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();
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
|||
if lines.len() == 1 {
|
||||
lines.insert(0, "".to_string());
|
||||
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();
|
||||
} else {
|
||||
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();
|
||||
if len == 2 {
|
||||
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)
|
||||
} else {
|
||||
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() {
|
||||
let line = line.trim_end();
|
||||
|
||||
if line.len() > 0 {
|
||||
if !line.is_empty() {
|
||||
indentation = usize::min(
|
||||
indentation,
|
||||
line.len() - line.trim_start().len(),
|
||||
|
@ -191,20 +191,17 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
|||
.map(|(index, line)| {
|
||||
if index == 0 || index + 1 == lines.len() {
|
||||
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 {
|
||||
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 {
|
||||
line.to_string()
|
||||
}
|
||||
line.to_string()
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
@ -221,7 +218,7 @@ fn dedent_comment(pos: &crate::position::Position, text: &str) -> String {
|
|||
.map(|(index, line)| {
|
||||
if index == 0 {
|
||||
line.to_string()
|
||||
} else if line.len() >= pos.column + 1 {
|
||||
} else if line.len() > pos.column {
|
||||
line[pos.column + 1..line.len()].to_string()
|
||||
} else {
|
||||
line.to_string()
|
||||
|
|
|
@ -60,7 +60,6 @@ pub fn rule(
|
|||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_STRING = next
|
||||
.element
|
||||
.clone()
|
||||
.into_node()
|
||||
.unwrap()
|
||||
.children()
|
||||
|
@ -81,7 +80,6 @@ pub fn rule(
|
|||
} else if let rnix::SyntaxKind::NODE_LAMBDA = next_kind {
|
||||
if let rnix::SyntaxKind::NODE_PATTERN = next
|
||||
.element
|
||||
.clone()
|
||||
.into_node()
|
||||
.unwrap()
|
||||
.children()
|
||||
|
|
|
@ -53,7 +53,7 @@ pub fn rule(
|
|||
content.split('\n').map(|line| line.to_string()).collect();
|
||||
|
||||
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
|
||||
.iter()
|
||||
|
@ -72,7 +72,7 @@ pub fn rule(
|
|||
for line in lines.iter() {
|
||||
let line = line.trim_end();
|
||||
|
||||
if line.len() > 0 {
|
||||
if !line.is_empty() {
|
||||
indentation = usize::min(
|
||||
indentation,
|
||||
line.len() - line.trim_start().len(),
|
||||
|
@ -97,12 +97,12 @@ pub fn rule(
|
|||
|
||||
// Indent everything 2 spaces
|
||||
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
|
||||
.iter()
|
||||
.map(|line| {
|
||||
if line.trim().len() > 0 {
|
||||
if !line.trim().is_empty() {
|
||||
format!(" {}", line)
|
||||
} else {
|
||||
line.to_string()
|
||||
|
@ -121,7 +121,7 @@ pub fn rule(
|
|||
.collect();
|
||||
|
||||
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 {
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue