New query: Singleton set literal.

This commit is contained in:
Anders Schack-Mulligen
2021-10-13 09:01:54 +00:00
committed by GitHub
parent ed767b4a54
commit 79485ec5da
2 changed files with 16 additions and 1 deletions

View File

@@ -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) }

View 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."