Skip to content

Put decorators on the same line#459

Merged
jlongster merged 1 commit intoprettier:masterfrom
vjeux:decorator
Jan 25, 2017
Merged

Put decorators on the same line#459
jlongster merged 1 commit intoprettier:masterfrom
vjeux:decorator

Conversation

@vjeux
Copy link
Copy Markdown
Contributor

@vjeux vjeux commented Jan 25, 2017

Mobx is the only popular JavaScript library that I know about which uses decorators. They put things on the same line so we should follow their conventions.

The logic implemented here is the following: if there is one decorator, it's on the same line. If there is more than one, they are each on their own line.

Fixes #325

@vramana
Copy link
Copy Markdown

vramana commented Jan 25, 2017

redux connect can also be used with a decorator. But the decorator is placed above the class.

@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Jan 25, 2017

@vramana good call! It seems like redux connect takes arguments. We likely don't want decorators with arguments to be inlined. Let me encode this rule as well!

Mobx is the only popular JavaScript library that I know about which uses decorators. They put things on the same line so we should follow their conventions.

The logic implemented here is the following: if there is one decorator, it's on the same line. If there is more than one, they are each on their own line.

Fixes prettier#325
@vjeux
Copy link
Copy Markdown
Contributor Author

vjeux commented Jan 25, 2017

Done, now it has to be a single decorator AND just an identifier to be inlined.

I also tried to enable flow decorator support but it only supports half of the decorators in the tests and has a different AST structure, so it's not worth using it.

@jlongster
Copy link
Copy Markdown
Member

Thanks, looks good!

@jlongster jlongster merged commit 888c7a5 into prettier:master Jan 25, 2017
@egeozcan
Copy link
Copy Markdown

egeozcan commented Oct 8, 2017

Is there a possibility to make this configurable? I personally really dislike decorators being in the same line. Makes it very hard to browse the class properties.

  @Entity("Todos")
  export class Todo implements ITodo {
    @PrimaryGeneratedColumn("uuid") public id?: string;
    @Column() public text: string;
    @Column() public completed: boolean;
  }

@RemyRylan
Copy link
Copy Markdown

@jlongster @vjeux @vramana I agree highly with @egeozcan -- would love to see this be a configurable value. If I submit a PR, would the team be up for merging it or is everyone set on keeping things as is?

@JoshuaKGoldberg
Copy link
Copy Markdown

+1. This is very annoying, especially with Inversify.

public constructor(
    @inject(MyStoreStore) public readonly myStore: MyStore,
    @inject(InjectionTypes.StyleProvider) public readonly styleProvider: IStyleProvider,
) { }

Relevant issue: #1974

@duailibe
Copy link
Copy Markdown
Collaborator

@JoshuaKGoldberg Please open a new issue, filling the template

@prettier prettier locked as resolved and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants