Skip to content

Commit e52d1db

Browse files
committed
fix warnings
1 parent b0179e2 commit e52d1db

15 files changed

Lines changed: 92 additions & 123 deletions

cli_args.mbt

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,68 +27,60 @@ fn runtime_cli_args(argv : Array[String]) -> Array[String] {
2727
}
2828

2929
///|
30-
let scan_command : @argparse.Command = @argparse.Command(
30+
let scan_command : @argparse.Command = Command(
3131
"scan",
3232
about="Scan MoonBit source files with structural and taint rules.",
3333
flags=[
34-
@argparse.FlagArg(
34+
FlagArg(
3535
"verbose",
3636
long="verbose",
3737
about="Print loaded rule ids and directory traversal progress.",
3838
),
39-
@argparse.FlagArg(
39+
FlagArg(
4040
"enable-builtin-rules",
4141
long="enable-builtin-rules",
4242
about="Enable embedded builtin rules.",
4343
),
4444
],
4545
options=[
46-
@argparse.OptionArg(
46+
OptionArg(
4747
"rules",
4848
short='r',
49-
action=@argparse.OptionAction::Append,
49+
action=Append,
5050
about="Directory containing YAML rules.",
5151
),
52-
@argparse.OptionArg(
53-
"rule",
54-
action=@argparse.OptionAction::Append,
55-
about="Single YAML rule file.",
56-
),
57-
@argparse.OptionArg(
52+
OptionArg("rule", action=Append, about="Single YAML rule file."),
53+
OptionArg(
5854
"pattern",
59-
action=@argparse.OptionAction::Append,
55+
action=Append,
6056
about="Anonymous structural pattern to match.",
6157
),
62-
@argparse.OptionArg(
58+
OptionArg(
6359
"guard",
64-
action=@argparse.OptionAction::Append,
60+
action=Append,
6561
about="YAML guard map for the preceding anonymous pattern.",
6662
),
67-
@argparse.OptionArg(
63+
OptionArg(
6864
"exclude-dir",
69-
action=@argparse.OptionAction::Append,
65+
action=Append,
7066
about="Directory name or path to skip while recursively scanning.",
7167
),
7268
],
73-
positionals=[@argparse.PositionArg("scan-root", about="Directory to scan.")],
69+
positionals=[PositionArg("scan-root", about="Directory to scan.")],
7470
)
7571

7672
///|
77-
let docs_command : @argparse.Command = @argparse.Command(
73+
let docs_command : @argparse.Command = Command(
7874
"docs",
7975
about="Print embedded moongrep documentation.",
8076
flags=[
81-
@argparse.FlagArg(
82-
"list",
83-
long="list",
84-
about="List available embedded documents.",
85-
),
77+
FlagArg("list", long="list", about="List available embedded documents."),
8678
],
8779
positionals=[
88-
@argparse.PositionArg(
80+
PositionArg(
8981
"doc-name",
9082
about="Document name to print.",
91-
num_args=@argparse.ValueRange(lower=0, upper=1),
83+
num_args=ValueRange(lower=0, upper=1),
9284
),
9385
],
9486
)
@@ -108,7 +100,7 @@ let dump_command : @argparse.Command = Command(
108100
)
109101

110102
///|
111-
let moongrep_command : @argparse.Command = @argparse.Command(
103+
let moongrep_command : @argparse.Command = Command(
112104
"moongrep",
113105
about="Scan MoonBit source files with structural and taint rules.",
114106
subcommands=[scan_command, docs_command, dump_command],

matching/matching.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn match_expr_pattern(
3232
compiled : CompiledExprPattern,
3333
candidate : @untyped_ast.Node,
3434
) -> ExprMatch? {
35-
let bindings : @hashmap.HashMap[String, BoundValue] = @hashmap.HashMap([])
35+
let bindings : @hashmap.HashMap[String, BoundValue] = HashMap([])
3636
match_expr_pattern_with_bindings(compiled, candidate, bindings)
3737
}
3838

matching/matching_test.mbt

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn test_loc() -> @basic.Location {
2222

2323
///|
2424
fn test_var(name : String) -> @syntax.Var {
25-
{ name: @syntax.LongIdent::Ident(name~), loc: test_loc() }
25+
{ name: Ident(name~), loc: test_loc() }
2626
}
2727

2828
///|
@@ -37,17 +37,15 @@ fn test_pattern_var(name : String) -> @syntax.Pattern {
3737

3838
///|
3939
fn test_pattern_tuple(items : Array[@syntax.Pattern]) -> @syntax.Pattern {
40-
Tuple(pats=@list.from_array(items), loc=test_loc())
40+
Tuple(pats=List(items), loc=test_loc())
4141
}
4242

4343
///|
4444
fn test_match_pattern(pattern : @syntax.Pattern) -> @untyped_ast.Node {
4545
@untyped_ast.from_expr(
4646
Match(
4747
expr=test_ident("input"),
48-
cases=@list.from_array([
49-
{ pattern, guard_: None, body: test_ident("body") },
50-
]),
48+
cases=List([{ pattern, guard_: None, body: test_ident("body") }]),
5149
match_loc=test_loc(),
5250
loc=test_loc(),
5351
),
@@ -66,17 +64,13 @@ fn test_field_def(label : String, expr : @syntax.Expr) -> @syntax.FieldDef {
6664

6765
///|
6866
fn test_ident(name : String) -> @syntax.Expr {
69-
@syntax.Expr::Ident(id=test_var(name), loc=test_loc())
67+
Ident(id=test_var(name), loc=test_loc())
7068
}
7169

7270
///|
7371
fn test_implies(lhs : String, rhs : String) -> @untyped_ast.Node {
7472
@untyped_ast.from_expr(
75-
@syntax.Expr::Implies(
76-
lhs=test_ident(lhs),
77-
rhs=test_ident(rhs),
78-
loc=test_loc(),
79-
),
73+
Implies(lhs=test_ident(lhs), rhs=test_ident(rhs), loc=test_loc()),
8074
)
8175
}
8276

@@ -86,19 +80,15 @@ fn test_foreach_syntax(
8680
continue_value : String,
8781
where_value : String,
8882
) -> @syntax.Expr {
89-
@syntax.Expr::ForEach(
90-
binders=@list.from_array([Some(test_binder("item"))]),
83+
ForEach(
84+
binders=List([Some(test_binder("item"))]),
9185
expr=test_ident("items"),
92-
init=@list.from_array([(test_binder("start"), test_ident(init))]),
93-
continue_block=@list.from_array([
94-
(test_binder("next"), test_ident(continue_value)),
95-
]),
86+
init=List([(test_binder("start"), test_ident(init))]),
87+
continue_block=List([(test_binder("next"), test_ident(continue_value))]),
9688
body=test_ident("body"),
9789
else_block=None,
9890
where_clause=Some({
99-
fields: @list.from_array([
100-
test_field_def("field", test_ident(where_value)),
101-
]),
91+
fields: List([test_field_def("field", test_ident(where_value))]),
10292
loc: test_loc(),
10393
}),
10494
label=None,

matching/untyped_matching_test.mbt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ fn untyped_test_pattern_var(name : String) -> @syntax.Pattern {
5353
fn untyped_test_pattern_tuple(
5454
items : Array[@syntax.Pattern],
5555
) -> @syntax.Pattern {
56-
Tuple(pats=@list.from_array(items), loc=untyped_test_loc())
56+
Tuple(pats=List(items), loc=untyped_test_loc())
5757
}
5858

5959
///|
6060
fn untyped_test_ident(name : String) -> @syntax.Expr {
61-
@syntax.Expr::Ident(
62-
id={ name: @syntax.LongIdent::Ident(name~), loc: untyped_test_loc() },
61+
Ident(
62+
id={ name: Ident(name~), loc: untyped_test_loc() },
6363
loc=untyped_test_loc(),
6464
)
6565
}
@@ -68,9 +68,7 @@ fn untyped_test_ident(name : String) -> @syntax.Expr {
6868
fn untyped_test_match_pattern(pattern : @syntax.Pattern) -> @syntax.Expr {
6969
Match(
7070
expr=untyped_test_ident("input"),
71-
cases=@list.from_array([
72-
{ pattern, guard_: None, body: untyped_test_ident("body") },
73-
]),
71+
cases=List([{ pattern, guard_: None, body: untyped_test_ident("body") }]),
7472
match_loc=untyped_test_loc(),
7573
loc=untyped_test_loc(),
7674
)

query/query.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ fn anonymous_pattern_rule(pattern : String) -> RawRuleSpec {
8080
inside_expr: None,
8181
patterns: [{ shape: pattern, guards: {} }],
8282
patterns_not: [],
83-
patterns_not_mode: @rule_model.StructuralPatternsNotMode::PruneOnNegative,
83+
patterns_not_mode: PruneOnNegative,
8484
}),
8585
}
8686
}
@@ -93,7 +93,7 @@ fn collect_node_matches(
9393
) -> Unit {
9494
@untyped_ast.visit_node_scoped_expr_roots(ast, fn(scoped_expr) {
9595
collect_scoped_node_matches(pattern, scoped_expr, matches)
96-
@untyped_ast.NodeVisitAction::NodeVisitPrune
96+
NodeVisitPrune
9797
})
9898
}
9999

render.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fn render_source_context_line(
7575

7676
///|
7777
fn render_gray(text : String) -> String {
78-
@chalk.chalk().color(@chalk.Colors::BlackBright).render(text)
78+
@chalk.chalk().color(BlackBright).render(text)
7979
}
8080

8181
///|

rule/apply/apply.mbt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn apply_structural_rules_to_node(
5959
apply_ast_structural_rule_entries_to_scoped_expr(
6060
file, entries, scoped_expr, hits,
6161
)
62-
@untyped_ast.NodeVisitAction::NodeVisitPrune
62+
NodeVisitPrune
6363
})
6464
hits
6565
}
@@ -171,7 +171,7 @@ pub fn apply_taint_rules(
171171
rules : Array[CompiledRule],
172172
) -> Array[RuleFinding] raise {
173173
let hits : Array[RuleFinding] = []
174-
if root_node.kind == @untyped_ast.NodeKind::ImplList {
174+
if root_node.kind == ImplList {
175175
for entry in root_node.children {
176176
let (_, node) = entry
177177
let node_hits = apply_taint_rules_to_node(file, node, rules)
@@ -274,7 +274,7 @@ fn apply_inside_expr_ast_bucketed(
274274
)
275275
} else {
276276
match structural.patterns_not_mode {
277-
@model.StructuralPatternsNotMode::RejectUncoveredNegative =>
277+
RejectUncoveredNegative =>
278278
apply_ast_bucketed_covered_patterns_in_target_subtree(
279279
file,
280280
rule,
@@ -286,7 +286,7 @@ fn apply_inside_expr_ast_bucketed(
286286
inside.compiled.identifier_metavars,
287287
hits,
288288
)
289-
@model.StructuralPatternsNotMode::PruneOnNegative =>
289+
PruneOnNegative =>
290290
apply_ast_bucketed_patterns_in_target_subtree(
291291
file,
292292
rule,
@@ -322,8 +322,8 @@ fn apply_ast_bucketed_patterns_in_target_subtree(
322322
file, rule, pattern_buckets, negative_pattern_buckets, scoped_expr, outer_loc,
323323
outer_bindings, inherited_identifier_metavars, hits,
324324
) {
325-
RulePrune => @untyped_ast.NodeVisitAction::NodeVisitPrune
326-
RuleContinue => @untyped_ast.NodeVisitAction::NodeVisitContinue
325+
RulePrune => NodeVisitPrune
326+
RuleContinue => NodeVisitContinue
327327
}
328328
})
329329
}
@@ -344,19 +344,19 @@ fn apply_ast_bucketed_covered_patterns_in_target_subtree(
344344
let mut rejected = false
345345
@untyped_ast.visit_node_scoped_exprs(target, fn(scoped_expr) {
346346
if rejected {
347-
@untyped_ast.NodeVisitAction::NodeVisitPrune
347+
NodeVisitPrune
348348
} else {
349349
match
350350
apply_ast_bucketed_covered_patterns_at_scoped_expr(
351351
file, rule, pattern_buckets, negative_pattern_buckets, scoped_expr, outer_loc,
352352
outer_bindings, inherited_identifier_metavars, pending_hits,
353353
) {
354-
InsideTargetPrune => @untyped_ast.NodeVisitAction::NodeVisitPrune
354+
InsideTargetPrune => NodeVisitPrune
355355
InsideTargetReject => {
356356
rejected = true
357-
@untyped_ast.NodeVisitAction::NodeVisitPrune
357+
NodeVisitPrune
358358
}
359-
InsideTargetContinue => @untyped_ast.NodeVisitAction::NodeVisitContinue
359+
InsideTargetContinue => NodeVisitContinue
360360
}
361361
}
362362
})
@@ -641,7 +641,7 @@ fn ast_guards_match(
641641
) -> Bool {
642642
for guard_entry in guards {
643643
match guard_entry.capture_kind {
644-
@model.RuleGuardCaptureKind::IdentifierGuard =>
644+
IdentifierGuard =>
645645
match bindings.get(guard_entry.name) {
646646
Some(value) => {
647647
guard node_leaf_string(value) is Some(text) else { return false }
@@ -651,7 +651,7 @@ fn ast_guards_match(
651651
}
652652
_ => return false
653653
}
654-
@model.RuleGuardCaptureKind::ConstantGuard =>
654+
ConstantGuard =>
655655
match bindings.get(guard_entry.name) {
656656
Some(value) => {
657657
guard constant_guard_value(value) is Some(text) else {

0 commit comments

Comments
 (0)