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

Allowing inline decorators for multi-line expressions? #707

Open
davidtaylorhq opened this issue Aug 4, 2023 · 2 comments
Open

Allowing inline decorators for multi-line expressions? #707

davidtaylorhq opened this issue Aug 4, 2023 · 2 comments

Comments

@davidtaylorhq
Copy link
Contributor

In Discourse, we have a handful of property decorators like this:

// decorator-position ❌
class Blah {
  @tracked somePropertyName =
    this.some.long.property.which.extend.beyond.printWidth;
}

Prettier breaks this onto two lines, and keeps the @tracked somePropertyName 'inline', which is great. We'd like to keep this formatting.

Unfortunately the decorator-position eslint rule fails. It wants to move the decorator onto a line by itself, leaving us with this:

// decorator-position ✅
class Blah {
  @tracked
  somePropertyName =
    this.some.long.property.which.extend.beyond.printWidth;
}

A similar problem can be demonstrated with ternary expressions:

// decorator-position ❌
class Blah {
  @tracked somePropertyName = this.someBoolean
    ? "resultIfTrue"
    : "thisIsTheValueIfFalse";
}
// decorator-position ✅
class Blah {
  @tracked
  somePropertyName = this.someBoolean
    ? "resultIfTrue"
    : "thisIsTheValueIfFalse";
}

Interestingly, multi-line function invocations seem to be accepted by the rule:

// decorator-position ✅
class Blah {
  @tracked somePropertyName = this.someFunction(
    "argumentValueOne",
    "argumentValueTwo"
  );
}

Would it be possible to have the decorator-position rule accept the two ❌ cases described above?

@NullVoxPopuli
Copy link
Owner

Yeah, i think it's doable! Thanks for the code snippets!

Also, can you provide your prettier settings? Thanks!

@davidtaylorhq
Copy link
Contributor Author

Prettier config is here - we use the default lineWidth of 80.

Our eslint config has decorator-position configured with a matching lineWidth of 80

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

No branches or pull requests

2 participants