Skip to content
This repository was archived by the owner on Oct 19, 2020. It is now read-only.

Commit eedc6d9

Browse files
committed
Merge branch 'release/0.2.0'
2 parents 85547e1 + 936c1e7 commit eedc6d9

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

lib/linter.js

+20-3
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,15 @@ class Linter {
3939

4040
fileTemplates.forEach((template) => {
4141
const fileErrors = sassLint.lintText({
42-
text: template,
42+
text: template.content,
4343
filename: filename,
4444
format: 'scss'
4545
})
4646

4747
if (fileErrors.messages.length) {
48+
fileErrors.messages.forEach((message) => {
49+
message.line += template.lineOffset
50+
})
4851
this.lintErrors = this.lintErrors.concat(fileErrors)
4952
}
5053
})
@@ -67,14 +70,28 @@ class Linter {
6770
}
6871

6972
const $ = cheerio.load(dom)
70-
templates = templates.concat($('style[lang="sass"]').text())
71-
templates = templates.concat($('style[lang="scss"]').text())
73+
const template = $('style[lang="scss"]').text()
74+
75+
if (template.length <= 0) {
76+
return
77+
}
78+
79+
templates.push({
80+
content: template,
81+
lineOffset: this.getLineOffset(template, $.text())
82+
})
7283
})
7384

7485
var parser = new htmlparser.Parser(handler)
7586
parser.parseComplete(fileData)
7687
return templates
7788
}
89+
90+
getLineOffset (needle, haystack) {
91+
const targetPosition = haystack.indexOf(needle)
92+
const untilTargetPosition = haystack.substring(0, targetPosition)
93+
return untilTargetPosition.split(/\r?\n/).length - 1
94+
}
7895
}
7996

8097
module.exports = Linter

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sass-lint-vue",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Command line tool to lint Sass styles in Vue single file components.",
55
"keywords": [
66
"lint",

0 commit comments

Comments
 (0)