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 documentation is wrong #588

Closed
MichalZalecki opened this issue May 6, 2016 · 7 comments
Closed

prefer-stateless-function documentation is wrong #588

MichalZalecki opened this issue May 6, 2016 · 7 comments
Labels

Comments

@MichalZalecki
Copy link

Hi!

I'm facing false positive for rule prefer-stateless-function with latest dependencies.

image

// .eslintrc.json
{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "settings": {
    "import/resolver": {
      "webpack": { "config": "./webpack/webpack.prod.config.js" }
    }
  },
  "env": {
    "jasmine": true
  },
  "rules": {
    "quotes": ["error", "double"],
    "no-unused-vars": [2, { "vars": "local", "args": "after-used", "argsIgnorePattern": "^_" }]
  }
}
// package.json
"babel-eslint": "^6.0.4",
"eslint": "^2.9.0",
"eslint-config-airbnb": "^8.0.0",
"eslint-import-resolver-webpack": "^0.2.4",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-jsx-a11y": "^1.0.4",
"eslint-plugin-react": "^5.0.1",
@philiiiiiipp
Copy link

I have the same issue

"eslint": "^2.8.0",
"eslint-config-airbnb": "^8.0.0",
"eslint-plugin-import": "^1.6.1",
"eslint-plugin-jsx-a11y": "^1.0.3",
"eslint-plugin-react": "^5.0.1",

eslint.rc:

{
  "eslintignore": [
    "build",
    "node_modules"
  ],
  "parser": "babel-eslint",
  "extends": "airbnb",
  "globals": {
    "__DEV__": true
  },
  "env": {
    "browser": true
  },
  "rules": {
    "indent": [
      "warn",
      2
    ],
    "comma-dangle": [
      "error",
      "never"
    ],
    "arrow-body-style": [
      "error",
      "always"
    ],
    "no-confusing-arrow": 0,
    "react/jsx-quotes": 0,
    "jsx-quotes": [
      2,
      "prefer-single"
    ]
  }
}

The file in question:

export default class App extends Component {
  render() {
    return (
      <Router routes={routes} history={browserHistory} />
    );
  }
}

@ljharb
Copy link
Member

ljharb commented May 6, 2016

These are not false positives. A class-based component that has nothing but a render method should be an SFC instead.

@philiiiiiipp
Copy link

philiiiiiipp commented May 6, 2016

Ah true, I see. Should have looked more closely at the explanation

@ljharb
Copy link
Member

ljharb commented May 6, 2016

@MichalZalecki i'm going to close this, but will be happy to reopen if further clarification is needed

@ljharb ljharb closed this as completed May 6, 2016
@ljharb ljharb added the invalid label May 6, 2016
@MichalZalecki
Copy link
Author

@ljharb According to this doc, yes https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/prefer-stateless-function.md

Look at "The following patterns are not considered warnings:". 2. example is failing on that rule.

@ljharb ljharb added bug and removed invalid labels May 7, 2016
@ljharb
Copy link
Member

ljharb commented May 7, 2016

Hmm, you're right. I think the documentation is wrong then.

@ljharb ljharb reopened this May 7, 2016
@ljharb ljharb changed the title False positive prefer-stateless-function prefer-stateless-function documentation is wrong May 7, 2016
@ljharb
Copy link
Member

ljharb commented May 7, 2016

@MichalZalecki ah, i think i get the difference - in React 15, SFCs can return null. So, that example should only not be a warning in React 0.13 or 0.14.

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

No branches or pull requests

3 participants