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