mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +00:00
refactor: solve clippy warnings
This commit is contained in:
parent
f9ba9b9192
commit
4cdee48ddf
12 changed files with 65 additions and 66 deletions
|
@ -78,3 +78,12 @@ steps:
|
|||
command:
|
||||
- echo +++
|
||||
- nix flake check
|
||||
|
||||
- label: lint
|
||||
if: build.branch != "main"
|
||||
command:
|
||||
- echo --- Load environment
|
||||
- direnv allow
|
||||
- eval "$(direnv export bash)"
|
||||
- echo +++ Run Linter
|
||||
- cargo clippy
|
||||
|
|
|
@ -44,8 +44,8 @@ pub fn build(
|
|||
config.clone(),
|
||||
force_wide,
|
||||
path,
|
||||
crate::position::Position::new(),
|
||||
crate::position::Position::new(),
|
||||
crate::position::Position::default(),
|
||||
crate::position::Position::default(),
|
||||
);
|
||||
|
||||
build_step(
|
||||
|
|
|
@ -126,15 +126,12 @@ impl Children {
|
|||
|
||||
pub fn drain_comment<F: FnMut(String)>(&mut self, mut callback: F) {
|
||||
if let Some(child) = self.peek_next() {
|
||||
match child.element.kind() {
|
||||
rnix::SyntaxKind::TOKEN_COMMENT => {
|
||||
callback(dedent_comment(
|
||||
&child.pos,
|
||||
child.element.into_token().unwrap().text(),
|
||||
));
|
||||
self.move_next();
|
||||
}
|
||||
_ => {}
|
||||
if let rnix::SyntaxKind::TOKEN_COMMENT = child.element.kind() {
|
||||
callback(dedent_comment(
|
||||
&child.pos,
|
||||
child.element.into_token().unwrap().text(),
|
||||
));
|
||||
self.move_next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
18
src/cli.rs
18
src/cli.rs
|
@ -150,8 +150,8 @@ pub fn tui(
|
|||
|
||||
while !finished {
|
||||
loop {
|
||||
match receiver.try_recv() {
|
||||
Ok(event) => match event {
|
||||
if let Ok(event) = receiver.try_recv() {
|
||||
match event {
|
||||
Event::FormattedPath(formatted_path) => {
|
||||
match formatted_path.result {
|
||||
Ok(changed) => {
|
||||
|
@ -175,20 +175,14 @@ pub fn tui(
|
|||
finished = true;
|
||||
}
|
||||
Event::Input(key) => {
|
||||
match key {
|
||||
termion::event::Key::Ctrl('c') => {
|
||||
return Err(
|
||||
std::io::ErrorKind::Interrupted.into()
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
if let termion::event::Key::Ctrl('c') = key {
|
||||
return Err(std::io::ErrorKind::Interrupted.into());
|
||||
}
|
||||
}
|
||||
Event::Tick => {
|
||||
break;
|
||||
}
|
||||
},
|
||||
Err(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,13 @@ pub struct Config {
|
|||
layout: Layout,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new() -> Config {
|
||||
impl Default for Config {
|
||||
fn default() -> Config {
|
||||
Config { layout: Layout::Tall }
|
||||
}
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn layout(&self) -> &Layout {
|
||||
&self.layout
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fn main() -> std::io::Result<()> {
|
||||
let matches = alejandra::cli::parse(std::env::args().collect());
|
||||
|
||||
let config = alejandra::config::Config::new();
|
||||
let config = alejandra::config::Config::default();
|
||||
|
||||
match matches.values_of("paths") {
|
||||
Some(paths) => {
|
||||
|
|
|
@ -4,11 +4,13 @@ pub struct Position {
|
|||
pub line: usize,
|
||||
}
|
||||
|
||||
impl Position {
|
||||
pub fn new() -> Position {
|
||||
impl Default for Position {
|
||||
fn default() -> Position {
|
||||
Position { column: 0, line: 1 }
|
||||
}
|
||||
}
|
||||
|
||||
impl Position {
|
||||
pub fn update(&mut self, text: &str) {
|
||||
let chars: Vec<char> = text.chars().collect();
|
||||
let newlines = chars.iter().filter(|&c| *c == '\n').count();
|
||||
|
|
|
@ -28,16 +28,14 @@ pub fn rule_with_configuration(
|
|||
crate::config::Layout::Tall => {
|
||||
let kind = child.element.kind();
|
||||
|
||||
if parent_kind == "bin_op_and_or_default"
|
||||
if (parent_kind == "bin_op_and_or_default"
|
||||
&& matches!(
|
||||
kind,
|
||||
rnix::SyntaxKind::NODE_BIN_OP
|
||||
| rnix::SyntaxKind::NODE_OR_DEFAULT
|
||||
)
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
} else if parent_kind == "select"
|
||||
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT)
|
||||
))
|
||||
|| (parent_kind == "select"
|
||||
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Format(child.element));
|
||||
} else {
|
||||
|
|
|
@ -36,13 +36,8 @@ pub fn rule(
|
|||
if crate::builder::fits_in_single_line(
|
||||
build_ctx,
|
||||
child.element.clone(),
|
||||
) {
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
child.element,
|
||||
));
|
||||
} else if branch == "else"
|
||||
&& child.element.kind() == rnix::SyntaxKind::NODE_IF_ELSE
|
||||
) || (branch == "else"
|
||||
&& child.element.kind() == rnix::SyntaxKind::NODE_IF_ELSE)
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
steps.push_back(crate::builder::Step::FormatWider(
|
||||
|
|
|
@ -83,22 +83,20 @@ pub fn rule(
|
|||
steps.push_back(crate::builder::Step::Indent);
|
||||
steps.push_back(crate::builder::Step::NewLine);
|
||||
steps.push_back(crate::builder::Step::Pad);
|
||||
} else if false
|
||||
|| matches!(
|
||||
child_expr.element.kind(),
|
||||
rnix::SyntaxKind::NODE_ASSERT
|
||||
| rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LAMBDA
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
| rnix::SyntaxKind::NODE_WITH
|
||||
)
|
||||
|| (matches!(
|
||||
child_expr.element.kind(),
|
||||
rnix::SyntaxKind::NODE_APPLY
|
||||
) && !newlines)
|
||||
} else if matches!(
|
||||
child_expr.element.kind(),
|
||||
rnix::SyntaxKind::NODE_ASSERT
|
||||
| rnix::SyntaxKind::NODE_ATTR_SET
|
||||
| rnix::SyntaxKind::NODE_PAREN
|
||||
| rnix::SyntaxKind::NODE_LAMBDA
|
||||
| rnix::SyntaxKind::NODE_LET_IN
|
||||
| rnix::SyntaxKind::NODE_LIST
|
||||
| rnix::SyntaxKind::NODE_STRING
|
||||
| rnix::SyntaxKind::NODE_WITH
|
||||
) || (matches!(
|
||||
child_expr.element.kind(),
|
||||
rnix::SyntaxKind::NODE_APPLY
|
||||
) && !newlines)
|
||||
{
|
||||
steps.push_back(crate::builder::Step::Whitespace);
|
||||
} else {
|
||||
|
|
|
@ -10,11 +10,13 @@ pub fn rule(
|
|||
|
||||
let items_count = node
|
||||
.children()
|
||||
.filter(|element| match element.kind() {
|
||||
rnix::SyntaxKind::NODE_KEY_VALUE
|
||||
| rnix::SyntaxKind::NODE_INHERIT
|
||||
| rnix::SyntaxKind::NODE_INHERIT_FROM => true,
|
||||
_ => false,
|
||||
.filter(|element| {
|
||||
matches!(
|
||||
element.kind(),
|
||||
rnix::SyntaxKind::NODE_KEY_VALUE
|
||||
| rnix::SyntaxKind::NODE_INHERIT
|
||||
| rnix::SyntaxKind::NODE_INHERIT_FROM
|
||||
)
|
||||
})
|
||||
.count();
|
||||
|
||||
|
|
|
@ -21,10 +21,12 @@ pub fn rule(
|
|||
|
||||
let items_count = node
|
||||
.children_with_tokens()
|
||||
.filter(|element| match element.kind() {
|
||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY => true,
|
||||
_ => false,
|
||||
.filter(|element| {
|
||||
matches!(
|
||||
element.kind(),
|
||||
rnix::SyntaxKind::TOKEN_ELLIPSIS
|
||||
| rnix::SyntaxKind::NODE_PAT_ENTRY
|
||||
)
|
||||
})
|
||||
.count();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue