-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Declaring context type on class component breaks static-property-placement #3467
Comments
I ran into the same problem and started digging into the source code of lint rules for the first time. I don't understand enough yet to propose a fix but if it helps this could be a test case to reproduce it, which fails if I add it to the {
code: `
class MyComponent extends React.Component {
static contextTypes = {
something: PropTypes.bool
};
declare context: MyContext;
}
`,
features: ['ts'],
options: [STATIC_PUBLIC_FIELD],
}, I will look around a bit more. Even if I don't find a fix it's a good learning experience! |
@ljharb the snippet you mentioned is indeed identifying the Removing this check fixes the failing tests I added and doesn't break any other tests, but as you said they were just missing so there's a risk that it breaks something else. Another possibility is checking if there is already a sibling that looks like a // Flow support
if (node.typeAnnotation && node.key.name === 'context') {
return !node.parent.body.some((sibling) => isContextTypesDeclaration(sibling));
} |
Yeah, that doesn't feel like a safe approach. You might be right that it should never have been added, and that it's safe to remove, but I'm hesitant to do that without hearing from @jomasti. |
Starting in version 7.31.9 of eslint-plugin-react, this rule has a bug where it talks about `contextTypes` when in reality we don't have and never want a `contextTypes`: jsx-eslint/eslint-plugin-react#3467 Just disable the rule -- it's not a valuable enough rule to spend effort hacking around the bug.
Starting in version 7.31.9 of eslint-plugin-react, this rule has a bug where it talks about `contextTypes` when in reality we don't have and never want a `contextTypes`: jsx-eslint/eslint-plugin-react#3467 Just disable the rule -- it's not a valuable enough rule to spend effort hacking around the bug.
Starting in version 7.31.9 of eslint-plugin-react, this rule has a bug where it talks about `contextTypes` when in reality we don't have and never want a `contextTypes`: jsx-eslint/eslint-plugin-react#3467 Just disable the rule -- it's not a valuable enough rule to spend effort hacking around the bug.
Starting in version 7.31.9 of eslint-plugin-react, this rule has a bug where it talks about `contextTypes` when in reality we don't have and never want a `contextTypes`: jsx-eslint/eslint-plugin-react#3467 Just disable the rule -- it's not a valuable enough rule to spend effort hacking around the bug.
Sorry, I haven't kept up with notifications at all.
I believe #1533 is the PR instead. That has the change specific to context. It has been quite a while, but I assume I was copying the implementation of |
Sounds good, let’s remove it |
Hi,
After upgrading
eslint-plugin-react
from 7.31.8 to 7.31.9+ (#2581), it started breaking thedeclare
keyword on context in TypeScript:Not sure what is the mitigation in this case
The text was updated successfully, but these errors were encountered: