Handles circular dependencies while getting rules and dependencies (#2014)

* Remove test for scope "unspecified"

* raise error on circular dependency

* test for circular dependency
This commit is contained in:
Aayush Goel
2024-03-06 16:09:21 +05:30
committed by GitHub
parent 10a4381ad5
commit 49231366f1
4 changed files with 54 additions and 74 deletions

View File

@@ -166,9 +166,7 @@ class MissingScopes(Lint):
class MissingStaticScope(Lint):
name = "missing static scope"
recommendation = (
"Add a static scope for the rule (file, function, basic block, instruction, or unspecified/unsupported)"
)
recommendation = "Add a static scope for the rule (file, function, basic block, instruction, or unsupported)"
def check_rule(self, ctx: Context, rule: Rule):
return "static" not in rule.meta.get("scopes")
@@ -176,7 +174,7 @@ class MissingStaticScope(Lint):
class MissingDynamicScope(Lint):
name = "missing dynamic scope"
recommendation = "Add a dynamic scope for the rule (file, process, thread, call, or unspecified/unsupported)"
recommendation = "Add a dynamic scope for the rule (file, process, thread, call, or unsupported)"
def check_rule(self, ctx: Context, rule: Rule):
return "dynamic" not in rule.meta.get("scopes")
@@ -184,9 +182,7 @@ class MissingDynamicScope(Lint):
class InvalidStaticScope(Lint):
name = "invalid static scope"
recommendation = (
"For the static scope, use either: file, function, basic block, instruction, or unspecified/unsupported"
)
recommendation = "For the static scope, use either: file, function, basic block, instruction, or unsupported"
def check_rule(self, ctx: Context, rule: Rule):
return rule.meta.get("scopes").get("static") not in (
@@ -194,14 +190,13 @@ class InvalidStaticScope(Lint):
"function",
"basic block",
"instruction",
"unspecified",
"unsupported",
)
class InvalidDynamicScope(Lint):
name = "invalid static scope"
recommendation = "For the dynamic scope, use either: file, process, thread, call, or unspecified/unsupported"
recommendation = "For the dynamic scope, use either: file, process, thread, call, or unsupported"
def check_rule(self, ctx: Context, rule: Rule):
return rule.meta.get("scopes").get("dynamic") not in (
@@ -209,7 +204,6 @@ class InvalidDynamicScope(Lint):
"process",
"thread",
"call",
"unspecified",
"unsupported",
)
@@ -219,8 +213,8 @@ class InvalidScopes(Lint):
recommendation = "At least one scope (static or dynamic) must be specified"
def check_rule(self, ctx: Context, rule: Rule):
return (rule.meta.get("scopes").get("static") in ("unspecified", "unsupported")) and (
rule.meta.get("scopes").get("dynamic") in ("unspecified", "unsupported")
return (rule.meta.get("scopes").get("static") == "unsupported") and (
rule.meta.get("scopes").get("dynamic") == "unsupported"
)