Skip to content

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

@Marcono1234

Description

@Marcono1234

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions