Skip to content

Commit 5783f5d

Browse files
committed
[Fix] static-property-placement: warn on nonstatic expected-statics
Fixes #2581
1 parent 78ad0f0 commit 5783f5d

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
1010
* [`no-arrow-function-lifecycle`]: when converting from an arrow, remove the semi and wrapping parens ([#3337][] @ljharb)
1111
* [`jsx-key`]: Ignore elements inside `React.Children.toArray()` ([#1591][] @silvenon)
1212
* [`jsx-no-constructed-context-values`]: fix false positive for usage in non-components ([#3448][] @golopot)
13+
* [`static-property-placement`]: warn on nonstatic expected-statics ([#2581][] @ljharb)
1314

1415
### Changed
1516
* [Docs] [`no-unknown-property`]: fix typo in link ([#3445][] @denkristoffer)
@@ -22,6 +23,7 @@ This change log adheres to standards from [Keep a CHANGELOG](https://keepachange
2223
[#3444]: https://github.com/jsx-eslint/eslint-plugin-react/pull/3444
2324
[#3436]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3436
2425
[#3337]: https://github.com/jsx-eslint/eslint-plugin-react/issues/3337
26+
[#2581]: https://github.com/jsx-eslint/eslint-plugin-react/issues/2581
2527
[#1591]: https://github.com/jsx-eslint/eslint-plugin-react/pull/1591
2628

2729
## [7.31.8] - 2022.09.08

lib/rules/static-property-placement.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,13 @@ module.exports = {
128128
});
129129

130130
// If name is set but the configured rule does not match expected then report error
131-
if (name && config[name] !== expectedRule) {
131+
if (
132+
name
133+
&& (
134+
config[name] !== expectedRule
135+
|| (!node.static && (config[name] === STATIC_PUBLIC_FIELD || config[name] === STATIC_GETTER))
136+
)
137+
) {
132138
const messageId = ERROR_MESSAGES[config[name]];
133139
report(context, messages[messageId], messageId, {
134140
node,

tests/lib/rules/static-property-placement.js

+15
Original file line numberDiff line numberDiff line change
@@ -2186,5 +2186,20 @@ ruleTester.run('static-property-placement', rule, {
21862186
},
21872187
],
21882188
},
2189+
{
2190+
code: `
2191+
class MyComponent extends React.Component {
2192+
displayName = 'Foo';
2193+
}
2194+
`,
2195+
features: ['class fields'],
2196+
options: [STATIC_PUBLIC_FIELD],
2197+
errors: [
2198+
{
2199+
messageId: 'notStaticClassProp',
2200+
data: { name: 'displayName' },
2201+
},
2202+
],
2203+
},
21892204
]),
21902205
});

0 commit comments

Comments
 (0)