codeql icon indicating copy to clipboard operation
codeql copied to clipboard

[CLI] `query format` should keep set literal elements on separate lines

Open Marcono1234 opened this issue 1 year ago • 0 comments

Problem

(CodeQL CLI 2.17.6)

When you run codeql query format, respectively the "Format Document" action in the VS Code extension, CodeQL set literal elements are laid out to be as compact as possible.

This is an issue when in the original code the elements were intentionally on separate lines to increase readability.

For example, formatting this code:

import java

from Method m, string s
where
  s = m.getDeclaringType().getQualifiedName() + "#" + m.getName() and
  s =
    [
      "com.example.mypackage.subpackage.MyClass#myMethod",
      "com.example.otherpackage.MyClass#myMethod",
      "com.example.MyClass#myMethod",
      "com.example.anotherpackage.AnotherClass#withSomeMethod",
    ]
select m

will move "com.example.MyClass#myMethod" on the same line as the previous element:

   s =
     [
       "com.example.mypackage.subpackage.MyClass#myMethod",
-      "com.example.otherpackage.MyClass#myMethod",
-      "com.example.MyClass#myMethod",
+      "com.example.otherpackage.MyClass#myMethod", "com.example.MyClass#myMethod",
       "com.example.anotherpackage.AnotherClass#withSomeMethod",

Suggested solution

If in the original code every set literal element was on a separate line (and maybe the set literal has at least X elements), then the formatted set literal should also have all elements on separate lines.

Marcono1234 avatar Jun 29 '24 22:06 Marcono1234