1
1
'use babel' ;
2
2
3
+ // eslint-disable-next-line import/extensions, import/no-extraneous-dependencies
4
+ import { CompositeDisposable } from 'atom' ;
5
+
3
6
let helpers = null ;
4
7
let clangFlags = null ;
5
8
6
9
export default {
7
10
activate ( ) {
8
11
require ( 'atom-package-deps' ) . install ( 'linter-clang' ) ;
12
+ this . subscriptions = new CompositeDisposable ( ) ;
13
+ this . subscriptions . add (
14
+ atom . config . observe ( 'linter-clang.execPath' , ( value ) => {
15
+ this . execPath = value ;
16
+ } ) ,
17
+ ) ;
18
+ this . subscriptions . add (
19
+ atom . config . observe ( 'linter-clang.clangIncludePaths' , ( value ) => {
20
+ this . clangIncludePaths = value ;
21
+ } ) ,
22
+ ) ;
23
+ this . subscriptions . add (
24
+ atom . config . observe ( 'linter-clang.clangSuppressWarnings' , ( value ) => {
25
+ this . clangSuppressWarnings = value ;
26
+ } ) ,
27
+ ) ;
28
+ this . subscriptions . add (
29
+ atom . config . observe ( 'linter-clang.clangDefaultCFlags' , ( value ) => {
30
+ this . clangDefaultCFlags = value ;
31
+ } ) ,
32
+ ) ;
33
+ this . subscriptions . add (
34
+ atom . config . observe ( 'linter-clang.clangDefaultCppFlags' , ( value ) => {
35
+ this . clangDefaultCppFlags = value ;
36
+ } ) ,
37
+ ) ;
38
+ this . subscriptions . add (
39
+ atom . config . observe ( 'linter-clang.clangDefaultObjCFlags' , ( value ) => {
40
+ this . clangDefaultObjCFlags = value ;
41
+ } ) ,
42
+ ) ;
43
+ this . subscriptions . add (
44
+ atom . config . observe ( 'linter-clang.clangDefaultObjCppFlags' , ( value ) => {
45
+ this . clangDefaultObjCppFlags = value ;
46
+ } ) ,
47
+ ) ;
48
+ this . subscriptions . add (
49
+ atom . config . observe ( 'linter-clang.clangErrorLimit' , ( value ) => {
50
+ this . clangErrorLimit = value ;
51
+ } ) ,
52
+ ) ;
53
+ } ,
54
+
55
+ deactivate ( ) {
56
+ this . subscriptions . dispose ( ) ;
9
57
} ,
10
58
11
59
provideLinter ( ) {
12
60
const regex = '(?<file>.+):(?<line>\\d+):(?<col>\\d+):({(?<lineStart>\\d+):(?<colStart>\\d+)-(?<lineEnd>\\d+):(?<colEnd>\\d+)}.*:)? (?<type>[\\w \\-]+): (?<message>.*)' ;
13
61
return {
14
62
name : 'clang' ,
15
- grammarScopes : [ 'source.c' , 'source.cpp' , 'source.objc' , 'source.objcpp' ] ,
16
63
scope : 'file' ,
17
64
lintOnFly : false ,
65
+ grammarScopes : [ 'source.c' , 'source.cpp' , 'source.objc' , 'source.objcpp' ] ,
18
66
lint : ( activeEditor ) => {
19
67
if ( helpers === null ) {
20
68
helpers = require ( 'atom-linter' ) ;
21
69
}
22
70
if ( clangFlags === null ) {
23
71
clangFlags = require ( 'clang-flags' ) ;
24
72
}
25
- const command = atom . config . get ( 'linter-clang.execPath' ) ;
73
+
26
74
const filePath = activeEditor . getPath ( ) ;
27
75
const args = [
28
76
'-fsyntax-only' ,
@@ -36,30 +84,30 @@ export default {
36
84
37
85
if ( / ^ C \+ \+ / . test ( grammar ) ) {
38
86
args . push ( '-xc++' ) ;
39
- args . push ( ...atom . config . get ( 'linter-clang. clangDefaultCppFlags' ) . split ( / \s + / ) ) ;
87
+ args . push ( ...this . clangDefaultCppFlags . split ( / \s + / ) ) ;
40
88
}
41
89
if ( grammar === 'Objective-C++' ) {
42
90
args . push ( '-xobjective-c++' ) ;
43
- args . push ( ...atom . config . get ( 'linter-clang. clangDefaultObjCppFlags' ) . split ( / \s + / ) ) ;
91
+ args . push ( ...this . clangDefaultObjCppFlags . split ( / \s + / ) ) ;
44
92
}
45
93
if ( grammar === 'C' ) {
46
94
args . push ( '-xc' ) ;
47
- args . push ( ...atom . config . get ( 'linter-clang. clangDefaultCFlags' ) . split ( / \s + / ) ) ;
95
+ args . push ( ...this . clangDefaultCFlags . split ( / \s + / ) ) ;
48
96
}
49
97
if ( grammar === 'Objective-C' ) {
50
98
args . push ( '-xobjective-c' ) ;
51
- args . push ( ...atom . config . get ( 'linter-clang. clangDefaultObjCFlags' ) . split ( / \s + / ) ) ;
99
+ args . push ( ...this . clangDefaultObjCFlags . split ( / \s + / ) ) ;
52
100
}
53
101
54
- args . push ( `-ferror-limit=${ atom . config . get ( 'linter-clang. clangErrorLimit' ) } ` ) ;
55
- if ( atom . config . get ( 'linter-clang. clangSuppressWarnings' ) ) {
102
+ args . push ( `-ferror-limit=${ this . clangErrorLimit } ` ) ;
103
+ if ( this . clangSuppressWarnings ) {
56
104
args . push ( '-w' ) ;
57
105
}
58
106
if ( atom . inDevMode ( ) ) {
59
107
args . push ( '--verbose' ) ;
60
108
}
61
109
62
- atom . config . get ( 'linter-clang. clangIncludePaths' ) . forEach ( path =>
110
+ this . clangIncludePaths . forEach ( path =>
63
111
args . push ( `-I${ path } ` ) ,
64
112
) ;
65
113
@@ -81,7 +129,7 @@ export default {
81
129
allowEmptyStderr : true ,
82
130
} ;
83
131
84
- return helpers . exec ( command , args , execOpts ) . then ( output =>
132
+ return helpers . exec ( this . execPath , args , execOpts ) . then ( output =>
85
133
helpers . parse ( output , regex ) ,
86
134
) ;
87
135
} ,
0 commit comments