mark-wiemer-org/ahkpp

Formatter incorrectly indents object literals

Closed this issue · 1 comments

Description

The formatter does not behave properly on multi-line object literal assignments.

Unformatted input snippet

PF= C:\Program Files
PF86= C:\Program Files (x86)

; first version
AppPaths := {
    "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
    , "bar.exe" : PF86 . "bar\bar.exe"
}

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe" : PF86 . "\foo\foo.exe"
            , "bar.exe" : PF86 . "bar\bar.exe" }

Expected formatted output snippet

; first version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe"       : PF86 . "\foo\foo.exe"
            , "bar.exe"       : PF86 . "bar\bar.exe" }

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
            , "foo.exe"       : PF86 . "\foo\foo.exe"
            , "bar.exe"       : PF86 . "bar\bar.exe" }

Note:

  1. The first version is not actually valid syntax in AHK as written. I'm not sure if it's fair to expect the formatter to fix this, but if it's not it would be helpful if the extension recognised and highlighted the error during editing
  2. lining up the colons vertically is nice, but perhaps a lot to ask

Actual formatted output snippet

; first version
AppPaths := {
    "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
    , "bar.exe" : PF86 . "bar\bar.exe"
}

; second version
AppPaths := { "PowerToys.exe" : PF . "\Other\PowerToys\PowerToys.exe"
    , "foo.exe" : PF86 . "\foo\foo.exe"
, "bar.exe" : PF86 . "bar\bar.exe" }

Additional context

Note:

  1. The formatter ignores the first version, possibly because it is not valid syntax?
  2. However the second version is recognised and reformatted, but the result is ugly with the indenting being prgressively reduced on succesive lines
  3. This issue would seem to be related to Issue ID #184 (same title) but-
    a) #184 seems to relate to object literals defined as the return values of functions (true?)
    b) The example provided in #184 uses the "one true brace" style-
    function(){
        ...
    }

but this is a syntax error in AHK for object literals (which I was rather hoping the formatter woudl fix for me automatically, per my example). Object literals in AHK require the opening and closing braces to be on the same line as the immediately following/preceding expressions.

It's about broken formatting of continuation sections. I had it in my TODO list of feature fixes.