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

Allow for Boolean Prop Naming Custom Message #1588

Merged
merged 2 commits into from Dec 13, 2017
Merged

Allow for Boolean Prop Naming Custom Message #1588

merged 2 commits into from Dec 13, 2017

Conversation

louisscruz
Copy link
Contributor

@louisscruz louisscruz commented Dec 7, 2017

The default message for boolean-prop-naming does not make it clear why the rule is being flagged. I'd like my organization to be able to immediately know what the issue is without them having to parse the Regex.

This PR introduces functionality such that the following configuration:

{
    'react/boolean-prop-naming': [
      'error',
      {
        rule: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
        message: 'Boolean prop names must begin with either \'is\' or \'has\'.'
      }
    ]
}

displays the custom message of Boolean prop names must begin with either 'is' or 'has'..

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.

Thanks, this is a great addition!

@@ -35,6 +35,10 @@ module.exports = {
default: '^(is|has)[A-Z]([A-Za-z0-9]?)+',
minLength: 1,
type: 'string'
},
message: {
default: '',
Copy link
Member

Choose a reason for hiding this comment

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

I don't think eslint pays attention to default here, fwiw.

Also, could we add minLength: 1? nobody should need to configure an empty string

@rapheld
Copy link

rapheld commented Dec 11, 2017

@ljharb Did you mean to request changes on this PR. From your comment, it looks like you meant to approve.

@ljharb
Copy link
Member

ljharb commented Dec 12, 2017

@rapheld if you click on "show outdated" you'll see the change i requested.

@@ -131,7 +135,7 @@ module.exports = {
const propName = getPropName(propNode);
context.report({
node: propNode,
message: `Prop name (${propName}) doesn't match rule (${config.rule})`,
message: config.message || `Prop name (${propName}) doesn't match rule (${config.rule})`,
Copy link
Member

Choose a reason for hiding this comment

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

I think if we're making this configurable, then instead of using a template literal to interpolate propName and config.rule, we should use eslint's built-in string templating - that way the configurable message can use placeholders for those two things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding now.

@rapheld
Copy link

rapheld commented Dec 12, 2017

I had tried that, but for whatever reason, it wasn’t displaying a comment. Worked this time though.

@louisscruz
Copy link
Contributor Author

@ljharb String templating added!

@ljharb ljharb merged commit 292ebed into jsx-eslint:master Dec 13, 2017
@louisscruz
Copy link
Contributor Author

louisscruz commented Dec 14, 2017

@ljharb Glad to see this merged! This is my first contribution to this project, and I'm trying to determine how I should bring this into my own project. What's the timeline for publication of this enhancement? (P.S. will delete this branch soon)

@ljharb
Copy link
Member

ljharb commented Dec 14, 2017

@louisscruz once merged, you're welcome to delete your branch whenever you like, or keep it forever :-) For this project, only @yannickcr can do a release, so it'll be released when they get a chance to do so (I can't speak to their timeline).

@louisscruz
Copy link
Contributor Author

@yannickcr Any plans for publication?

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.

None yet

4 participants