Skip to content

formatexpr is broken #261

Open
Open
@romainl

Description

@romainl

Steps to reproduce

  1. Put the following content in foo.ts (TypeScript sample taken from https://prettier.io/playground/):

    interface MyInterface {
      foo(): string,
      bar: Array<number>,
    }
    
    export abstract class Foo implements MyInterface {
      foo() {
                // TODO: return an actual value here
            return 'hello'
          }
      get bar() {
        return [  1,
    
          2, 3,
        ]
      }
    }
    
    type RequestType = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'OPTIONS' | 'CONNECT' | 'DELETE' | 'TRACE'
    
  2. Open it in a clean Vim:

    $ vim --clean foo.ts
    
  3. Format the whole buffer with the built-in formatexpr:

    gggqG
    
  4. Enjoy:

    interface MyInterface { foo(): string, bar: Array<number>, } export abstract class Foo implements MyInterface { foo() { // TODO: return an actual value here return 'hello' } get bar() { return [  1, 2, 3, ] } } type RequestType = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'OPTIONS' | 'CONNECT' | 'DELETE' | 'TRACE'
    

Expected behaviour

Something that generally looks like the input, but with better formatting, alignment, etc. Anything but everything mashed into a single line, really.

Version of Vim

9.0.20, 9.0.472, 9.0.828, 9.0.1276, 9.01313

Environment

Operating system: macOS 12.6.1 and now 13.3.1 but irrelevant
Terminal: irrelevant
$TERM: irrelevant
Shell: irrelevant

Other considerations

The FixedGq() in $VIMRUNTIME/indent/typescript.vim and the one in this repo are essentially (not exactly) identical but I am not sure if there is an official maintainer for Vim's TS runtime file or if there is some kind of official relationship between this repo and Vim's TS runtime files. Either way, the one in Vim and this one are both broken.

Mirror issue opened in Vim's issue tracker: vim/vim#11493

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions