diff --git a/ql/src/codeql_ql/ast/Ast.qll b/ql/src/codeql_ql/ast/Ast.qll index 4d8da8d8ee5..367355e2e5d 100644 --- a/ql/src/codeql_ql/ast/Ast.qll +++ b/ql/src/codeql_ql/ast/Ast.qll @@ -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) } diff --git a/ql/src/queries/style/SingletonSetLiteral.ql b/ql/src/queries/style/SingletonSetLiteral.ql new file mode 100644 index 00000000000..c05b3dca71d --- /dev/null +++ b/ql/src/queries/style/SingletonSetLiteral.ql @@ -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."