Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: impossible comparison #148

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

chachaleo
Copy link
Contributor

Resolves: #119

Catches 8 cases of impossible comparison :

  • x > 500 && x < 400
  • x > 500 && x <= 400
  • x >= 500 && x < 400
  • x >= 500 && x <= 400
  • x < 400 && x > 500
  • x < 400 && x >= 500
  • x <= 400 && x > 500
  • x <= 400 && x >= 500

Copy link
Contributor

@0xLucqs 0xLucqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t'as check le lint double_comparison ? on a deja du impossible comparison

Comment on lines +661 to +682
pub fn fix_impossible_comparison(&self, db: &dyn SyntaxGroup, node: SyntaxNode) -> Option<(SyntaxNode, String)> {
let expr_if = ExprIf::from_syntax_node(db, node.clone());
let indent = expr_if.if_kw(db).as_syntax_node().get_text(db).chars().take_while(|c| c.is_whitespace()).count();

match expr_if.else_clause(db) {
OptionElseClause::Empty(_) => Some((
node,
indent_snippet(&format!("if false {}", expr_if.if_block(db).as_syntax_node().get_text(db)), indent / 4),
)),
OptionElseClause::ElseClause(else_clause) => Some((
node,
indent_snippet(
&format!(
"if false {}{}",
expr_if.if_block(db).as_syntax_node().get_text(db),
else_clause.as_syntax_node().get_text(db)
),
indent / 4,
),
)),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix pas
if false {...} n'a pas de sens

// Check is >= or > or < or <=
let full_name = func_call.function.full_name(db);
let logic_op = if full_name.contains("core::integer::") {
if full_name.contains("PartialOrd::gt") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tu peux pas faire core::PartialOrd::gt ? et utiliser les constantes dans src/lib.rs ?

) -> Option<(String, &'static str, BigInt)> {
// Check is >= or > or < or <=
let full_name = func_call.function.full_name(db);
let logic_op = if full_name.contains("core::integer::") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let logic_op = if full_name.contains("core::integer::") {
let logic_op = full_name.contains("core::integer::").then(|| {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants