eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

[react/jsx-indent] False positive

Open Robloche opened this issue 3 years ago • 5 comments

My code was OK until version 7.28.0 but fails with multiple react/jsx-indent errors in versions 7.29.0-3.

Example:

    render(): React.Node {
      const {forwardedRef, isDisabled, key} = this.props;

      return <WrappedComponent
        forwardedRef={forwardedRef}
        isDisabled={isDisabled}
        key={key}
        svgElement={svgElement} />;
    }

Error: ESLint: Expected indentation of 6 space characters but found 8.(react/jsx-indent)

Applying autofix gives me this:

    render(): React.Node {
      const {forwardedRef, isDisabled, key} = this.props;

      return <WrappedComponent
        forwardedRef={forwardedRef}
        isDisabled={isDisabled}
        key={key}
      svgElement={svgElement} />;
    }

which leads to: ESLint: Expected indentation of 8 space characters but found 6.(react/jsx-indent-props)

Robloche avatar Mar 08 '22 16:03 Robloche

How is your eslint configured?

ljharb avatar Mar 08 '22 16:03 ljharb

"react/jsx-indent": ["error", 2],

Robloche avatar Mar 09 '22 11:03 Robloche

Thanks; i reproduced this with failing tests, but wasn’t able to come up with an easy fix. Help is appreciated.

ljharb avatar Mar 09 '22 15:03 ljharb

Have you tried formatting as follows?

      return <WrappedComponent
        forwardedRef={forwardedRef}
        isDisabled={isDisabled}
        key={key}
        svgElement={svgElement} />
      ;

saraadams avatar May 20 '22 05:05 saraadams

This gives me a new error: semi-style (semicolon is expected to be at the end of the previous line)

Robloche avatar May 20 '22 07:05 Robloche