-
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 (#39)
* refacto(core): switch to semantic query and remove custom db * chore: make clippy happy * chore: remove useless deps
- Loading branch information
Showing
17 changed files
with
326 additions
and
911 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 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,48 @@ | ||
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] | ||
&& 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,2 +1,3 @@ | ||
pub mod double_parens; | ||
pub mod loops; | ||
pub mod single_match; |
Oops, something went wrong.