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 at-charset and single quotes in string-quotes #2788 #2902

Merged
merged 7 commits into from
Sep 22, 2017
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/rules/string-quotes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ a[id="foo"] { content: "x"; }

Quotes within comments are ignored.

Also, the quotes in a `charset` @-rule are ignored as using single quotes in this context is incorrect according the [CSS specification](https://www.w3.org/TR/CSS2/syndata.html#x57).
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 move this line to below the quotes in comments code underneath this sentence

Update the verbiage to Single quotes in a charset @-rule are ignored as using single quotes in this context is incorrect according the CSS specification.

Maybe see what adding a code example for this also looks like, it might look weird or add confusion 🤔


```css
/* "This is fine" */
/* 'And this is also fine' */
Expand Down
10 changes: 10 additions & 0 deletions lib/rules/string-quotes/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ testRule(rule, {
{
code: 'a { /* "horse" */ }',
description: "ignores comment"
},
{
code: '@charset "utf-8"',
description: "ignore @charset rules"
}
Copy link
Member

Choose a reason for hiding this comment

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

Could you add this same test to the "double quotes" test around line #119 as a safe guard of sorts please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added below ...

Copy link
Member

Choose a reason for hiding this comment

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

Thanks, though you added it to the SCSS tests at lines 160-163, which won't hurt either, can you add it after line 118 please :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops. Yes added there.

],

Expand Down Expand Up @@ -67,6 +71,12 @@ testRule(rule, {
message: messages.expected("single"),
line: 2,
column: 19
},
{
code: '@import "base.css"',
message: messages.expected("single"),
line: 1,
column: 9
}
]
});
Expand Down
14 changes: 13 additions & 1 deletion lib/rules/string-quotes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ const rule = function(expectation) {
return;
}

const cssString = root.toString();
let cssString = root.toString();

// allow @charset rules to have double quotes, in spite of the configuration
if (erroneousQuote === '"') {
root.walkAtRules(atRule => {
if (atRule.name === "charset") {
const badAtRule = atRule.toString();
const goodAtRule = badAtRule.split('"').join("'");
cssString = cssString.replace(badAtRule, goodAtRule);
}
});
}

styleSearch({ source: cssString, target: erroneousQuote }, match => {
report({
message: messages.expected(expectation),
Expand Down