Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Marcono1234 opened this issue Jun 29, 2024 · 3 comments
Closed
Labels
question Further information is requested

Comments

@Marcono1234
Copy link
Contributor

Marcono1234 commented Jun 29, 2024

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 Marcono1234 added the question Further information is requested label Jun 29, 2024
@smowton
Copy link
Contributor

smowton commented Jul 5, 2024

Go on then -- I've made an internal PR to tolerate one-per-line style if already present; it might make it into 2.18.0 or .1

@Marcono1234
Copy link
Contributor Author

Thanks a lot! Could you please close this issue then if / once this is available in a CodeQL release version?

(Also I hope you actually find that feature useful as well)

@smowton
Copy link
Contributor

smowton commented Jul 12, 2024

The autoformatter will allow this from 2.18.1 onwards.

In particular, if the array already has max one item per source line, it will regularise to item-per-line style; if there is any existing line with multiple items, it will pack them to lines as it did before 2.18.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants