Skip to content
Open
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
4 changes: 2 additions & 2 deletions dist/cli/htmlhint.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/core/core.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/core/htmlparser.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/cli/htmlhint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ function hintFile(filepath: string, ruleset?: Ruleset) {
// ignore
}

return HTMLHint.verify(content, ruleset)
return HTMLHint.verify(content, ruleset, filepath)
}

// hint stdin
Expand Down
8 changes: 6 additions & 2 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class HTMLHintCore {
this.rules[rule.id] = rule
}

public verify(html: string, ruleset: Ruleset = this.defaultRuleset) {
public verify(
html: string,
ruleset: Ruleset = this.defaultRuleset,
filepath: string = ''
) {
Comment thread
commodis marked this conversation as resolved.
if (Object.keys(ruleset).length === 0) {
ruleset = this.defaultRuleset
}
Expand Down Expand Up @@ -74,7 +78,7 @@ class HTMLHintCore {
}
}

parser.parse(html)
parser.parse(html, filepath)

return reporter.messages
}
Expand Down
4 changes: 3 additions & 1 deletion src/core/htmlparser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Block {
long: boolean
close: string
lastEvent?: Partial<Block>
filepath?: string
}

export type Listener = (event: Block) => void
Expand Down Expand Up @@ -49,7 +50,7 @@ export default class HTMLParser {
return obj
}

public parse(html: string): void {
public parse(html: string, filepath: string = ''): void {
const mapCdataTags = this._mapCdataTags

const regTag =
Expand Down Expand Up @@ -78,6 +79,7 @@ export default class HTMLParser {
pos: 0,
line: 1,
col: 1,
filepath: filepath,
Comment thread
commodis marked this conversation as resolved.
})

// Do not ignore validation inside <script type="ng/template"> template
Expand Down
28 changes: 28 additions & 0 deletions test/htmlparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,31 @@ describe('HTMLParser: Case parse', () => {
parser.parse('<img src="aaa" alt= />')
})
})

describe('HTMLParser: Filepath', () => {
it('should include filepath in start event when provided to parse', (done) => {
const parser = new HTMLParser()
const arrEvents = []
getAllEvents(parser, arrEvents, () => {
// The start event must be the first event (index 0)
expect(arrEvents[0]).toEvent('start', {
filepath: '/some/example.txt',
})
done()
})
parser.parse('', '/some/example.txt')
})

it('should include empty string filepath in start event when not provided', (done) => {
const parser = new HTMLParser()
const arrEvents = []
getAllEvents(parser, arrEvents, () => {
// The start event must be the first event (index 0)
expect(arrEvents[0]).toEvent('start', {
filepath: '',
})
done()
})
parser.parse('')
})
})