This repository was archived by the owner on Oct 19, 2020. It is now read-only.
File tree 2 files changed +21
-4
lines changed
2 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -39,12 +39,15 @@ class Linter {
39
39
40
40
fileTemplates . forEach ( ( template ) => {
41
41
const fileErrors = sassLint . lintText ( {
42
- text : template ,
42
+ text : template . content ,
43
43
filename : filename ,
44
44
format : 'scss'
45
45
} )
46
46
47
47
if ( fileErrors . messages . length ) {
48
+ fileErrors . messages . forEach ( ( message ) => {
49
+ message . line += template . lineOffset
50
+ } )
48
51
this . lintErrors = this . lintErrors . concat ( fileErrors )
49
52
}
50
53
} )
@@ -67,14 +70,28 @@ class Linter {
67
70
}
68
71
69
72
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
+ } )
72
83
} )
73
84
74
85
var parser = new htmlparser . Parser ( handler )
75
86
parser . parseComplete ( fileData )
76
87
return templates
77
88
}
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
+ }
78
95
}
79
96
80
97
module . exports = Linter
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " sass-lint-vue" ,
3
- "version" : " 0.1 .0" ,
3
+ "version" : " 0.2 .0" ,
4
4
"description" : " Command line tool to lint Sass styles in Vue single file components." ,
5
5
"keywords" : [
6
6
" lint" ,
You can’t perform that action at this time.
0 commit comments