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 positives for namespaced variables in property-no-unknown #4803

Merged
merged 4 commits into from Jun 9, 2020

Conversation

ryym
Copy link
Contributor

@ryym ryym commented May 24, 2020

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

Closes #4544

Is there anything in the PR that needs further explanation?

I didn't add test cases of isStandardSyntaxDeclaration for Sass indented syntax because the postcss-sass parser does not understand @use syntax yet (AleshaOleg/postcss-sass#145).

Comment on lines 60 to 63
// Sass variables within a namespace (e.g. namespace.$var: x)
if (prop.includes('.$') && prop[0] !== '.' && prop[prop.length - 1] !== '$') {
return false;
}
Copy link
Contributor Author

@ryym ryym May 24, 2020

Choose a reason for hiding this comment

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

I'm not sure what this function should return for invalid declarations such as .$var and namespace.$. For now this branch excludes those invalid props.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

I think that the logic about SCSS variables added via this PR can be unified with the following code:

// SCSS var (e.g. $var: x), list (e.g. $list: (x)) or map (e.g. $map: (key:value))
if (property.startsWith('$')) {
return false;
}

// Sass var (e.g. $var: x), nested list (e.g. $list: (x)) or nested map (e.g. $map: (key:value))
if (prop[0] === '$') {
return false;
}

For example, what about adding a new utility function to handle SCSS variables?

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.

@ryym Thanks for the pull request. I've made a request.

I think that the logic about SCSS variables added via this PR

Yes, we should remove that duplication.

@ryym Are you able to create a isScssVariable(prop) util that returns true for either:

  • prop.startsWith('$'))
  • prop.includes('.$')

Then use that util in both:

  • isStandardSyntaxDeclaration.js
  • isStandardSyntaxProperty.js.

@@ -57,5 +57,10 @@ module.exports = function (decl) {
return false;
}

// Sass variables within a namespace (e.g. namespace.$var: x)
if (prop.includes('.$') && prop[0] !== '.' && prop[prop.length - 1] !== '$') {
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 just go with if (prop.includes('.$')) as the util is more interested in excluding non-standard properties than the validity of name-spaced dollar variables.

@ryym
Copy link
Contributor Author

ryym commented Jun 6, 2020

@ybiquitous @jeddy3 Thanks for your reviewing!
I added the isScssVariable function and replaced the duplicate code with it.

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.

Excellent. Thanks for making the changes!

Looks good to me now.

Copy link
Member

@ybiquitous ybiquitous left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you! 👏

@m-allanson m-allanson merged commit 80f3fab into stylelint:master Jun 9, 2020
@m-allanson
Copy link
Member

Updated changelog:

  • Fixed: property-no-unknown false positives for namespaced variables (#4803).

@ryym ryym deleted the scss-namespace-var branch June 9, 2020 23:45
m-allanson added a commit that referenced this pull request Jun 10, 2020
# By Mike Allanson (6) and others
# Via GitHub
* master:
  Bump got from 11.2.0 to 11.3.0 (#4825)
  Export an object from the CSS-in-JS syntax (#4824)
  Add type `Formatter` for formatter functions (#4823)
  Update CHANGELOG.md
  Fix false positives for namespaced variables in property-no-unknown (#4803)
  Update CHANGELOG.md
  Fix TypeError for inline comments and autofix for sugarss in max-empty-lines (#4821)
  Create new 'lintPostcssResult' module (#4819)
  13.6.0
  Update deps
  Prepare 13.6.0
  Update CHANGELOG.md
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 false positives for namespaced variables in property-no-unknown
4 participants