Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prefer-stateless-function] not work with @typescript-eslint/parser #2187

Closed
clock157 opened this issue Mar 3, 2019 · 6 comments · Fixed by #2582
Closed

[prefer-stateless-function] not work with @typescript-eslint/parser #2187

clock157 opened this issue Mar 3, 2019 · 6 comments · Fixed by #2582

Comments

@clock157
Copy link

clock157 commented Mar 3, 2019

TypeError: Cannot read property 'body' of null
    at properties.some.property (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint-plugin-react@7.12.4@eslint-plugin-react/lib/rules/prefer-stateless-function.js:191:52)
    at Array.some (<anonymous>)
    at hasOtherProperties (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint-plugin-react@7.12.4@eslint-plugin-react/lib/rules/prefer-stateless-function.js:183:25)
    at Program:exit.Object.keys.forEach.component (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint-plugin-react@7.12.4@eslint-plugin-react/lib/rules/prefer-stateless-function.js:361:13)
    at Array.forEach (<anonymous>)
    at Object.Program:exit (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint-plugin-react@7.12.4@eslint-plugin-react/lib/rules/prefer-stateless-function.js:359:27)
    at updatedRuleInstructions.(anonymous function) (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint-plugin-react@7.12.4@eslint-plugin-react/lib/util/Components.js:756:75)
    at listeners.(anonymous function).forEach.listener (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint@5.15.0@eslint/lib/util/safe-emitter.js:52:26)
    at Array.forEach (<anonymous>)
    at Object.emit (/Users/puwei/Dev/code/ant-design-pro/node_modules/_eslint@5.15.0@eslint/lib/util/safe-emitter.js:49:38)
@ljharb
Copy link
Member

ljharb commented Mar 3, 2019

Can you provide the code this is failing on?

@clock157
Copy link
Author

clock157 commented Mar 3, 2019

hi, @ljharb. this is my code:

import * as React from 'react';
export interface IAvatarItemProps {
  tips: React.ReactNode;
  src: string;
  style?: React.CSSProperties;
}

export default class AvatarItem extends React.Component<IAvatarItemProps, any> {
  constructor(props: IAvatarItemProps);
}

@ljharb
Copy link
Member

ljharb commented Mar 3, 2019

Thanks!

(as an aside; you'll want to enable esModuleInterop and synthetic imports; import * as React is never correct)

@clock157
Copy link
Author

clock157 commented Mar 3, 2019

thanks for your correction @ljharb 👍

@golopot
Copy link
Contributor

golopot commented Apr 3, 2019

This bug happens because constructor(props: IAvatarItemProps) is missing function body (curly braces). In espree this is a parsing error, in ts-parser this parses successfully. Maybe it is a bug in ts-parser?

@ljharb
Copy link
Member

ljharb commented Apr 3, 2019

It seems more likely that this plugin's rules just don't anticipate something that would never be valid in JS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

3 participants