Skip to content

Commit

Permalink
QL: Merge pull request github#54 from github/aschackmull/singleton-set
Browse files Browse the repository at this point in the history
New query: Singleton set literal.
  • Loading branch information
aschackmull authored Oct 13, 2021
2 parents fed3d80 + f71acdf commit 87910e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ql/src/codeql_ql/ast/Ast.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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) }

Expand Down
15 changes: 15 additions & 0 deletions ql/src/queries/style/SingletonSetLiteral.ql
Original file line number Diff line number Diff line change
@@ -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."

0 comments on commit 87910e8

Please sign in to comment.