jsx-eslint / eslint-plugin-react

React-specific linting rules for ESLint
MIT License
9k stars 2.77k forks source link

[prefer-stateless-function] should check if component has ES7 decorator #501

Closed dmt0 closed 2 years ago

dmt0 commented 8 years ago

ES7 decorators only work with classes and not with functions. If a decorator is present [react/prefer-stateless-function] should not be recommended.

ljharb commented 8 years ago

Decorators are not ES7, and part of the proposal absolutely might be that they work with function declarations. They also certainly work with concise object methods as well.

Kerumen commented 8 years ago

Related https://github.com/yannickcr/eslint-plugin-react/issues/491#issuecomment-196749779

thewillhuang commented 8 years ago

@ljharb thats great and all, but the current proposal is with classes, and until that has been agreed upon and or implemented this is still a false positive and a bug. see https://github.com/wycats/javascript-decorators, first line in the summery for decorators.

Decorators make it possible to annotate and modify classes and properties at design time.

ljharb commented 8 years ago

@thewillhuang "and properties". https://github.com/wycats/javascript-decorators#object-literal-method-declaration - it is NOT a bug, it is an essential part of the proposal.

thewillhuang commented 8 years ago

@ljharb ah i see, missed that part completely

ljharb commented 2 years ago

Decorators remain stage 2, and have changed 3-4 times since this was filed.

However, we do support them via the TS eslint parser.

Additionally, the likely state of the proposal will exclude functions, so we should use the presence of a class decorator as an indication that the component should not be a stateless function.

golopot commented 2 years ago

fixed in https://github.com/jsx-eslint/eslint-plugin-react/pull/1086