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

Ignore ERB template tags in selectors #4491

Merged
merged 1 commit into from Dec 25, 2019
Merged

Ignore ERB template tags in selectors #4491

merged 1 commit into from Dec 25, 2019

Conversation

hudochenkov
Copy link
Member

@hudochenkov hudochenkov commented Dec 25, 2019

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

Fixes #4489.

Is there anything in the PR that needs further explanation?

Problem lies in many places. We are passing selector <% COLORS.each do |color| %>\na to postcss-selector-parser, and the later falls into endless loop. Which is understandable. This case might be fixed in postcss-selector-parser, but it won't happen any time soon. Currently, we're using postcss-selector-parser@3.1.0, while the latest version is 6.0.2. We can't upgrade, because there are still some issues in new version of a parser which needs to be resolved in a parser.

So, the only choice we have is to fix problem in stylelint. My solution is not universal, but if will fix the problem. It might create false negatives for isStandardSyntaxSelector, when selector like [data-something="<%"] is used. I think it's very unlikely to have a selector with <% or %> in it.


There is also a question when to release the fix. The next version of stylelint should be major, because we have some breaking changes in master. On the other hand we want to drop Node.js 8 from January 1. Which will require to release new major version. I don't want to release two major versions, as it's bad UX for our users have to update two major versions.

If this fix has to be release as soon as possible, we can create a new branch from latest release tag and cherry pick this PR there, and release patch version from that branch.

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Good job!

@hudochenkov
Copy link
Member Author

hudochenkov commented Dec 25, 2019

@stylelint/core What we decided about release? (second part of my top message)

@alexander-akait
Copy link
Member

If this fix has to be release as soon as possible, we can create a new branch from latest release tag and cherry pick this PR there, and release patch version from that branch.

Sounds good for me

@hudochenkov hudochenkov changed the base branch from master to release-12-0-1 December 25, 2019 13:05
@hudochenkov hudochenkov changed the base branch from release-12-0-1 to master December 25, 2019 13:05
@hudochenkov hudochenkov merged commit fbd403f into master Dec 25, 2019
@hudochenkov hudochenkov deleted the fix-issue-4489 branch December 25, 2019 13:06
@hudochenkov
Copy link
Member Author

  • Fixed: string-no-newline memory leak for ERB templates (#4491)

hudochenkov added a commit that referenced this pull request Dec 25, 2019
@vilchik-elena
Copy link

vilchik-elena commented Dec 26, 2019

@hudochenkov thanks for the quick fix!
but looks like there is [at least] one more place to fix:

if (!isStandardSyntaxSelector(resolvedSelector)) {
return;
}

As I can reproduce the same problem with no-descending-specificity rule

As far as I understand this condition should be checked before trying to parse selector.

@hudochenkov
Copy link
Member Author

@vilchik-elena make sense! Can you send a PR, please?

@vilchik-elena
Copy link

vilchik-elena commented Dec 26, 2019

@hudochenkov I tried to do that, but I fail to reproduce with unit test :( (while I do with CLI with the same .erb file and { "rules": { "no-descending-specificity": true } } as config)

Also I checked that that ~40 usages of parseSelector. I'm not sure if all of them should be preceeded with isStandardSyntaxSelector check.

@hudochenkov
Copy link
Member Author

@vilchik-elena I believe this test will be ok:

testRule(rule, {
	ruleName,
	config: [true],
	syntax: 'html',
	skipBasicChecks: true,

	accept: [
		{
			code: `<style>
				.highlight {
					padding: 2px;
				}
				<%- SEVERITY_COLORS.each do |severity, color| %>
				.severity.<%= severity %> {
					color: <%= color %>;
				}
				.highlight.<%= severity %> {
					background-color: <%= color.fade_out(0.4) %>;
				}
				</style>`,
			description: 'ERB templates are ignored',
		},
	],
});

Also I checked that that ~40 usages of parseSelector. I'm not sure if all of them should be preceeded with isStandardSyntaxSelector check.

Let's fix rules which confirmed has issues.

Maybe we can change parseSelector.js and check for standard syntax there.

@vilchik-elena
Copy link

Ok, I finally found out what's the problem. I was trying to create patch from master branch. And the problem of no-descending-specificity does not exist on master, yet it does exist on fresh release 12.0.1 as for some reason (you know better) commit 0f04539 is not part of 12.0.1.

So what should be done next according to you @hudochenkov ?

@hudochenkov
Copy link
Member Author

Good catch :) In commit you found we added isStandardSyntaxSelector check to isStandardSyntaxRule, so now isStandardSyntaxSelector is not needed in no-descending-specificity.

// Ignore nested property `foo: {};`
if (!isStandardSyntaxRule(rule)) {
return;
}

@vilchik-elena
Copy link

@hudochenkov so when this will be part of release?

@hudochenkov
Copy link
Member Author

We plan to release in the beginning of January.

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.

'string-no-newline' freezes for template inside css
4 participants