Skip to content

Commit a5f2290

Browse files
committed
Merge branch 'new_rule-jsx-no-leaked-zero' of https://github.com/Belco90/eslint-plugin-react into new_rule-jsx-no-leaked-zero
2 parents ad3589f + 95883de commit a5f2290

33 files changed

+588
-330
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
99
* [`destructuring-assignment`]: add option `destructureInSignature` ([#3235][] @golopot)
1010
* [`no-unknown-property`]: Allow crossOrigin on image tag (SVG) ([#3251][] @zpao)
1111
* [`jsx-tag-spacing`]: Add `multiline-always` option ([#3260][] @Nokel81)
12+
* [`function-component-definition`]: replace `var` by `const` in certain situations ([#3248][] @JohnBerd @SimeonC)
1213

1314
### Fixed
1415
* [`hook-use-state`]: Allow UPPERCASE setState setter prefixes ([#3244][] @duncanbeevers)
@@ -24,7 +25,9 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2425
* [Refactor] improve performance for detecting class components ([#3267][] @golopot)
2526
* [Refactor] [`no-deprecated`]: improve performance ([#3271][] @golopot)
2627
* [Refactor] [`no-did-mount-set-state`], [`no-did-update-set-state`], [`no-will-update-set-state`]: improve performance ([#3272][] @golopot)
28+
* [Refactor] improve performance by avoiding unnecessary `Components.detect` ([#3273][] @golopot)
2729

30+
[#3273]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3273
2831
[#3272]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3272
2932
[#3271]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3271
3033
[#3267]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3267
@@ -36,6 +39,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
3639
[#3258]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3258
3740
[#3254]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3254
3841
[#3251]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3251
42+
[#3248]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3248
3943
[#3244]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3244
4044
[#3235]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3235
4145
[#3230]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3230

docs/rules/function-component-definition.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Examples of **incorrect** code for this rule:
1212

1313
```jsx
1414
// function expression for named component
15-
var Component = function (props) {
15+
const Component = function (props) {
1616
return <div>{props.content}</div>;
1717
};
1818

1919
// arrow function for named component
20-
var Component = (props) => {
20+
const Component = (props) => {
2121
return <div>{props.content}</div>;
2222
};
2323

@@ -49,11 +49,11 @@ Examples of **incorrect** code for this rule:
4949
```jsx
5050
// only function declarations for named components
5151
// [2, { "namedComponents": "function-declaration" }]
52-
var Component = function (props) {
52+
const Component = function (props) {
5353
return <div />;
5454
};
5555

56-
var Component = (props) => {
56+
const Component = (props) => {
5757
return <div />;
5858
};
5959

@@ -63,7 +63,7 @@ function Component (props) {
6363
return <div />;
6464
};
6565

66-
var Component = (props) => {
66+
const Component = (props) => {
6767
return <div />;
6868
};
6969

@@ -73,7 +73,7 @@ function Component (props) {
7373
return <div />;
7474
};
7575

76-
var Component = function (props) {
76+
const Component = function (props) {
7777
return <div />;
7878
};
7979

@@ -107,13 +107,13 @@ function Component (props) {
107107

108108
// only function expressions for named components
109109
// [2, { "namedComponents": "function-expression" }]
110-
var Component = function (props) {
110+
const Component = function (props) {
111111
return <div />;
112112
};
113113

114114
// only arrow functions for named components
115115
// [2, { "namedComponents": "arrow-function" }]
116-
var Component = (props) => {
116+
const Component = (props) => {
117117
return <div />;
118118
};
119119

@@ -170,11 +170,11 @@ The following patterns can **not** be autofixed in TypeScript:
170170
```tsx
171171
// function expressions and arrow functions that have type annotations cannot be autofixed to function declarations
172172
// [2, { "namedComponents": "function-declaration" }]
173-
var Component: React.FC<Props> = function (props) {
173+
const Component: React.FC<Props> = function (props) {
174174
return <div />;
175175
};
176176

177-
var Component: React.FC<Props> = (props) => {
177+
const Component: React.FC<Props> = (props) => {
178178
return <div />;
179179
};
180180

@@ -184,7 +184,7 @@ function Component<T>(props: Props<T>) {
184184
return <div />;
185185
};
186186

187-
var Component = function <T>(props: Props<T>) {
187+
const Component = function <T>(props: Props<T>) {
188188
return <div />;
189189
};
190190

@@ -203,13 +203,13 @@ The following patterns can be autofixed in TypeScript:
203203
```tsx
204204
// autofix to function expression with type annotation
205205
// [2, { "namedComponents": "function-expression" }]
206-
var Component: React.FC<Props> = (props) => {
206+
const Component: React.FC<Props> = (props) => {
207207
return <div />;
208208
};
209209

210210
// autofix to arrow function with type annotation
211211
// [2, { "namedComponents": "function-expression" }]
212-
var Component: React.FC<Props> = function (props) {
212+
const Component: React.FC<Props> = function (props) {
213213
return <div />;
214214
};
215215

@@ -219,7 +219,7 @@ function Component<T extends {}>(props: Props<T>) {
219219
return <div />;
220220
}
221221

222-
var Component = function <T extends {}>(props: Props<T>) {
222+
const Component = function <T extends {}>(props: Props<T>) {
223223
return <div />;
224224
};
225225

@@ -229,7 +229,7 @@ function Component<T1, T2>(props: Props<T1, T2>) {
229229
return <div />;
230230
}
231231

232-
var Component = function <T1, T2>(props: Props<T2>) {
232+
const Component = function <T1, T2>(props: Props<T2>) {
233233
return <div />;
234234
};
235235

lib/rules/display-name.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const values = require('object.values');
99

1010
const Components = require('../util/Components');
1111
const astUtil = require('../util/ast');
12+
const componentUtil = require('../util/componentUtil');
1213
const docsUrl = require('../util/docsUrl');
1314
const propsUtil = require('../util/props');
1415
const report = require('../util/report');
@@ -106,7 +107,7 @@ module.exports = {
106107
astUtil.isFunctionLikeExpression(node)
107108
&& node.parent
108109
&& (node.parent.type === 'VariableDeclarator' || node.parent.type === 'Property' || node.parent.method === true)
109-
&& (!node.parent.parent || !utils.isES5Component(node.parent.parent))
110+
&& (!node.parent.parent || !componentUtil.isES5Component(node.parent.parent, context))
110111
);
111112

112113
if (
@@ -192,7 +193,7 @@ module.exports = {
192193
},
193194

194195
ObjectExpression(node) {
195-
if (!utils.isES5Component(node)) {
196+
if (!componentUtil.isES5Component(node, context)) {
196197
return;
197198
}
198199
if (ignoreTranspilerName || !hasTranspilerName(node)) {

0 commit comments

Comments
 (0)