Skip to content
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

Add a forbid-dom-props rule #1562

Merged
merged 4 commits into from Nov 28, 2017
Merged

Conversation

davazp
Copy link
Contributor

@davazp davazp commented Nov 22, 2017

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.

@davazp
Copy link
Contributor Author

davazp commented Nov 22, 2017

I used dom as they keyword for this rule as I didn't find any other rule acting only on DOM Nodes, and element refers to both Component and DOM Nodes. Hopefully it is a good name!

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 forbid-component-props for now. I guess it can be extended if somebody finds that useful.

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.
@davazp davazp force-pushed the add-forbid-dom-props-rule branch 2 times, most recently from 4df4ebc to 1ae0a99 Compare November 22, 2017 10:29
Copy link
Member

@ljharb ljharb left a 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.

}
}
},
additionalProperties: true
Copy link
Member

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',
Copy link
Member

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

forbid: {
type: 'array',
items: {
type: 'string'
Copy link
Member

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

Copy link
Member

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.

@davazp
Copy link
Contributor Author

davazp commented Nov 22, 2017

@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 forbid-component-props, including the schema. Would you like me to change also the schema of forbid-component-props to follow your requested changes as well? Or keep it for backward compatibility?

Thanks,
David.

@davazp
Copy link
Contributor Author

davazp commented Nov 22, 2017

I have also added Related section to the components to link to each other, following the example from default-props-match-prop-types.md.

@ljharb
Copy link
Member

ljharb commented Nov 22, 2017

Changing the schema of the existing rule would be a breaking change; leave that the same, and let's update this one.

@davazp
Copy link
Contributor Author

davazp commented Nov 23, 2017

I updated the PR with the refined schema 👍

forbid: {
type: 'array',
items: {
type: 'string'
Copy link
Member

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.

@davazp
Copy link
Contributor Author

davazp commented Nov 24, 2017

I misread your original comment. I fixed the schema now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

None yet

3 participants