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

Fix no-unknown-property: check attributes with any input case #2790

Merged
merged 1 commit into from Sep 21, 2020

Conversation

@julienw
Copy link
Contributor

@julienw julienw commented Sep 9, 2020

I think this is ready now. I checked my project with this rule and it didn't break anything :-)

I wasn't sure if this rule should also check completely unknown attributes. My view is that it should, but I didn't do it in this patch.

With this patch the rule will probably find new errors in existing code, so it should probably be versioned in a new minor or major version.

Tell me what you think!

(pretest fails but this seems to happen on master too?)

@julienw julienw marked this pull request as draft Sep 9, 2020
@julienw julienw force-pushed the julienw:fix-no-unknown-property branch 2 times, most recently from c70c6b0 to 7791b63 Sep 9, 2020
@julienw julienw changed the title [no-unknown-property] Support fixing attributes with any input case Fix no-unknown-property: check attributes with any input case Sep 9, 2020
@julienw julienw force-pushed the julienw:fix-no-unknown-property branch from 7791b63 to 93e4585 Sep 9, 2020
});
return found ? names[i] : null;
// Let's find a possible attribute match with a case-insensitive search.
const foundName = names.find(

This comment has been minimized.

@julienw

julienw Sep 9, 2020
Author Contributor

I checked that find is supported by node 4 before changing the code.

@julienw julienw marked this pull request as ready for review Sep 9, 2020
Copy link
Collaborator

@ljharb ljharb left a comment

LGTM pending question

const foundName = names.find(
(element, index) => element.toLowerCase() === name.toLowerCase()
);
return foundName === undefined ? null : foundName;

This comment has been minimized.

@ljharb

ljharb Sep 11, 2020
Collaborator

any reason not to just return foundName here, and have the function return String | undefined?

This comment has been minimized.

@julienw

julienw Sep 12, 2020
Author Contributor

There was 2 reasons:

  • initially I wanted to keep it working just like before, without changing too much code -- I ended up changing more code than I wanted :)
  • we have this habit in our project that we use null as an explicite "no value" whereas undefined is accidental.

In this context I agree this isn't so useful, where getStandardName is used at only one place. I can change this.

@@ -205,11 +206,11 @@ function getStandardName(name, context) {
}
let i = -1;

This comment has been minimized.

@ljharb

ljharb Sep 11, 2020
Collaborator

Suggested change
let i = -1;

this is no longer used

return found ? names[i] : null;
// Let's find a possible attribute match with a case-insensitive search.
const foundName = names.find(
(element, index) => element.toLowerCase() === name.toLowerCase()

This comment has been minimized.

@ljharb

ljharb Sep 11, 2020
Collaborator

Suggested change
(element, index) => element.toLowerCase() === name.toLowerCase()
(element) => element.toLowerCase() === name.toLowerCase()
@julienw julienw force-pushed the julienw:fix-no-unknown-property branch from 93e4585 to f7a072a Sep 12, 2020
@julienw
Copy link
Contributor Author

@julienw julienw commented Sep 12, 2020

Thanks for the review @ljharb, I think I fixed all your comments!

One question: I think this property should also check completely unknown attributes on the html tags (eg <div foo="bar">). Maybe this could be an option though... What do you think?

@ljharb
Copy link
Collaborator

@ljharb ljharb commented Sep 21, 2020

@julienw yes, ideally it should, but we'd need to ensure we can use the same mappings React itself uses, and i don't think they're exposed anywhere. I think we can do that in another PR :-)

@ljharb
ljharb approved these changes Sep 21, 2020
Copy link
Collaborator

@ljharb ljharb left a comment

Thanks, I'll clean up these tweaks and land.

@@ -194,7 +195,7 @@ function tagNameHasDot(node) {
* Get the standard name of the attribute.
* @param {String} name - Name of the attribute.
* @param {String} context - eslint context
* @returns {String} The standard name of the attribute.
* @returns {String | undefined} The standard name of the attribute, or null if no standard name was found.

This comment has been minimized.

@ljharb

ljharb Sep 21, 2020
Collaborator

Suggested change
* @returns {String | undefined} The standard name of the attribute, or null if no standard name was found.
* @returns {String | undefined} The standard name of the attribute, or undefined if no standard name was found.
const foundName = names.find(
(element) => element.toLowerCase() === name.toLowerCase()
);
return foundName; // This can be undefined if the value hasn't been found.
Comment on lines 209 to 212

This comment has been minimized.

@ljharb

ljharb Sep 21, 2020
Collaborator

Suggested change
const foundName = names.find(
(element) => element.toLowerCase() === name.toLowerCase()
);
return foundName; // This can be undefined if the value hasn't been found.
return names.find(
(element) => element.toLowerCase() === name.toLowerCase()
);

the comment isn't really helpful since that's how .find already works :-)

@ljharb ljharb force-pushed the julienw:fix-no-unknown-property branch from f7a072a to 4da7451 Sep 21, 2020
@ljharb ljharb merged commit 4da7451 into yannickcr:master Sep 21, 2020
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage decreased (-0.002%) to 97.5%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.