pi-lens
Version:
Real-time code feedback for pi — LSP, linters, formatters, type-checking, structural analysis & booboo
58 lines (47 loc) • 1.21 kB
YAML
# Unnecessary Bit Operations Java
# Detects bit operations that have no effect in Java
id: unnecessary-bit-ops-java
name: Unnecessary Bit Operations Should Not Be Performed
severity: error
category: maintainability
defect_class: correctness
inline_tier: blocking
language: java
message: "Unnecessary bit operation - has no effect"
description: |
Operations like (x | 0), (x & -1), (x ^ 0) have no effect.
They indicate confusion or incomplete refactoring. Remove them.
✅ FIX: Remove unnecessary operation
```java
int y = x; // GOOD - simplified
```
query: |
(binary_expression
(identifier) @VAR
"|" @OP
(decimal_integer_literal) @ZERO (#eq? @ZERO "0"))
(binary_expression
(identifier) @VAR
"&" @OP
(decimal_integer_literal) @VAL (#match? @VAL "^-?1+$"))
(binary_expression
(identifier) @VAR
"^" @OP
(decimal_integer_literal) @ZERO (#eq? @ZERO "0"))
metavars:
- VAR
- OP
- ZERO
- VAL
tags:
- maintainability
- java
- suspicious
examples:
bad: |
int y = x | 0; // BAD - no effect
int z = x & -1; // BAD - no effect
good: |
int y = x; // GOOD - simplified
has_fix: true
fix_action: remove_bit_operation