tslint-eslint-rules icon indicating copy to clipboard operation
tslint-eslint-rules copied to clipboard

Missing newline rules to achieve consistent trailing comma handling

Open feedm3 opened this issue 7 years ago • 3 comments

There are some missing rules in this repository regarding "newline", which are part of ESLint.

  • function-paren-newline
  • object-curly-newline
  • array-bracket-newline
  • array-element-newline

All those rules are needed to have a consistent "Additional trailing comma" handling in our code.

Is there a reason why those rules are missing or a plan to add them? If not, is there an alternative to achieve the trailing comma handling?

feedm3 avatar Aug 03 '18 08:08 feedm3

I've been using https://palantir.github.io/tslint/rules/trailing-comma/, and this is how I have configured it so that it can achieve the same style as airbnb.

"trailing-comma": [
      true,
      {
        "multiline": "always",
        "singleline": "never",
        "esSpecCompliant": true
      }
    ],

It does have a bug though:

https://github.com/palantir/tslint/issues/3870

Is there something in that rule that doesn't allow you to have code style your project needs?

jmlopez-rod avatar Aug 15 '18 13:08 jmlopez-rod

Thanks for your reply!

That's what I'm currently using. The problem here is that I need additional rules, to make multiple parameters are forced to be multiline and not singleline.

For example function paramters:

// bad, but  valid
export function test(
  paramOne: string,
  paramTow: string) { 
  ...
}

// good
export function test(
  paramOne: string,
  paramTow: string,
  ) {
  ...
}

Or object declarations:

// bad, but valid
const object = { varOne: 'test', varTwo: 'test' };

// good
const object = {
  varOne: 'test',
  varTwo: 'test',
};

To make multiline mandatory I need the rules listed in my first post.

Do you know how I can enable these rules or know another solution for my problem?

feedm3 avatar Aug 28 '18 07:08 feedm3

Ah, I see what you are saying now. Yeah, the rules you mentioned above are necessary. PRs are welcome to any of these rules.

jmlopez-rod avatar Aug 29 '18 17:08 jmlopez-rod