Skip to content

Commit

Permalink
[Fix] static-property-placement: do not report non-components
Browse files Browse the repository at this point in the history
Fixes #2884.
  • Loading branch information
golopot committed Dec 30, 2020
1 parent e2eaada commit 863e43d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/rules/static-property-placement.js
Expand Up @@ -131,7 +131,13 @@ module.exports = {
// Public
// ----------------------------------------------------------------------
return {
ClassProperty: (node) => reportNodeIncorrectlyPositioned(node, STATIC_PUBLIC_FIELD),
ClassProperty: (node) => {
if (!utils.getParentES6Component()) {
return;
}

reportNodeIncorrectlyPositioned(node, STATIC_PUBLIC_FIELD);
},

MemberExpression: (node) => {
// If definition type is undefined then it must not be a defining expression or if the definition is inside a
Expand All @@ -155,7 +161,7 @@ module.exports = {

MethodDefinition: (node) => {
// If the function is inside a class and is static getter then check if correctly positioned
if (isContextInClass() && node.static && node.kind === 'get') {
if (utils.getParentES6Component() && node.static && node.kind === 'get') {
// Report error if needed
reportNodeIncorrectlyPositioned(node, STATIC_GETTER);
}
Expand Down
20 changes: 20 additions & 0 deletions tests/lib/rules/static-property-placement.js
Expand Up @@ -181,6 +181,26 @@ ruleTester.run('static-property-placement', rule, {
};
`].join('\n')
},

{
// Do not error on non-component classes #2884
code: `
class Foo {
static get propTypes() {}
}
`
},

{
// Do not error on non-component classes #2884
code: `
class Foo {
static propTypes = {}
}
`,
options: [PROPERTY_ASSIGNMENT]
},

// ------------------------------------------------------------------------------
// no properties
// ------------------------------------------------------------------------------
Expand Down

0 comments on commit 863e43d

Please sign in to comment.