Skip to content

Feature/add is var meta data #83

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

Merged
merged 9 commits into from
Jan 28, 2020

Conversation

AndyOGo
Copy link
Contributor

@AndyOGo AndyOGo commented Mar 26, 2019

This PR fixes #82 contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

If yes, please describe the breakage.

Please Describe Your Changes

lastNode.isColor = colorFunctions.includes(lastNode.name.toLowerCase());
const lowerName = lastNode.name.toLowerCase();
lastNode.isColor = colorFunctions.includes(lowerName);
lastNode.isVar = lowerName === 'var';
Copy link
Contributor Author

@AndyOGo AndyOGo Mar 26, 2019

Choose a reason for hiding this comment

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

@shellscape So far this is a loose check, ideally it would also check that it's argument is of length 1 and has this pattern: /--.*/.

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

@@ -29,7 +29,8 @@ module.exports = {
'calc(1px + -2vw - 4px)',
'calc(((768px - 100vw) / 2) - 15px)',
'bar(baz(black, 10%), 10%)',
'-webkit-linear-gradient(0)'
'-webkit-linear-gradient(0)',
'var(--foo)'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shellscape
The tests for var() and all color functions above would ideally also check that the related meta property of isVar or isColor is set

Copy link
Contributor Author

Choose a reason for hiding this comment

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

never mind, it's all visible within the snapshots

const lowerName = lastNode.name.toLowerCase();
const { nodes } = node;
lastNode.isColor = colorFunctions.includes(lowerName);
lastNode.isVar = lowerName === 'var' && nodes.length === 1 && reVar.test(nodes[0].value);
Copy link
Contributor Author

@AndyOGo AndyOGo Mar 27, 2019

Choose a reason for hiding this comment

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

This is too restrictive, does not allow for default fallback values to be defined:
<declaration-value> shall be allowed.
https://developer.mozilla.org/en-US/docs/Web/CSS/var#Values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

const lowerName = lastNode.name.toLowerCase();
const { nodes } = node;
lastNode.isColor = colorFunctions.includes(lowerName);
lastNode.isVar = lowerName === 'var' && nodes.length && reVar.test(nodes[0].value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In theory no need for custom regex to test for var.
But variable detection could be configured to not include CSS custom properties by { variables: { prefixed: ['\\$'] }}.

@shellscape shellscape merged commit e2ca314 into shellscape:master Jan 28, 2020
@shellscape
Copy link
Owner

thanks!

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

Successfully merging this pull request may close these issues.

add isVar to func to mark CSS variables usage
2 participants