...
 
Commits (4)
# html-validate changelog
## [2.4.1](https://gitlab.com/html-validate/html-validate/compare/v2.4.0...v2.4.1) (2019-12-02)
### Bug Fixes
- **lexer:** handle missing `Source` properties (like `offset`) ([2092942](https://gitlab.com/html-validate/html-validate/commit/20929425dd69eadcc5432d11f33b53a35050b76c))
# [2.4.0](https://gitlab.com/html-validate/html-validate/compare/v2.3.0...v2.4.0) (2019-12-01)
### Bug Fixes
......
{
"name": "html-validate",
"version": "2.4.0",
"version": "2.4.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......@@ -9504,9 +9504,9 @@
}
},
"eslint-plugin-jest": {
"version": "23.0.5",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.0.5.tgz",
"integrity": "sha512-etxXrWsFWzxsrxKwJnFC38uppH/vlJ3oF7Wmp/cxedqxRIxVhXup8e5y5MmtVXelevgxrgA1QS1vo8j889iK5Q==",
"version": "23.1.1",
"resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-23.1.1.tgz",
"integrity": "sha512-2oPxHKNh4j1zmJ6GaCBuGcb8FVZU7YjFUOJzGOPnl9ic7VA/MGAskArLJiRIlnFUmi1EUxY+UiATAy8dv8s5JA==",
"dev": true,
"requires": {
"@typescript-eslint/experimental-utils": "^2.5.0"
......
{
"name": "html-validate",
"version": "2.4.0",
"version": "2.4.1",
"description": "html linter",
"keywords": [
"html",
......@@ -56,7 +56,14 @@
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
],
"rules": {
"header-max-length": [
2,
"always",
90
]
}
},
"husky": {
"hooks": {
......@@ -167,7 +174,7 @@
"eslint-config-sidvind": "1.3.2",
"eslint-plugin-array-func": "3.1.3",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jest": "23.0.5",
"eslint-plugin-jest": "23.1.1",
"eslint-plugin-node": "10.0.0",
"eslint-plugin-prettier": "3.1.1",
"eslint-plugin-security": "1.4.0",
......
......@@ -18,10 +18,10 @@ export class Context {
public constructor(source: Source) {
this.state = undefined;
this.string = source.data;
this.filename = source.filename;
this.offset = source.offset;
this.line = source.line;
this.column = source.column;
this.filename = source.filename ?? "";
this.offset = source.offset ?? 0;
this.line = source.line ?? 1;
this.column = source.column ?? 1;
this.contentModel = ContentModel.TEXT;
}
......
......@@ -109,3 +109,36 @@ it("should compute correct line, column and offset when using transformed source
}
`);
});
it("should handle source missing properties", () => {
expect.assertions(2);
const source = {
data: "<p>lorem ipsum</i>",
};
const htmlvalidate = new HtmlValidate({
root: true,
extends: ["htmlvalidate:recommended"],
});
const report = htmlvalidate.validateSource(source as Source);
expect(report).toBeInvalid();
expect(report.results[0]).toMatchInlineSnapshot(`
Object {
"errorCount": 1,
"filePath": "",
"messages": Array [
Object {
"column": 16,
"context": undefined,
"line": 1,
"message": "Mismatched close-tag, expected '</p>' but found '</i>'.",
"offset": 15,
"ruleId": "close-order",
"severity": 2,
"size": 2,
},
],
"source": "<p>lorem ipsum</i>",
"warningCount": 0,
}
`);
});
......@@ -61,10 +61,10 @@ export class Parser {
/* reset DOM in case there are multiple calls in the same session */
this.dom = new DOMTree({
filename: source.filename,
offset: source.offset,
line: source.line,
column: source.column,
filename: source.filename ?? "",
offset: source.offset ?? 0,
line: source.line ?? 1,
column: source.column ?? 1,
});
/* trigger any rules waiting for DOM load event */
......
......@@ -135,7 +135,7 @@ export class Reporter {
results: Object.keys(this.result).map(filePath => {
const messages = [].concat(this.result[filePath]).sort(messageSort);
const source = (sources || []).find(
(source: Source) => source.filename === filePath
(source: Source) => filePath === (source.filename ?? "")
);
return {
filePath,
......