Skip to content

Keep parameter decorators on different lines as parameter when possible (Babylon, TypeScript) #4922

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Prettier 1.14.0
Playground link

# Options (if any):
--parser typescript --trailing-comma all

Input:

class Foo {
  constructor(
    @inject(Bar)
    private readonly bar: IBar,

    @inject(MyProcessor)
    private readonly myProcessor: IMyProcessor, 

    @inject(InjectionTypes.AnotherThing)
    private readonly anotherThing: IAnotherThing | undefined,
  ) { }
}

Output:

class Foo {
  constructor(
    @inject(Bar) private readonly bar: IBar,
    @inject(MyProcessor) private readonly myProcessor: IMyProcessor,
    @inject(InjectionTypes.AnotherThing)
    private readonly anotherThing: IAnotherThing | undefined,
  ) {}
}

Expected behavior:

It's very difficult to read constructor parameters when they're on the same line and have irregular levels of starting indentation. The input is what you would expect a well-formatted document to look like.

Counterpart to #1974. I'd personally prefer to just send a revert PR for #459 (@vjeux) as this code sample is very common with libraries such as http://inversify.io. If it's desirable to have the current behavior, I'd also be more than happy to send a PR that adds a flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    lang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.status:needs discussionIssues needing discussion and a decision to be made before action can be taken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions