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 false negatives for css-in-js object notation in color-hex-case #5101

Merged
merged 6 commits into from Jan 19, 2021

Conversation

Dru89
Copy link
Contributor

@Dru89 Dru89 commented Jan 6, 2021

As discussed in #4826, style-search has false positives when used with css-in-js object notation. This change updates the color-hex-case rule to use postcss-value-parser instead, which has support for css-in-js as a syntax.

The unit tests now also include a suite for testing both upper and lower options for color-hex-case with the css-in-js syntax.

As discussed in stylelint#4826, `style-search` has false positives when used with
`css-in-js` object notation. This change updates the `color-hex-case`
rule to use `postcss-value-parser` instead, which has support for
`css-in-js` as a syntax.

The unit tests now also include a suite for testing both `upper` and
`lower` options for `color-hex-case` with the `css-in-js` syntax.
@Dru89
Copy link
Contributor Author

Dru89 commented Jan 6, 2021

This is my first contribution, so let me know if there's something I missed with respect to formatting or code style.

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.

@Dru89 Thanks! It's looking great so far, and so much cleaner now that the value parser is being used.

I've made a few requested changes.

lib/rules/color-hex-case/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Outdated Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Show resolved Hide resolved
lib/rules/color-hex-case/__tests__/index.js Show resolved Hide resolved
@Dru89
Copy link
Contributor Author

Dru89 commented Jan 6, 2021

Thanks for taking the time to look at all of this @jeddy3!

I've gone through and made the changes you requested. For many of them (like the invalid five hex colors, e.g. #aBABA), I pulled those directly from the test cases above. (My assumption was that the original tests still wanted to make sure that "invalid" hex colors still got transformed.)

Should we transform the original tests to also use more valid CSS? Or just leave them as they were before?

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.

Fantastic, thanks for making the changes! It's almost there. Just one last tweak with the indents.

Should we transform the original tests to also use more valid CSS? Or just leave them as they were before?

Let's leave them as they are. We default to using valid CSS, but deviating in this case makes sense as it's testing something particular. Whereas in the testRule for "css-in-js" were testing that objects are read correctly, rather than the edge cases of the rule itself, and so valid CSS is appropriate here.

lib/rules/color-hex-case/__tests__/index.js Show resolved Hide resolved
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.

@Dru89 Thanks. Looks great to me!

It's awesome to see the improvements with the refactoring to the value parser.

@jeddy3 jeddy3 mentioned this pull request Jan 11, 2021
6 tasks
@Dru89
Copy link
Contributor Author

Dru89 commented Jan 12, 2021

Thanks! I was gonna start in on some of the other style-search use cases like color-hex-length, color-no-hex, and value-no-vendor-prefix.

Should I wait until this one gets the second approval and merged? Also, would you prefer one PR per rule?

Dru89 added a commit to Dru89/stylelint that referenced this pull request Jan 12, 2021
`style-search` returns false positives when used with `css-in-js` object
notation. Continuing on the change made in stylelint#5101, this updates
`color-hex-length` to switch to using `postcss-value-parser`.

Unit tests have also been added to check the `css-in-js` syntax for this
rule.
@jeddy3
Copy link
Member

jeddy3 commented Jan 12, 2021

Thanks! I was gonna start in on some of the other style-search use cases...

Fantastic!

Should I wait until this one gets the second approval and merged? Also, would you prefer one PR per rule?

No need to wait. Yes, one pull request per rule, please.

lib/rules/color-hex-case/index.js Show resolved Hide resolved

return stringStart + replaceString + stringEnd;
return decl;
Copy link
Member

Choose a reason for hiding this comment

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

Return is not used anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

@Dru89 It looks like this is the only change we need to make for a second approval.

Copy link
Member

Choose a reason for hiding this comment

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

@Dru89 It looks like this is the only change we need to make for a second approval.

@jeddy3 jeddy3 changed the title Validate color-hex-case with postcss-value-parser Fix false negatives for css-in-js object notation in color-hex-case Jan 15, 2021
@Dru89
Copy link
Contributor Author

Dru89 commented Jan 18, 2021

Sorry for the delay in getting this updated. Last week was a bit busier than I expected, but I've addressed that last piece of feedback.

Copy link
Member

@hudochenkov hudochenkov left a comment

Choose a reason for hiding this comment

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

👍

jeddy3 pushed a commit that referenced this pull request Jan 19, 2021
…#5106)

* Use postcss-value-parser for color-hex-length

`style-search` returns false positives when used with `css-in-js` object
notation. Continuing on the change made in #5101, this updates
`color-hex-length` to switch to using `postcss-value-parser`.

Unit tests have also been added to check the `css-in-js` syntax for this
rule.

* Remove unnecessary return
@jeddy3 jeddy3 merged commit d1ce4f4 into stylelint:master Jan 19, 2021
@jeddy3
Copy link
Member

jeddy3 commented Jan 19, 2021

Changelog:

  • Fixed: color-hex-case false negatives for css-in-js object notation (#5101).

@Dru89 Thanks again for your first two pull request. Excellent job!

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.

None yet

3 participants