1
1
var csslint = require ( 'csslint' ) . CSSLint ;
2
- var cssparser = require ( 'css ' ) ;
2
+ var cssparser = require ( 'postcss ' ) ;
3
3
4
4
function CssFile ( source , path , callback ) {
5
5
callback = callback || function ( ) { }
@@ -12,28 +12,25 @@ CssFile.prototype.webSrc = function(){
12
12
} ;
13
13
14
14
CssFile . prototype . selectorFromPosition = function ( line , column ) {
15
- var rules = this . parsed . stylesheet . rules ;
16
- for ( var i = 0 ; i < rules . length ; i ++ ) {
17
- var position = rules [ i ] . position ;
18
- if ( ( position . start . line < line && position . end . line > line )
19
- || ( position . start . line == line
20
- && position . end . line != line
21
- && position . start . column <= line )
22
- || ( position . start . line != line
23
- && position . end . line == line
24
- && position . start . column >= line )
25
- || ( position . start . line == line
26
- && position . end . line == line
27
- && position . start . column <= line
28
- && position . end . column >= line ) ) {
29
- if ( rules [ i ] . selectors ) {
30
- return rules [ i ] . selectors . join ( ' ' ) ;
31
- } else {
32
- return null ;
33
- }
15
+ for ( const rule of this . parsed . nodes ) {
16
+ const {
17
+ start : { line : startLine , column : startColumn } ,
18
+ end : { line : endLine , column : endColumn } ,
19
+ } = rule . source
20
+ if ( ( startLine < line && endLine > line )
21
+ || ( startLine == line
22
+ && endLine != line
23
+ && startColumn <= line )
24
+ || ( startLine != line
25
+ && endLine == line
26
+ && startColumn >= line )
27
+ || ( startLine == line
28
+ && endLine == line
29
+ && startColumn <= line
30
+ && endColumn >= line ) ) {
31
+ return rule . selector || null ;
34
32
}
35
33
}
36
-
37
34
return null ;
38
35
} ;
39
36
@@ -62,11 +59,12 @@ CssFile.prototype.setContent = function(source, callback){
62
59
return ;
63
60
}
64
61
65
- this . parsed . stylesheet . rules . forEach ( function ( rule ) {
66
- var position = rule . position ;
67
- position . start . line -- ;
68
- position . start . column -- ;
69
- } ) ;
62
+ for ( const rule of this . parsed . nodes ) {
63
+ let source = rule . source ;
64
+ source . start . line -- ;
65
+ source . start . column -- ;
66
+ source . end . column ++ ;
67
+ }
70
68
71
69
if ( changed ) {
72
70
callback ( null ) ;
0 commit comments