Skip to content

Commit 4cdee48

Browse files
committed
refactor: solve clippy warnings
1 parent f9ba9b9 commit 4cdee48

12 files changed

+65
-66
lines changed

buildkite.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,12 @@ steps:
7878
command:
7979
- echo +++
8080
- nix flake check
81+
82+
- label: lint
83+
if: build.branch != "main"
84+
command:
85+
- echo --- Load environment
86+
- direnv allow
87+
- eval "$(direnv export bash)"
88+
- echo +++ Run Linter
89+
- cargo clippy

src/builder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn build(
4444
config.clone(),
4545
force_wide,
4646
path,
47-
crate::position::Position::new(),
48-
crate::position::Position::new(),
47+
crate::position::Position::default(),
48+
crate::position::Position::default(),
4949
);
5050

5151
build_step(

src/children.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,12 @@ impl Children {
126126

127127
pub fn drain_comment<F: FnMut(String)>(&mut self, mut callback: F) {
128128
if let Some(child) = self.peek_next() {
129-
match child.element.kind() {
130-
rnix::SyntaxKind::TOKEN_COMMENT => {
131-
callback(dedent_comment(
132-
&child.pos,
133-
child.element.into_token().unwrap().text(),
134-
));
135-
self.move_next();
136-
}
137-
_ => {}
129+
if let rnix::SyntaxKind::TOKEN_COMMENT = child.element.kind() {
130+
callback(dedent_comment(
131+
&child.pos,
132+
child.element.into_token().unwrap().text(),
133+
));
134+
self.move_next();
138135
}
139136
}
140137
}

src/cli.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ pub fn tui(
150150

151151
while !finished {
152152
loop {
153-
match receiver.try_recv() {
154-
Ok(event) => match event {
153+
if let Ok(event) = receiver.try_recv() {
154+
match event {
155155
Event::FormattedPath(formatted_path) => {
156156
match formatted_path.result {
157157
Ok(changed) => {
@@ -175,20 +175,14 @@ pub fn tui(
175175
finished = true;
176176
}
177177
Event::Input(key) => {
178-
match key {
179-
termion::event::Key::Ctrl('c') => {
180-
return Err(
181-
std::io::ErrorKind::Interrupted.into()
182-
);
183-
}
184-
_ => {}
185-
};
178+
if let termion::event::Key::Ctrl('c') = key {
179+
return Err(std::io::ErrorKind::Interrupted.into());
180+
}
186181
}
187182
Event::Tick => {
188183
break;
189184
}
190-
},
191-
Err(_) => {}
185+
}
192186
}
193187
}
194188

src/config.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ pub struct Config {
99
layout: Layout,
1010
}
1111

12-
impl Config {
13-
pub fn new() -> Config {
12+
impl Default for Config {
13+
fn default() -> Config {
1414
Config { layout: Layout::Tall }
1515
}
16+
}
1617

18+
impl Config {
1719
pub fn layout(&self) -> &Layout {
1820
&self.layout
1921
}

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fn main() -> std::io::Result<()> {
22
let matches = alejandra::cli::parse(std::env::args().collect());
33

4-
let config = alejandra::config::Config::new();
4+
let config = alejandra::config::Config::default();
55

66
match matches.values_of("paths") {
77
Some(paths) => {

src/position.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ pub struct Position {
44
pub line: usize,
55
}
66

7-
impl Position {
8-
pub fn new() -> Position {
7+
impl Default for Position {
8+
fn default() -> Position {
99
Position { column: 0, line: 1 }
1010
}
11+
}
1112

13+
impl Position {
1214
pub fn update(&mut self, text: &str) {
1315
let chars: Vec<char> = text.chars().collect();
1416
let newlines = chars.iter().filter(|&c| *c == '\n').count();

src/rules/bin_op_and_or_default.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,14 @@ pub fn rule_with_configuration(
2828
crate::config::Layout::Tall => {
2929
let kind = child.element.kind();
3030

31-
if parent_kind == "bin_op_and_or_default"
31+
if (parent_kind == "bin_op_and_or_default"
3232
&& matches!(
3333
kind,
3434
rnix::SyntaxKind::NODE_BIN_OP
3535
| rnix::SyntaxKind::NODE_OR_DEFAULT
36-
)
37-
{
38-
steps.push_back(crate::builder::Step::Format(child.element));
39-
} else if parent_kind == "select"
40-
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT)
36+
))
37+
|| (parent_kind == "select"
38+
&& matches!(kind, rnix::SyntaxKind::NODE_SELECT))
4139
{
4240
steps.push_back(crate::builder::Step::Format(child.element));
4341
} else {

src/rules/if_else.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,8 @@ pub fn rule(
3636
if crate::builder::fits_in_single_line(
3737
build_ctx,
3838
child.element.clone(),
39-
) {
40-
steps.push_back(crate::builder::Step::Whitespace);
41-
steps.push_back(crate::builder::Step::FormatWider(
42-
child.element,
43-
));
44-
} else if branch == "else"
45-
&& child.element.kind() == rnix::SyntaxKind::NODE_IF_ELSE
39+
) || (branch == "else"
40+
&& child.element.kind() == rnix::SyntaxKind::NODE_IF_ELSE)
4641
{
4742
steps.push_back(crate::builder::Step::Whitespace);
4843
steps.push_back(crate::builder::Step::FormatWider(

src/rules/key_value.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,20 @@ pub fn rule(
8383
steps.push_back(crate::builder::Step::Indent);
8484
steps.push_back(crate::builder::Step::NewLine);
8585
steps.push_back(crate::builder::Step::Pad);
86-
} else if false
87-
|| matches!(
88-
child_expr.element.kind(),
89-
rnix::SyntaxKind::NODE_ASSERT
90-
| rnix::SyntaxKind::NODE_ATTR_SET
91-
| rnix::SyntaxKind::NODE_PAREN
92-
| rnix::SyntaxKind::NODE_LAMBDA
93-
| rnix::SyntaxKind::NODE_LET_IN
94-
| rnix::SyntaxKind::NODE_LIST
95-
| rnix::SyntaxKind::NODE_STRING
96-
| rnix::SyntaxKind::NODE_WITH
97-
)
98-
|| (matches!(
99-
child_expr.element.kind(),
100-
rnix::SyntaxKind::NODE_APPLY
101-
) && !newlines)
86+
} else if matches!(
87+
child_expr.element.kind(),
88+
rnix::SyntaxKind::NODE_ASSERT
89+
| rnix::SyntaxKind::NODE_ATTR_SET
90+
| rnix::SyntaxKind::NODE_PAREN
91+
| rnix::SyntaxKind::NODE_LAMBDA
92+
| rnix::SyntaxKind::NODE_LET_IN
93+
| rnix::SyntaxKind::NODE_LIST
94+
| rnix::SyntaxKind::NODE_STRING
95+
| rnix::SyntaxKind::NODE_WITH
96+
) || (matches!(
97+
child_expr.element.kind(),
98+
rnix::SyntaxKind::NODE_APPLY
99+
) && !newlines)
102100
{
103101
steps.push_back(crate::builder::Step::Whitespace);
104102
} else {

src/rules/let_in.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ pub fn rule(
1010

1111
let items_count = node
1212
.children()
13-
.filter(|element| match element.kind() {
14-
rnix::SyntaxKind::NODE_KEY_VALUE
15-
| rnix::SyntaxKind::NODE_INHERIT
16-
| rnix::SyntaxKind::NODE_INHERIT_FROM => true,
17-
_ => false,
13+
.filter(|element| {
14+
matches!(
15+
element.kind(),
16+
rnix::SyntaxKind::NODE_KEY_VALUE
17+
| rnix::SyntaxKind::NODE_INHERIT
18+
| rnix::SyntaxKind::NODE_INHERIT_FROM
19+
)
1820
})
1921
.count();
2022

src/rules/pattern.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ pub fn rule(
2121

2222
let items_count = node
2323
.children_with_tokens()
24-
.filter(|element| match element.kind() {
25-
rnix::SyntaxKind::TOKEN_ELLIPSIS
26-
| rnix::SyntaxKind::NODE_PAT_ENTRY => true,
27-
_ => false,
24+
.filter(|element| {
25+
matches!(
26+
element.kind(),
27+
rnix::SyntaxKind::TOKEN_ELLIPSIS
28+
| rnix::SyntaxKind::NODE_PAT_ENTRY
29+
)
2830
})
2931
.count();
3032

0 commit comments

Comments
 (0)