1
1
'use babel' ;
2
2
3
- import path from 'path' ;
4
3
import configLoader from 'lesshint/lib/config-loader' ;
4
+ import { findCachedAsync , rangeFromLineNumber } from 'atom-linter' ;
5
+ import Lesshint from 'lesshint' ;
6
+ import path from 'path' ;
5
7
import os from 'os' ;
6
8
7
9
export default class LinterLesshint {
@@ -40,22 +42,19 @@ export default class LinterLesshint {
40
42
}
41
43
42
44
static provideLinter ( ) {
43
- const Lesshint = require ( 'lesshint' ) ;
44
- const Helpers = require ( 'atom-linter' ) ;
45
-
46
45
return {
47
46
name : 'lesshint' ,
48
47
grammarScopes : [ 'source.css.less' ] ,
49
48
scope : 'file' ,
50
49
lintOnFly : true ,
51
50
lint : async ( editor ) => {
52
51
const lesshint = new Lesshint ( ) ;
53
- const text = editor . getText ( ) ;
54
52
const filePath = editor . getPath ( ) ;
55
- let configFile = await Helpers . findCachedAsync ( path . dirname ( filePath ) , '.lesshintrc' ) ;
53
+
54
+ let configFile = await findCachedAsync ( path . dirname ( filePath ) , '.lesshintrc' ) ;
56
55
57
56
if ( ! configFile && this . globalConfig ) {
58
- configFile = await Helpers . findCachedAsync ( this . globalConfigDir , '.lesshintrc' ) ;
57
+ configFile = await findCachedAsync ( this . globalConfigDir , '.lesshintrc' ) ;
59
58
}
60
59
61
60
if ( ! configFile && this . onlyWithRc ) {
@@ -79,6 +78,8 @@ export default class LinterLesshint {
79
78
let errors = [ ] ;
80
79
81
80
try {
81
+ const text = editor . getText ( ) ;
82
+
82
83
errors = lesshint . checkString ( text , filePath ) ;
83
84
} catch ( e ) {
84
85
atom . notifications . addError ( "lesshint couldn't check this file." , {
@@ -90,7 +91,7 @@ export default class LinterLesshint {
90
91
return errors . map ( ( { linter, message, line, column, severity } ) => {
91
92
line = line || editor . getLineCount ( ) ;
92
93
93
- const range = Helpers . rangeFromLineNumber ( editor , line - 1 , column - 1 ) ;
94
+ const range = rangeFromLineNumber ( editor , line - 1 , column - 1 ) ;
94
95
95
96
const type = severity ;
96
97
const html = `<span class='badge badge-flexible'>${ linter } </span> ${ message } ` ;
0 commit comments