-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refacto(core): switch to semantic query and remove custom db
- Loading branch information
Showing
15 changed files
with
304 additions
and
276 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
#![feature(let_chains)] | ||
pub mod db; | ||
pub mod fix; | ||
pub mod lints; | ||
pub mod plugin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use cairo_lang_defs::plugin::PluginDiagnostic; | ||
use cairo_lang_diagnostics::Severity; | ||
use cairo_lang_semantic::db::SemanticGroup; | ||
use cairo_lang_semantic::{Arenas, Expr, ExprLoop, Statement}; | ||
|
||
pub const LOOP_MATCH_POP_FRONT: &str = | ||
"you seem to be trying to use `loop` for iterating over a span. Consider using `for in`"; | ||
|
||
const SPAN_MATCH_POP_FRONT: &str = "\"SpanImpl::pop_front\""; | ||
|
||
pub fn check_loop_match_pop_front( | ||
db: &dyn SemanticGroup, | ||
loop_expr: &ExprLoop, | ||
diagnostics: &mut Vec<PluginDiagnostic>, | ||
arenas: &Arenas, | ||
) { | ||
let Expr::Block(expr_block) = &arenas.exprs[loop_expr.body] else { | ||
return; | ||
}; | ||
if let Some(tail) = &expr_block.tail | ||
&& let Expr::Match(expr_match) = &arenas.exprs[*tail] | ||
&& let Expr::FunctionCall(func_call) = &arenas.exprs[expr_match.matched_expr] | ||
{ | ||
if func_call.function.name(db) == SPAN_MATCH_POP_FRONT { | ||
diagnostics.push(PluginDiagnostic { | ||
stable_ptr: loop_expr.stable_ptr.into(), | ||
message: LOOP_MATCH_POP_FRONT.to_owned(), | ||
severity: Severity::Warning, | ||
}); | ||
return; | ||
} | ||
} | ||
for statement in &expr_block.statements { | ||
if let Statement::Expr(stmt_expr) = &arenas.statements[*statement] | ||
&& let Expr::Match(expr_match) = &arenas.exprs[stmt_expr.expr] | ||
{ | ||
let Expr::FunctionCall(func_call) = &arenas.exprs[expr_match.matched_expr] else { | ||
continue; | ||
}; | ||
if func_call.function.name(db) == SPAN_MATCH_POP_FRONT { | ||
diagnostics.push(PluginDiagnostic { | ||
stable_ptr: loop_expr.stable_ptr.into(), | ||
message: LOOP_MATCH_POP_FRONT.to_owned(), | ||
severity: Severity::Warning, | ||
}) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod loops; | ||
pub mod single_match; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.