Skip to content

Commit 87910e8

Browse files
authored
QL: Merge pull request github#54 from github/aschackmull/singleton-set
New query: Singleton set literal.
2 parents fed3d80 + f71acdf commit 87910e8

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

ql/src/codeql_ql/ast/Ast.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1926,7 +1926,7 @@ class Set extends TSet, Expr {
19261926
Set() { this = TSet(set) }
19271927

19281928
/**
1929-
* Gets the ith element in the set literal expression.
1929+
* Gets the `i`th element in this set literal expression.
19301930
*/
19311931
Expr getElement(int i) { toGenerated(result) = set.getChild(i) }
19321932

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @name Singleton set literal
3+
* @description A singleton set literal can be replaced by its member.
4+
* @kind problem
5+
* @problem.severity warning
6+
* @id ql/singleton-set-literal
7+
* @tags maintainability
8+
* @precision very-high
9+
*/
10+
11+
import ql
12+
13+
from Set setlit
14+
where exists(unique(Expr e | e = setlit.getElement(_)))
15+
select setlit, "Singleton set literal can be replaced by its member."

0 commit comments

Comments
 (0)