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

[New] jsx-boolean-value: add inverse option for always/never #1250

Merged
merged 3 commits into from
Jun 26, 2017

Conversation

ljharb
Copy link
Member

@ljharb ljharb commented Jun 11, 2017

Fixes #1249

@ljharb
Copy link
Member Author

ljharb commented Jun 13, 2017

ping for reviews :-)

@@ -28,13 +28,18 @@ var ruleTester = new RuleTester({parserOptions});
ruleTester.run('jsx-boolean-value', rule, {
valid: [
{code: '<App foo />;', options: ['never']},
{code: '<App foo />;', options: ['always', {never: ['foo']}]},
Copy link
Contributor

@jseminck jseminck Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also cover the always part in these test cases? E.g. checking that bar={true} is still valid when the config is ['always', {never: ['foo']}].

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, why not

@ljharb ljharb force-pushed the boolean_inverse branch 6 times, most recently from 89b0dbe to 42eb4b1 Compare June 17, 2017 04:58
@ljharb
Copy link
Member Author

ljharb commented Jun 17, 2017

@yannickcr @lencioni @EvNaverniouk if you have a chance to review this that'd be appreciated :-)

@ljharb ljharb force-pushed the boolean_inverse branch from 42eb4b1 to 2f1ad31 Compare June 21, 2017 23:04
var NEVER_MESSAGE = 'Value must be omitted for boolean attributes';
var ALWAYS_MESSAGE = 'Value must be set for boolean attributes';
const NEVER_MESSAGE = 'Value must be omitted for boolean attributes{{exceptionsMessage}}';
const ALWAYS_MESSAGE = 'Value must be set for boolean attributes{{exceptionsMessage}}';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nice to move some of this into a helper function that takes exceptions as an argument, so this code only has to run in the event of a warning.

const isException = exceptions.has(propName);

const isAlways = configuration === ALWAYS ? !isException : isException;
const isNever = configuration === NEVER ? !isException : isException;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find these two ternaries less clear than if/else. I had to work through the logic here, which slowed me down. It might be worth converting.

The following patterns are considered warnings when configured `"never"`:
The second argument is optional: if provided, it must be an object with a `"never"` property (if the first argument is `"always"`), or an `"always"` property (if the first argument is `"never"`). This property’s value must be an array of strings representing prop names.

The following patterns are considered warnings when configured `"never"`, or with `"always", { "never": ["personal"] }`:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on the fence about whether this should be never/always, or something more general like exceptions or except. As it is written here, it is possible to have both never and always which would be a little weird. I think it is fine, but I think a unified option might make the documentation a little clearer and the code a small amount simpler. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, "exceptions" means "these things are not checked" - the semantic here is, everything is forced to something: some things are forced to always, and some to never.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. That makes sense.

@ljharb ljharb force-pushed the boolean_inverse branch from 2f1ad31 to a24e027 Compare June 22, 2017 04:10
ljharb added a commit to ljharb/eslint-plugin-react that referenced this pull request Jun 22, 2017
ljharb added a commit to ljharb/eslint-plugin-react that referenced this pull request Jun 22, 2017
@ljharb
Copy link
Member Author

ljharb commented Jun 22, 2017

@lencioni updated per your comments; i'll merge tomorrow if there's no other issues.

@ljharb ljharb force-pushed the boolean_inverse branch from a24e027 to a794101 Compare June 26, 2017 08:18
@lencioni lencioni merged commit fd2fba1 into jsx-eslint:master Jun 26, 2017
@ljharb ljharb deleted the boolean_inverse branch June 26, 2017 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants