NullVoxPopuli / eslint-plugin-decorator-position

ESLint plugin for enforcing decorator position
MIT License
51 stars 10 forks source link

Allowing inline decorators for multi-line expressions? #707

Open davidtaylorhq opened 1 year ago

davidtaylorhq commented 1 year ago

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 commented 1 year ago

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

Also, can you provide your prettier settings? Thanks!

davidtaylorhq commented 1 year ago

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

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