eslint / typescript-eslint-parser

An ESLint custom parser which leverages TypeScript ESTree to allow for ESLint to lint TypeScript source code.
Other
915 stars 75 forks source link

React plugin with jsx-sort-props rule throws AssertionError. #401

Closed phyllisstein closed 6 years ago

phyllisstein commented 6 years ago

What version of TypeScript are you using? 2.5.3

What version of typescript-eslint-parser are you using? 8.0.1

What code were you trying to parse?

class App extends React.PureComponent {
  render() {
    return [
      <Helmet defaultTitle='Queerly ambitious publishing. ✦ Ignota Works' key='helmet' titleTemplate='%s ✦ Ignota Works'>
        <html lang='en' />

        <meta charSet='utf-8' />
        <meta content='IE=edge,chrome=1' httpEquiv='X-UA-Compatible' />
        <meta content={ SITE_NAME } name='apple-mobile-web-app-title' />
        <meta content={ SITE_NAME } name='application-name' />

        <link rel='shortcut icon' href={ imageFaviconICO } type='image/x-icon' />
      </Helmet>,
    ]
  }
}

What did you expect to happen? The react/jsx-sort-props rule should report an error on the link tag, and suggest href, rel, type as the correct order, but linting should otherwise be successful.

What happened? An AssertionError was thrown:

AssertionError [ERR_ASSERTION]: Fix objects must not be overlapped in a report.
    at mergeFixes (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/report-translator.js:149:9)
    at normalizeFixes (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/report-translator.js:179:16)
    at /Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/report-translator.js:270:18
    at Object.report (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/linter.js:894:62)
    at JSXOpeningElement.node.attributes.reduce (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint-plugin-react/lib/rules/jsx-sort-props.js:301:21)
    at Array.reduce (<anonymous>)
    at JSXOpeningElement (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint-plugin-react/lib/rules/jsx-sort-props.js:212:25)
    at listeners.(anonymous function).forEach.listener (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/daniel/Repos/Ignota/disibodenberg/node_modules/eslint/lib/util/safe-emitter.js:47:38)
phyllisstein commented 6 years ago

Updated to reflect the fact that I can now reproduce the error with both the stable and the dev builds of TypeScript installed.

JamesHenry commented 6 years ago

Thanks @phyllisstein, have you confirmed this does not happen when using espree (ESLint's default parser)?

phyllisstein commented 6 years ago

Yup, I can verify that this works as expected with espree and babel-eslint under eslint@4.13.0.

JamesHenry commented 6 years ago

@phyllisstein Please could you provide a minimal reproduction of the issue?

phyllisstein commented 6 years ago

Sorry for the delay in getting back to you on this! By the time I got here, though, typescript-eslint-parser@12.0.0, eslint-plugin-react@7.5.1, and eslint@4.15.0 were able to parse the line correctly and returned the expected error. 🙌