-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add a forbid-dom-props rule #1562
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
Conversation
I used I can imagine a more flexible set of option where you can forbid some properties based on the specific DOM Node, but I preferred to keep it similar to |
A new rule forbid-dom-props was added. It is based on forbid-component-props but it only forbid property on DOM Node elements. This can be useful to enforce some good practices, as not using 'id' attributes or inline styles.
4df4ebc
to
1ae0a99
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.
Let's make the docs for both forbid-X-props rules link to each other.
We also need tests for all three of createReactClass, SFC, and class-based component.
lib/rules/forbid-dom-props.js
Outdated
} | ||
} | ||
}, | ||
additionalProperties: true |
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.
this should be set to false
type: 'object', | ||
properties: { | ||
forbid: { | ||
type: 'array', |
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.
this array should be forced to be unique
lib/rules/forbid-dom-props.js
Outdated
forbid: { | ||
type: 'array', | ||
items: { | ||
type: 'string' |
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.
these items should have a minLength of 1
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.
sorry, to clarify: 0 items in the array is OK, but an empty string should not be.
@ljharb There were tests for the 3 cases already I think? I have anyway added extra SFC and class-based invalid tests, that there was just one. All code was derived from Thanks, |
I have also added Related section to the components to link to each other, following the example from |
Changing the schema of the existing rule would be a breaking change; leave that the same, and let's update this one. |
I updated the PR with the refined schema 👍 |
lib/rules/forbid-dom-props.js
Outdated
forbid: { | ||
type: 'array', | ||
items: { | ||
type: 'string' |
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.
sorry, to clarify: 0 items in the array is OK, but an empty string should not be.
e31c794
to
268a704
Compare
I misread your original comment. I fixed the schema now. |
A new rule forbid-dom-props was added. It is based on
forbid-component-props but it only forbid property on DOM Node
elements.
This can be useful to enforce some good practices, as not using 'id'
attributes or inline styles.