palantir / tslint-react

:orange_book: Lint rules related to React & JSX for TSLint.
Apache License 2.0
749 stars 76 forks source link

jsx-wrap-multiline + React 16 fragments #118

Closed whatisaphone closed 7 years ago

whatisaphone commented 7 years ago

React 16 allows you to return an array from a render function, which brings up a new pattern that's possibly worth supporting. The rule flags the first div in this code as an error due to missing parentheses:

class MyComponent extends React.Component {
  public render() {
    return [
      <div>
        <SomeCrazyLongComponent />
      </div>,
      <div>
        <OtherCrazyLongComponent />
      </div>,
    ];
  }
}

The suggested fix wastes a lot of space and doesn't gain anything readability-wise:

class MyComponent extends React.Component {
  public render() {
    return [
      (
        <div>
          <SomeCrazyLongComponent />
        </div>
      ),
      (
        <div>
          <OtherCrazyLongComponent />
        </div>
      ),
    ];
  }
}

What do you think about changing the rule to support cases like this? My suggested criteria is that the opening and closing (if present) angle brackets starting in the same column should cause the code to be OK under this rule. From my brief glance at the tests, all the cases would stay the same under this change.

adidahiya commented 7 years ago

This is basically the same as https://github.com/palantir/tslint-react/issues/79#issuecomment-289923337 and I would absolutely accept a PR to make the rule more lenient here.

whatisaphone commented 7 years ago

Whoops sorry, I tried searching but clearly I didn't search well enough. I'll take the liberty of closing this as a dup