@@ -11,26 +11,6 @@ const { findAsync, generateRange } = lazyReq('atom-linter')('findAsync', 'genera
11
11
const stripJSONComments = lazyReq ( 'strip-json-comments' ) ;
12
12
const tinyPromisify = lazyReq ( 'tiny-promisify' ) ;
13
13
14
- const grammarScopes = [ ] ;
15
-
16
- let subscriptions ;
17
-
18
- export function activate ( ) {
19
- require ( 'atom-package-deps' ) . install ( 'linter-htmlhint' ) ;
20
-
21
- subscriptions = new CompositeDisposable ( ) ;
22
- subscriptions . add ( atom . config . observe ( 'linter-htmlhint.enabledScopes' , ( scopes ) => {
23
- // Remove any old scopes
24
- grammarScopes . splice ( 0 , grammarScopes . length ) ;
25
- // Add the current scopes
26
- Array . prototype . push . apply ( grammarScopes , scopes ) ;
27
- } ) ) ;
28
- }
29
-
30
- export function deactivate ( ) {
31
- subscriptions . dispose ( ) ;
32
- }
33
-
34
14
const getConfig = async ( filePath ) => {
35
15
const readFile = tinyPromisify ( ) ( fsReadFile ) ;
36
16
const configPath = await findAsync ( dirname ( filePath ) , '.htmlhintrc' ) ;
@@ -44,45 +24,65 @@ const getConfig = async (filePath) => {
44
24
return null ;
45
25
} ;
46
26
47
- export function provideLinter ( ) {
48
- return {
49
- name : 'htmlhint' ,
50
- grammarScopes,
51
- scope : 'file' ,
52
- lintOnFly : true ,
53
- lint : async ( editor ) => {
54
- if ( ! atom . workspace . isTextEditor ( editor ) ) {
55
- return null ;
56
- }
57
-
58
- const filePath = editor . getPath ( ) ;
59
- if ( ! filePath ) {
60
- // Invalid path
61
- return null ;
62
- }
63
-
64
- const fileText = editor . getText ( ) ;
65
- if ( ! fileText ) {
66
- return [ ] ;
27
+ export default {
28
+ activate ( ) {
29
+ require ( 'atom-package-deps' ) . install ( 'linter-htmlhint' ) ;
30
+
31
+ this . grammarScopes = [ ] ;
32
+
33
+ this . subscriptions = new CompositeDisposable ( ) ;
34
+ this . subscriptions . add ( atom . config . observe ( 'linter-htmlhint.enabledScopes' , ( scopes ) => {
35
+ // Remove any old scopes
36
+ this . grammarScopes . splice ( 0 , this . grammarScopes . length ) ;
37
+ // Add the current scopes
38
+ Array . prototype . push . apply ( this . grammarScopes , scopes ) ;
39
+ } ) ) ;
40
+ } ,
41
+
42
+ deactivate ( ) {
43
+ this . subscriptions . dispose ( ) ;
44
+ } ,
45
+
46
+ provideLinter ( ) {
47
+ return {
48
+ name : 'htmlhint' ,
49
+ grammarScopes : this . grammarScopes ,
50
+ scope : 'file' ,
51
+ lintOnFly : true ,
52
+ lint : async ( editor ) => {
53
+ if ( ! atom . workspace . isTextEditor ( editor ) ) {
54
+ return null ;
55
+ }
56
+
57
+ const filePath = editor . getPath ( ) ;
58
+ if ( ! filePath ) {
59
+ // Invalid path
60
+ return null ;
61
+ }
62
+
63
+ const fileText = editor . getText ( ) ;
64
+ if ( ! fileText ) {
65
+ return [ ] ;
66
+ }
67
+
68
+ const { HTMLHint } = require ( 'htmlhint' ) ;
69
+
70
+ const ruleset = await getConfig ( filePath ) ;
71
+
72
+ const messages = HTMLHint . verify ( fileText , ruleset || undefined ) ;
73
+
74
+ if ( editor . getText ( ) !== fileText ) {
75
+ // Editor contents have changed, tell Linter not to update
76
+ return null ;
77
+ }
78
+
79
+ return messages . map ( message => ( {
80
+ range : generateRange ( editor , message . line - 1 , message . col - 1 ) ,
81
+ type : message . type ,
82
+ text : message . message ,
83
+ filePath
84
+ } ) ) ;
67
85
}
68
-
69
- const { HTMLHint } = require ( 'htmlhint' ) ;
70
-
71
- const ruleset = await getConfig ( filePath ) ;
72
-
73
- const messages = HTMLHint . verify ( fileText , ruleset || undefined ) ;
74
-
75
- if ( editor . getText ( ) !== fileText ) {
76
- // Editor contents have changed, tell Linter not to update
77
- return null ;
78
- }
79
-
80
- return messages . map ( message => ( {
81
- range : generateRange ( editor , message . line - 1 , message . col - 1 ) ,
82
- type : message . type ,
83
- text : message . message ,
84
- filePath
85
- } ) ) ;
86
- }
87
- } ;
88
- }
86
+ } ;
87
+ }
88
+ } ;
0 commit comments