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

Avoid comments in at-rule-property-requirelist #4744

Merged
merged 2 commits into from May 12, 2020

Conversation

srawlins
Copy link
Contributor

@srawlins srawlins commented May 6, 2020

Which issue, if any, is this issue related to?

Fixes #4638

Is there anything in the PR that needs further explanation?

It's self-explanatory.

If the undefined values represent a bug upstream, I'd be glad for a hint as to which project that might be.

Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

@srawlins Thanks for the pull request.

I made a query and a request.

@@ -38,9 +38,16 @@ function rule(primary) {
}

primary[atRuleName].forEach((property) => {
if (!property) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? property in this context is the property from the configuration object, e.g. margin in :

{
  "config": { "page": ["margin"] }
}

If I take it out locally, the tests still pass.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch; I must have gotten my line numbers mixed up.

const propertyName = property.toLowerCase();

const hasProperty = nodes.find((node) => node.prop.toLowerCase() === propertyName);
const hasProperty = nodes.find(
Copy link
Member

Choose a reason for hiding this comment

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

Let's go with this minor tweak:

const hasProperty = nodes.find(
  ({type, prop}) => type === "decl" && prop.toLowerCase() === propertyName
);

The original issue was caused by our assumption that an at-rule would only have declarations for children. By using type === "decl" we are being explicit about wanting to check declarations, whereas checking for the existence of the prop property only implies that. I think the former may better communicate the intent.

I'll create a follow-up pull request that tweaks the working on rules docs to suggest using this approach when node.forEach is a better fit than node.walk*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Much nicer.

@jeddy3 jeddy3 mentioned this pull request May 6, 2020
6 tasks
Copy link
Member

@jeddy3 jeddy3 left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes.

Looks good to me!

@jeddy3 jeddy3 merged commit a09fd82 into stylelint:master May 12, 2020
@jeddy3
Copy link
Member

jeddy3 commented May 12, 2020

Changelog:

  • Fixed: at-rule-property-requirelist TypeError for comments inside of font-face (#4744).

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

Successfully merging this pull request may close these issues.

Fix TypeError for comments inside of font-face in at-rule-property-requirelist
3 participants