1
- 'use babel'
1
+ 'use strict' ;
2
+ 'use babel' ;
2
3
3
- import Path from 'path'
4
- import { CompositeDisposable } from 'atom'
5
- import { spawnWorker } from './helpers'
6
- import escapeHTML from 'escape-html'
4
+ Object . defineProperty ( exports , "__esModule" , {
5
+ value : true
6
+ } ) ;
7
7
8
- export default {
8
+ var _path = require ( 'path' ) ;
9
+
10
+ var _path2 = _interopRequireDefault ( _path ) ;
11
+
12
+ var _atom = require ( 'atom' ) ;
13
+
14
+ var _helpers = require ( './helpers' ) ;
15
+
16
+ var _escapeHtml = require ( 'escape-html' ) ;
17
+
18
+ var _escapeHtml2 = _interopRequireDefault ( _escapeHtml ) ;
19
+
20
+ function _interopRequireDefault ( obj ) { return obj && obj . __esModule ? obj : { default : obj } ; }
21
+
22
+ exports . default = {
9
23
config : {
10
24
lintHtmlFiles : {
11
25
title : 'Lint HTML Files' ,
@@ -53,40 +67,40 @@ export default {
53
67
default : false
54
68
}
55
69
} ,
56
- activate : function ( ) {
57
- require ( 'atom-package-deps' ) . install ( )
70
+ activate : function ( ) {
71
+ require ( 'atom-package-deps' ) . install ( ) ;
58
72
59
- this . subscriptions = new CompositeDisposable ( )
60
- this . active = true
61
- this . worker = null
62
- this . scopes = [ 'source.js' , 'source.jsx' , 'source.js.jsx' , 'source.babel' , 'source.js-semantic' ]
73
+ this . subscriptions = new _atom . CompositeDisposable ( ) ;
74
+ this . active = true ;
75
+ this . worker = null ;
76
+ this . scopes = [ 'source.js' , 'source.jsx' , 'source.js.jsx' , 'source.babel' , 'source.js-semantic' ] ;
63
77
64
- const embeddedScope = 'source.js.embedded.html'
78
+ const embeddedScope = 'source.js.embedded.html' ;
65
79
this . subscriptions . add ( atom . config . observe ( 'linter-eslint.lintHtmlFiles' , lintHtmlFiles => {
66
80
if ( lintHtmlFiles ) {
67
- this . scopes . push ( embeddedScope )
81
+ this . scopes . push ( embeddedScope ) ;
68
82
} else {
69
83
if ( this . scopes . indexOf ( embeddedScope ) !== - 1 ) {
70
- this . scopes . splice ( this . scopes . indexOf ( embeddedScope ) , 1 )
84
+ this . scopes . splice ( this . scopes . indexOf ( embeddedScope ) , 1 ) ;
71
85
}
72
86
}
73
- } ) )
87
+ } ) ) ;
74
88
this . subscriptions . add ( atom . commands . add ( 'atom-text-editor' , {
75
89
'linter-eslint:fix-file' : ( ) => {
76
- const textEditor = atom . workspace . getActiveTextEditor ( )
77
- const filePath = textEditor . getPath ( )
78
- const fileDir = Path . dirname ( filePath )
90
+ const textEditor = atom . workspace . getActiveTextEditor ( ) ;
91
+ const filePath = textEditor . getPath ( ) ;
92
+ const fileDir = _path2 . default . dirname ( filePath ) ;
79
93
80
94
if ( ! textEditor || textEditor . isModified ( ) ) {
81
95
// Abort for invalid or unsaved text editors
82
- atom . notifications . addError ( 'Linter-ESLint: Please save before fixing' )
83
- return
96
+ atom . notifications . addError ( 'Linter-ESLint: Please save before fixing' ) ;
97
+ return ;
84
98
}
85
99
86
100
if ( this . worker === null ) {
87
101
// Abort if worker is not yet ready
88
- atom . notifications . addError ( 'Linter-ESLint: Not ready, please try again' )
89
- return
102
+ atom . notifications . addError ( 'Linter-ESLint: Not ready, please try again' ) ;
103
+ return ;
90
104
}
91
105
92
106
this . worker . request ( 'FIX' , {
@@ -95,61 +109,66 @@ export default {
95
109
global : atom . config . get ( 'linter-eslint.useGlobalEslint' ) ,
96
110
nodePath : atom . config . get ( 'linter-eslint.globalNodePath' ) ,
97
111
configFile : atom . config . get ( 'linter-eslint.eslintrcPath' )
98
- } ) . then ( function ( response ) {
99
- atom . notifications . addSuccess ( response )
100
- } ) . catch ( function ( response ) {
101
- atom . notifications . addWarning ( response )
102
- } )
112
+ } ) . then ( function ( response ) {
113
+ atom . notifications . addSuccess ( response ) ;
114
+ } ) . catch ( function ( response ) {
115
+ atom . notifications . addWarning ( response ) ;
116
+ } ) ;
103
117
}
104
- } ) )
118
+ } ) ) ;
105
119
106
120
// Reason: I (steelbrain) have observed that if we spawn a
107
121
// process while atom is starting up, it can increase startup
108
122
// time by several seconds, But if we do this after 5 seconds,
109
123
// we barely feel a thing.
110
124
const initializeWorker = ( ) => {
111
125
if ( this . active ) {
112
- const { child, worker, subscription} = spawnWorker ( )
113
- this . worker = worker
114
- this . subscriptions . add ( subscription )
126
+ var _spawnWorker = ( 0 , _helpers . spawnWorker ) ( ) ;
127
+
128
+ const child = _spawnWorker . child ;
129
+ const worker = _spawnWorker . worker ;
130
+ const subscription = _spawnWorker . subscription ;
131
+
132
+ this . worker = worker ;
133
+ this . subscriptions . add ( subscription ) ;
115
134
child . on ( 'exit-linter' , shouldLive => {
116
- this . worker = null
135
+ this . worker = null ;
117
136
// Respawn if it crashed. See atom/electron#3446
118
137
if ( shouldLive ) {
119
- initializeWorker ( )
138
+ initializeWorker ( ) ;
120
139
}
121
- } )
140
+ } ) ;
122
141
}
123
- }
124
- setTimeout ( initializeWorker , 5 * 1000 )
142
+ } ;
143
+ setTimeout ( initializeWorker , 5 * 1000 ) ;
125
144
} ,
126
- deactivate : function ( ) {
127
- this . active = false
128
- this . subscriptions . dispose ( )
145
+ deactivate : function ( ) {
146
+ this . active = false ;
147
+ this . subscriptions . dispose ( ) ;
129
148
} ,
130
- provideLinter : function ( ) {
131
- const Helpers = require ( 'atom-linter' )
149
+ provideLinter : function ( ) {
150
+ const Helpers = require ( 'atom-linter' ) ;
132
151
return {
133
152
name : 'ESLint' ,
134
153
grammarScopes : this . scopes ,
135
154
scope : 'file' ,
136
155
lintOnFly : true ,
137
156
lint : textEditor => {
138
- const text = textEditor . getText ( )
157
+ const text = textEditor . getText ( ) ;
139
158
if ( text . length === 0 ) {
140
- return Promise . resolve ( [ ] )
159
+ return Promise . resolve ( [ ] ) ;
141
160
}
142
- const filePath = textEditor . getPath ( )
143
- const fileDir = Path . dirname ( filePath )
144
- const showRule = atom . config . get ( 'linter-eslint.showRuleIdInMessage' )
161
+ const filePath = textEditor . getPath ( ) ;
162
+ const fileDir = _path2 . default . dirname ( filePath ) ;
163
+ const showRule = atom . config . get ( 'linter-eslint.showRuleIdInMessage' ) ;
145
164
146
165
if ( this . worker === null ) {
147
166
return Promise . resolve ( [ {
148
167
filePath : filePath ,
149
168
type : 'Info' ,
150
169
text : 'Worker initialization is delayed. Please try saving or typing to begin linting.' ,
151
170
range : Helpers . rangeFromLineNumber ( textEditor , 0 )
152
- } ] )
171
+ } ] ) ;
153
172
}
154
173
155
174
return this . worker . request ( 'JOB' , {
@@ -162,32 +181,38 @@ export default {
162
181
rulesDir : atom . config . get ( 'linter-eslint.eslintRulesDir' ) ,
163
182
configFile : atom . config . get ( 'linter-eslint.eslintrcPath' ) ,
164
183
disableIgnores : atom . config . get ( 'linter-eslint.disableEslintIgnore' )
165
- } ) . then ( function ( response ) {
184
+ } ) . then ( function ( response ) {
166
185
if ( response . length === 1 && response [ 0 ] . message === 'File ignored because of your .eslintignore file. Use --no-ignore to override.' ) {
167
- return [ ]
186
+ return [ ] ;
168
187
}
169
- return response . map ( function ( { message, line, severity, ruleId, column} ) {
170
- const range = Helpers . rangeFromLineNumber ( textEditor , line - 1 )
188
+ return response . map ( function ( _ref ) {
189
+ let message = _ref . message ;
190
+ let line = _ref . line ;
191
+ let severity = _ref . severity ;
192
+ let ruleId = _ref . ruleId ;
193
+ let column = _ref . column ;
194
+
195
+ const range = Helpers . rangeFromLineNumber ( textEditor , line - 1 ) ;
171
196
if ( column ) {
172
- range [ 0 ] [ 1 ] = column - 1
197
+ range [ 0 ] [ 1 ] = column - 1 ;
173
198
}
174
199
if ( column > range [ 1 ] [ 1 ] ) {
175
- range [ 1 ] [ 1 ] = column - 1
200
+ range [ 1 ] [ 1 ] = column - 1 ;
176
201
}
177
202
const ret = {
178
203
filePath : filePath ,
179
204
type : severity === 1 ? 'Warning' : 'Error' ,
180
205
range : range
181
- }
206
+ } ;
182
207
if ( showRule ) {
183
- ret . html = `<span class="badge badge-flexible">${ ruleId || 'Fatal' } </span> ${ escapeHTML ( message ) } `
208
+ ret . html = `<span class="badge badge-flexible">${ ruleId || 'Fatal' } </span> ${ ( 0 , _escapeHtml2 . default ) ( message ) } ` ;
184
209
} else {
185
- ret . text = message
210
+ ret . text = message ;
186
211
}
187
- return ret
188
- } )
189
- } )
212
+ return ret ;
213
+ } ) ;
214
+ } ) ;
190
215
}
191
- }
216
+ } ;
192
217
}
193
- }
218
+ } ;
0 commit comments