-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
no-typos rule doesn't handle custom proptypes classes #1389
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
Comments
Just for information, indeed we added logic to validate the specific PropTypes. Since Not sure how we should handle this case yet. Just explaining what changes and why the error is introduced. 😄 |
This seems like a bug in no-typos - we should only be looking for typos on |
I'm trying to work on this... I guess we need to support the following cases? Did I miss anything? import PropTypes from "prop-types"
import { PropTypes } from "react";
import { PropTypes as ValidPropTypes } from "react"
import React from "react"
React.PropTypes |
@jseminck also |
It also fails when importing specific prop types directly:
Resulting in |
same happens when using import { injectIntl, intlShape } from "react-intl";
function Example() { //code }
Example.propTypes = {
// ESLint error: 'Typo in declared prop type: isRequired (react/no-typos)'
intl: intlShape.isRequired
};
export default injectIntl(Example) you can ignore the line number in the screenshot, is just an example |
Well, this does not resolve the issue, but you can disable a rule in ESLint with a comment Foo.propTypes = {
// eslint-disable-next-line react/no-typos
bar: MyPropTypes.string.isRequired
} In this particular case I do that while this issue is open |
Same using |
Another case where webpack's In my code I don't import
and get the validators that way as webpack will replace all instances of |
@zxlin using webpack to get magic implicit imports isn't necessarily a use case we should be handling or encouraging, imo. |
Adding this for whoever looks for MobX no-typos error :) import { observer, inject, PropTypes as MobXPropTypes } from 'mobx-react';
class App extends React.Component { ...}
App.wrappedComponent.propTypes = {
appStore: MobXPropTypes.objectOrObservableObject.isRequired,
}; Produces
|
I'm working on this, so that custom PropTypes imports will be ignored and only the real "prop-types" package will be considered for checking typos. |
@jseminck also |
Same typo-error for ReactNative's style proptypes: import PropTypes from 'prop-types';
import {View} from 'react-native';
CoolComponent.propTypes = {
containerStyle: View.propTypes.style,
}; |
@jseminck , any update ? we are waiting ☕️ |
@abdennour you can make your own PR if you feel like it |
I have a branch here: https://github.com/jseminck/eslint-plugin-react/tree/no-typos-react-import It still has a failing test - but if you have any ideas feel free to help. If you want to finish it then you're free to take this code and continue working on top of it. This turned out harder than I thought. Didn't even work with Furthermore the React/PropTypes import code should probably be extracted to an util because other rules could also benefit from it. |
any update ? we are waiting ☕️ |
Yes, I have the same issue. It works inside React.component extended class and doesn't work for stateless components |
Hey everyone, I'd like to add two additional pieces of information regarding this issue:
|
with the
7.2.1
->7.3.0
upgrade this rule started breaking on this code:with
interestingly enough if i change to this:
then the rule passes, even though
MyPropTypes
doesn't export astring
prop.The text was updated successfully, but these errors were encountered: