-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathUnusedParameter.ql
More file actions
33 lines (30 loc) · 988 Bytes
/
UnusedParameter.ql
File metadata and controls
33 lines (30 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/**
* @name Unused parameter.
* @description A parameter that is not used later on, or whose value is always overwritten,
* can be removed.
* @kind problem
* @problem.severity warning
* @id rb/unused-parameter
* @tags maintainability
* external/cwe/cwe-563
* quality
* @precision low
*/
import codeql.ruby.AST
import codeql.ruby.dataflow.SSA
class RelevantParameterVariable extends LocalVariable {
RelevantParameterVariable() {
exists(Parameter p |
this = p.getAVariable() and
not this.getName().charAt(0) = "_"
)
}
}
from RelevantParameterVariable v
where
not exists(Ssa::WriteDefinition def | def.getWriteAccess().getAstNode() = v.getDefiningAccess()) and
not exists(SuperCall s | s.getEnclosingCallable().getAParameter().getAVariable() = v |
// a call to 'super' without any arguments will pass on the parameter.
not exists(s.getAnArgument())
)
select v, "The parameter '" + v.getName() + "' is never used."