Skip to content

Commit f5867e1

Browse files
authored
Fix linting errors (#1146)
1 parent 0868cb3 commit f5867e1

File tree

7 files changed

+35
-29
lines changed

7 files changed

+35
-29
lines changed

rust-code-analysis-web/src/web/server.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,7 @@ async fn metrics_plain(
149149
let cfg = WebMetricsCfg {
150150
id: "".to_string(),
151151
path,
152-
unit: info
153-
.unit
154-
.as_ref()
155-
.map_or(false, |s| s == "1" || s == "true"),
152+
unit: info.unit.as_ref().is_some_and(|s| s == "1" || s == "true"),
156153
language: name.to_string(),
157154
};
158155
Ok(HttpResponse::Ok().json(action::<WebMetricsCallback>(

src/getter.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -402,20 +402,24 @@ impl Getter for RustCode {
402402
//
403403
// Similarly, exclude `/` when it corresponds to the third slash in `///` (`OuterDocCommentMarker`)
404404
PIPEPIPE | SLASH => match node.parent() {
405-
Some(parent) if matches!(parent.kind_id().into(), BinaryExpression) => HalsteadType::Operator,
406-
_ => HalsteadType::Unknown
407-
}
405+
Some(parent) if matches!(parent.kind_id().into(), BinaryExpression) => {
406+
HalsteadType::Operator
407+
}
408+
_ => HalsteadType::Unknown,
409+
},
408410
// Ensure `!` is counted as an operator unless it belongs to an `InnerDocCommentMarker` `//!`
409411
BANG => match node.parent() {
410-
Some(parent) if !matches!(parent.kind_id().into(), InnerDocCommentMarker) => HalsteadType::Operator,
411-
_ => HalsteadType::Unknown
412-
}
412+
Some(parent) if !matches!(parent.kind_id().into(), InnerDocCommentMarker) => {
413+
HalsteadType::Operator
414+
}
415+
_ => HalsteadType::Unknown,
416+
},
413417
LPAREN | LBRACE | LBRACK | EQGT | PLUS | STAR | Async | Await | Continue | For | If
414-
| Let | Loop | Match | Return | Unsafe | While | EQ | COMMA | DASHGT | QMARK
415-
| LT | GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP
416-
| PIPE | CARET | EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | PERCENT
417-
| PLUSEQ | DASHEQ | STAREQ | SLASHEQ | PERCENTEQ | AMPEQ | PIPEEQ | CARETEQ
418-
| LTLTEQ | GTGTEQ | Move | DOT | PrimitiveType | Fn | SEMI => HalsteadType::Operator,
418+
| Let | Loop | Match | Return | Unsafe | While | EQ | COMMA | DASHGT | QMARK | LT
419+
| GT | AMP | MutableSpecifier | DOTDOT | DOTDOTEQ | DASH | AMPAMP | PIPE | CARET
420+
| EQEQ | BANGEQ | LTEQ | GTEQ | LTLT | GTGT | PERCENT | PLUSEQ | DASHEQ | STAREQ
421+
| SLASHEQ | PERCENTEQ | AMPEQ | PIPEEQ | CARETEQ | LTLTEQ | GTGTEQ | Move | DOT
422+
| PrimitiveType | Fn | SEMI => HalsteadType::Operator,
419423
Identifier | StringLiteral | RawStringLiteral | IntegerLiteral | FloatLiteral
420424
| BooleanLiteral | Zelf | CharLiteral | UNDERSCORE => HalsteadType::Operand,
421425
_ => HalsteadType::Unknown,
@@ -492,15 +496,17 @@ impl Getter for CppCode {
492496
match node.kind_id().into() {
493497
DOT | LPAREN | LPAREN2 | COMMA | STAR | GTGT | COLON | SEMI | Return | Break
494498
| Continue | If | Else | Switch | Case | Default | For | While | Goto | Do | Delete
495-
| New | Try | Try2 | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH | DASHGT
496-
| PLUS | PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE | LT | LTEQ | EQEQ
497-
| BANGEQ | GTEQ | GT | GT2 | PLUSEQ | BANG | STAREQ | SLASHEQ | PERCENTEQ | GTGTEQ
498-
| LTLTEQ | AMPEQ | CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE | QMARK | COLONCOLON
499-
| PrimitiveType | TypeSpecifier | Sizeof => HalsteadType::Operator,
499+
| New | Try | Try2 | Catch | Throw | EQ | AMPAMP | PIPEPIPE | DASH | DASHDASH
500+
| DASHGT | PLUS | PLUSPLUS | SLASH | PERCENT | PIPE | AMP | LTLT | TILDE | LT
501+
| LTEQ | EQEQ | BANGEQ | GTEQ | GT | GT2 | PLUSEQ | BANG | STAREQ | SLASHEQ
502+
| PERCENTEQ | GTGTEQ | LTLTEQ | AMPEQ | CARET | CARETEQ | PIPEEQ | LBRACK | LBRACE
503+
| QMARK | COLONCOLON | PrimitiveType | TypeSpecifier | Sizeof => HalsteadType::Operator,
500504
Identifier | TypeIdentifier | FieldIdentifier | RawStringLiteral | StringLiteral
501505
| NumberLiteral | True | False | Null | DOTDOTDOT => HalsteadType::Operand,
502506
NamespaceIdentifier => match node.parent() {
503-
Some(parent) if matches!(parent.kind_id().into(), NamespaceDefinition) => HalsteadType::Operand,
507+
Some(parent) if matches!(parent.kind_id().into(), NamespaceDefinition) => {
508+
HalsteadType::Operand
509+
}
504510
_ => HalsteadType::Unknown,
505511
},
506512
_ => HalsteadType::Unknown,

src/languages/language_kotlin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,4 +616,3 @@ impl PartialEq<Kotlin> for u16 {
616616
*x == *self
617617
}
618618
}
619-

src/metrics/abc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ fn java_inspect_container(container_node: &Node, conditions: &mut f64) {
264264
// Initializes the flag to true if the container is known to contain a boolean value
265265
let mut has_boolean_content = match node.parent().unwrap().kind_id().into() {
266266
BinaryExpression | IfStatement | WhileStatement | DoStatement | ForStatement => true,
267-
TernaryExpression => node.previous_sibling().map_or(true, |prev_node| {
268-
!matches!(prev_node.kind_id().into(), QMARK | COLON)
269-
}),
267+
TernaryExpression => node
268+
.previous_sibling()
269+
.is_none_or(|prev_node| !matches!(prev_node.kind_id().into(), QMARK | COLON)),
270270
_ => false,
271271
};
272272

src/metrics/loc.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,14 +738,18 @@ impl Loc for RustCode {
738738
| DocComment
739739
| InnerDocCommentMarker
740740
| BANG => {}
741-
| BlockComment => {
741+
BlockComment => {
742742
add_cloc_lines(stats, start, end);
743743
}
744744
LineComment => {
745745
// Exclude the last line for `LineComment` containing a `DocComment`,
746746
// since the `DocComment` includes the newline,
747747
// as explained here: https://github.com/tree-sitter/tree-sitter-rust/blob/2eaf126458a4d6a69401089b6ba78c5e5d6c1ced/src/scanner.c#L194-L195
748-
let end = if node.is_child(DocComment as u16) { end - 1 } else { end };
748+
let end = if node.is_child(DocComment as u16) {
749+
end - 1
750+
} else {
751+
end
752+
};
749753
add_cloc_lines(stats, start, end);
750754
}
751755
Statement

src/metrics/npa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl Npa for JavaCode {
225225
// The first child node contains the list of attribute modifiers
226226
// There are several modifiers that may be part of a field declaration
227227
// Source: https://docs.oracle.com/javase/tutorial/reflect/member/fieldModifiers.html
228-
if declaration.child(0).map_or(false, |modifiers| {
228+
if declaration.child(0).is_some_and(|modifiers| {
229229
// Looks for the `public` keyword in the list of attribute modifiers
230230
matches!(modifiers.kind_id().into(), Modifiers)
231231
&& modifiers.first_child(|id| id == Public).is_some()

src/node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl<'a> Node<'a> {
8282

8383
#[inline(always)]
8484
pub(crate) fn has_sibling(&self, id: u16) -> bool {
85-
self.0.parent().map_or(false, |parent| {
85+
self.0.parent().is_some_and(|parent| {
8686
self.0
8787
.children(&mut parent.walk())
8888
.any(|child| child.kind_id() == id)

0 commit comments

Comments
 (0)