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
[New] add prefer-exact-props
rule
#1547
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note the propWrapperFunctions
settings, with can be used to specify exact
or forbidPropTypes
.
Perhaps this warrants a new setting for "exact propType wrappers", that could also be checked everywhere the existing propWrappers are?
Do you think it should be a global setting instead of just an option for the rule? I'm unsure of the other use cases for it being a global setting. |
@jomasti if it were a global setting, then other rules could access it to "unwrap" propTypes for their own uses. |
@ljharb Wouldn't these particular "exact props" functions still be in |
@jomasti right; the idea is that i'd be able to move |
I guess an alternative schema for the existing setting could be: "propWrapperFunctions": [
"Object",
{ "property": "freeze", "object": "Object" },
{ "property": "forbidExtraProps", "exact": true }
] |
What exactly is missing before this can be merged? Can we maybe split this task and add support for libs like airbnb/prop-types in an other task? |
@maxammann that support already exists; see the "propWrapperFunctions" setting in the readme. This PR needs to be updated per the above comments. |
This change is adapting the `propWrapperFunctions` setting to allow for using objects along side the already present strings. This will help facilitate adding extra attributes to these objects like for exact prop functions. Precursor to jsx-eslint#1547.
After doing some digging, it looks like the failures on ESLint 3 are due to versions 7.22+ of babel-eslint using |
We could modify the dep range, and for eslint 3 in Travis.yml manually downgrade it? |
Would you prefer for the |
Downgrading to a working version of |
Breaks other tests on eslint 3? |
Yes, using |
So what is it exactly about this pr that causes this breakage? |
It's looking for the TypeAlias variable in the scope. This works fine on |
ecbb05d
to
cb6aba0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems great!
(I'm going to hold off merging it for awhile while the 7.12 release settles down)
This rule seems to be eerily similar to I get that this specifically forces exact definitions in Flow and PropType wrappers, but the underlying reason for that is to avoid unused props in a component -- is that right? |
I could be wrong, but my understanding of this is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Thanks @alexzherdev
What happened to this PR? Is there any other rule that can/should be used? I would love to enforce the usage of exact from prop-types-exact in our project as it seams to have only advantages and no disadvantages... |
Codecov Report
@@ Coverage Diff @@
## master #1547 +/- ##
==========================================
+ Coverage 97.44% 97.47% +0.02%
==========================================
Files 110 111 +1
Lines 7294 7395 +101
Branches 2665 2699 +34
==========================================
+ Hits 7108 7208 +100
- Misses 186 187 +1
Continue to review full report at Codecov.
|
This rule checks if non-exact objects are used for defining prop types when using Flow along with using normal objects for prop types instead of something like
prop-types-exact
to enforce only passing the exact props to a component.The exact prop wrapper functions for non-Flow usage are configurable by adding the
exact
property to an object setting in thepropWrapperFunctions
config option.Closes #1455