Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
14 changes: 12 additions & 2 deletions src/rules/no-duplicate-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,19 @@ export default {
data: { url },
fix(fixer) {
const [start, end] = sourceCode.getRange(node);
const text = sourceCode.text;
// Remove the node, and also remove a following newline if present
const removeEnd =
sourceCode.text[end] === "\n" ? end + 1 : end;
let removeEnd = end;
if (text[removeEnd] === "\r") {
removeEnd +=
text[removeEnd + 1] === "\n" ? 2 : 1;
} else if (
text[removeEnd] === "\n" ||
text[removeEnd] === "\f"
) {
removeEnd += 1;
}

return fixer.removeRange([start, removeEnd]);
},
});
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-important.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default {
const textWithoutComments = declarationText.replace(
commentPattern,
/* eslint-disable-next-line require-unicode-regexp -- we want to replace each code unit with a space */
match => match.replace(/[^\n]/g, " "),
match => match.replace(/[^\r\n\f]/g, " "),
);
const importantMatch =
importantPattern.exec(textWithoutComments);
Expand Down
42 changes: 42 additions & 0 deletions tests/rules/no-duplicate-imports.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,47 @@ ruleTester.run("no-duplicate-imports", rule, {
},
],
},
{
code: "@import url('a.css');\r\n@import url('a.css');\r\n@import url('b.css');",
output: "@import url('a.css');\r\n@import url('b.css');",
errors: [
{
messageId: "duplicateImport",
data: { url: "a.css" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
{
code: "@import url('a.css');\r@import url('a.css');\r@import url('b.css');",
output: "@import url('a.css');\r@import url('b.css');",
errors: [
{
messageId: "duplicateImport",
data: { url: "a.css" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
{
code: "@import url('a.css');\f@import url('a.css');\f@import url('b.css');",
output: "@import url('a.css');\f@import url('b.css');",
errors: [
{
messageId: "duplicateImport",
data: { url: "a.css" },
line: 2,
column: 1,
endLine: 2,
endColumn: 22,
},
],
},
],
});
54 changes: 54 additions & 0 deletions tests/rules/no-important.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,60 @@ ruleTester.run("no-important", rule, {
},
],
},
{
code: "a { color: red\r\n!important; }",
errors: [
{
messageId: "unexpectedImportant",
line: 2,
column: 1,
endLine: 2,
endColumn: 11,
suggestions: [
{
messageId: "removeImportant",
output: "a { color: red; }",
},
],
},
],
},
{
code: "a { color: red\r!important; }",
errors: [
{
messageId: "unexpectedImportant",
line: 2,
column: 1,
endLine: 2,
endColumn: 11,
suggestions: [
{
messageId: "removeImportant",
output: "a { color: red; }",
},
],
},
],
},
{
code: "a { color: red\f!important; }",
errors: [
{
messageId: "unexpectedImportant",
line: 2,
column: 1,
endLine: 2,
endColumn: 11,
suggestions: [
{
messageId: "removeImportant",
output: "a { color: red; }",
},
],
},
],
},
{
code: dedent`
a {
Expand Down