2
2
3
3
import * as helpers from 'atom-linter' ;
4
4
import { extname } from 'path' ;
5
+ // eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
6
+ import { CompositeDisposable } from 'atom' ;
5
7
6
8
export default {
7
- activate : ( ) => {
9
+ activate ( ) {
8
10
require ( 'atom-package-deps' ) . install ( 'linter-ruby' ) ;
11
+
12
+ this . subscriptions = new CompositeDisposable ( ) ;
13
+ this . subscriptions . add ( atom . config . observe ( 'linter-ruby.rubyExecutablePath' ,
14
+ ( value ) => { this . executablePath = value ; } ) ) ;
15
+ this . subscriptions . add ( atom . config . observe ( 'linter-ruby.ignoredExtensions' ,
16
+ ( value ) => { this . ignoredExtensions = value ; } ) ) ;
17
+ } ,
18
+
19
+ deactivate ( ) {
20
+ this . subscriptions . dispose ( ) ;
9
21
} ,
10
22
11
- provideLinter : ( ) => {
23
+ provideLinter ( ) {
12
24
const regex = / .+ : ( \d + ) : \s * ( .+ ?) [ , : ] \s ( .+ ) / ;
13
25
return {
14
26
name : 'Ruby' ,
15
27
grammarScopes : [ 'source.ruby' , 'source.ruby.rails' , 'source.ruby.rspec' ] ,
16
28
scope : 'file' ,
17
29
lintOnFly : true ,
18
30
lint : async ( activeEditor ) => {
19
- const command = atom . config . get ( 'linter-ruby.rubyExecutablePath' ) ;
20
- const ignored = atom . config . get ( 'linter-ruby.ignoredExtensions' ) ;
21
31
const filePath = activeEditor . getPath ( ) ;
22
32
const fileExtension = extname ( filePath ) . substr ( 1 ) ;
23
33
24
- if ( ignored . includes ( fileExtension ) ) {
34
+ if ( this . ignoredExtensions . includes ( fileExtension ) ) {
25
35
return [ ] ;
26
36
}
27
37
@@ -30,7 +40,7 @@ export default {
30
40
stdin : activeEditor . getText ( ) ,
31
41
stream : 'stderr' ,
32
42
} ;
33
- const output = await helpers . exec ( command , execArgs , execOpts ) ;
43
+ const output = await helpers . exec ( this . executablePath , execArgs , execOpts ) ;
34
44
const toReturn = [ ] ;
35
45
output . split ( / \r ? \n / ) . forEach ( ( line ) => {
36
46
const matches = regex . exec ( line ) ;
0 commit comments