mirror of
https://github.com/github/codeql.git
synced 2026-02-08 11:11:06 +01:00
New query: Singleton set literal.
This commit is contained in:
committed by
GitHub
parent
ed767b4a54
commit
79485ec5da
@@ -1926,7 +1926,7 @@ class Set extends TSet, Expr {
|
||||
Set() { this = TSet(set) }
|
||||
|
||||
/**
|
||||
* Gets the ith element in the set literal expression.
|
||||
* Gets the `i`th element in this set literal expression.
|
||||
*/
|
||||
Expr getElement(int i) { toGenerated(result) = set.getChild(i) }
|
||||
|
||||
|
||||
15
ql/src/queries/style/SingletonSetLiteral.ql
Normal file
15
ql/src/queries/style/SingletonSetLiteral.ql
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @name Singleton set literal
|
||||
* @description A singleton set literal can be replaced by its member.
|
||||
* @kind problem
|
||||
* @problem.severity warning
|
||||
* @id ql/singleton-set-literal
|
||||
* @tags maintainability
|
||||
* @precision very-high
|
||||
*/
|
||||
|
||||
import ql
|
||||
|
||||
from Set setlit
|
||||
where exists(unique(Expr e | e = setlit.getElement(_)))
|
||||
select setlit, "Singleton set literal can be replaced by its member."
|
||||
Reference in New Issue
Block a user