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

Support ranges for errors and warnings #31

Merged
merged 3 commits into from
Nov 24, 2021
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
6 changes: 6 additions & 0 deletions lib/html/parse-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class LocalFixer {
if (typeof object.offset === "number") {
object.offset += this.style.startIndex;
}
if (typeof object.endLine === "number") {
if (object.endLine === 1) {
object.endColumn += this.column;
}
object.endLine += this.line;
}
}
}

Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"dependencies": {
"htmlparser2": "^7.1.2",
"postcss": "^8.3.11",
"postcss": "^8.4.0",
"postcss-safe-parser": "^6.0.0"
},
"devDependencies": {
Expand Down
54 changes: 49 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,21 @@ describe("API", () => {
syntax.parse("<style>a {</style>", {
from: "SyntaxError.vue",
});
}).to.throw(/SyntaxError.vue:1:8: Unclosed block\b/);
})
.to.throw(/SyntaxError.vue:1:8: Unclosed block\b/)
.with.include({ line: 1, column: 8 })
.have.property("input")
.include({ line: 1, column: 8 });

expect(() => {
syntax.parse("<style>foo foo</style>", {
from: "SyntaxError.vue",
});
})
.to.throw(/SyntaxError.vue:1:8: Unknown word\b/)
.with.include({ line: 1, column: 8, endLine: 1, endColumn: 11 })
.have.property("input")
.include({ line: 1, column: 8, endLine: 1, endColumn: 11 });
});

it("single line with line ending syntax error", () => {
Expand All @@ -52,10 +66,40 @@ describe("API", () => {

it("multi line syntax error", () => {
expect(() => {
syntax.parse(["<html>", "<style>a {</style>", "</html>"].join("\n"), {
from: "SyntaxError.html",
});
}).to.throw(/SyntaxError.html:2:8: Unclosed block\b/);
syntax.parse(
[
//
"<html>",
"<style>a {</style>",
"</html>",
].join("\n"),
{
from: "SyntaxError.html",
}
);
})
.to.throw(/SyntaxError.html:2:8: Unclosed block\b/)
.with.include({ line: 2, column: 8 })
.have.property("input")
.include({ line: 2, column: 8 });

expect(() => {
syntax.parse(
[
//
"<html>",
"<style>foo foo</style>",
"</html>",
].join("\n"),
{
from: "SyntaxError.html",
}
);
})
.to.throw(/SyntaxError.html:2:8: Unknown word\b/)
.with.include({ line: 2, column: 8, endLine: 2, endColumn: 11 })
.have.property("input")
.include({ line: 2, column: 8, endLine: 2, endColumn: 11 });
});

it("custom parse error", () => {
Expand Down