Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 38e8c0f

Browse files
committedMar 31, 2025·
ruby: remove some FPs from rb/useless-assignment-to-local
1 parent 279e9e2 commit 38e8c0f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed
 

Diff for: ‎ruby/ql/src/queries/variables/DeadStoreOfLocal.ql

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212

1313
import codeql.ruby.AST
1414
import codeql.ruby.dataflow.SSA
15+
import codeql.ruby.ApiGraphs
1516

1617
class RelevantLocalVariableWriteAccess extends LocalVariableWriteAccess {
1718
RelevantLocalVariableWriteAccess() {
1819
not this.getVariable().getName().charAt(0) = "_" and
19-
not this = any(Parameter p).getAVariable().getDefiningAccess()
20+
not this = any(Parameter p).getAVariable().getDefiningAccess() and
21+
not exists(SuperCall s |
22+
s.getEnclosingCallable().getAParameter().getAVariable().getAnAccess() = this
23+
|
24+
// a call to 'super' without any arguments will pass on the parameter.
25+
// thus, the parameter is used, and the assignment is not useless.
26+
not exists(s.getAnArgument())
27+
) and
28+
not API::getTopLevelMember("ERB").getInstance().getAMethodCall("result").asExpr().getScope() =
29+
this.getCfgScope() and
30+
not exists(RetryStmt r | r.getCfgScope() = this.getCfgScope())
2031
}
2132
}
2233

0 commit comments

Comments
 (0)
Please sign in to comment.