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 function-no-unknown false positives for unspaced operators against nested brackets #6842

Conversation

romainmenke
Copy link
Member

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

Closes #6582

Is there anything in the PR that needs further explanation?

This change migrates this rule from postcss-value-parser to @csstools/css-parser-algorithms.

@changeset-bot
Copy link

changeset-bot bot commented May 12, 2023

🦋 Changeset detected

Latest commit: 8cd0ee9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
stylelint Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@mattxwang mattxwang left a comment

Choose a reason for hiding this comment

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

I have one quick question, but other than that this looks good to me - glad to see that the @csstools packages are useful!

Comment on lines -70 to -72
if (!isStandardSyntaxFunction(node)) {
return;
}
Copy link
Member

@mattxwang mattxwang May 15, 2023

Choose a reason for hiding this comment

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

Since we've removed this check, is it possible that this rule will now flag errors for SASS/CSS-in-JS users? If so, I imagine that this might be slightly breaking for those users (and/or something we propagate to configs)?

(I could also be missing something about how SASS and CSS-in-JS play together with this rule, or with @csstools)

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch :)

module.exports = function isStandardSyntaxFunction(node) {
	// Function nodes without names are things in parentheses like Sass lists
	if (!node.value) {
		return false;
	}

	if (node.value.startsWith('#{')) {
		return false;
	}

	// CSS-in-JS interpolation
	if (node.value.startsWith('${')) {
		return false;
	}

	// CSS-in-JS syntax
	if (node.value.startsWith('`')) {
		return false;
	}

	return true;
};

None of those cases would be parsed as a FunctionNode by @csstools/css-parser-algorithms.

Only <ident><open-parenthesis> (e.g. foo() starts a function in standard CSS.

This behavior makes isFunctionNode the equivalent of isStandardSyntaxFunction.

is it possible that this rule will now flag errors for SASS/CSS-in-JS users?

no

@mattxwang mattxwang mentioned this pull request May 15, 2023
4 tasks
…unspaced-operators-against-nested-brackets--resourceful-kangaroo-ec239dde9a
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.

Thanks for the pull request. I've suggested a tiny refactoring, but this PR sounds good. 👍🏼

Because postcss-value-parser seems to stop maintenance, we may need to switch it to @csstools/css-tokenizer to reduce dependencies.

lib/rules/function-no-unknown/index.js Outdated Show resolved Hide resolved
Co-authored-by: Masafumi Koba <473530+ybiquitous@users.noreply.github.com>
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 👍🏼

@romainmenke romainmenke merged commit 6f421a0 into main May 15, 2023
14 checks passed
@romainmenke romainmenke deleted the fix-function-no-unknown-false-positives-for-unspaced-operators-against-nested-brackets--resourceful-kangaroo-ec239dde9a branch May 15, 2023 14:53
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 function-no-unknown false positives for unspaced operators against nested brackets
3 participants