1
1
'use babel' ;
2
2
3
+ let helpers = null ;
4
+ let clangFlags = null ;
5
+
3
6
export default {
4
7
config : {
5
- // It should be noted that I, Kepler, hate these Config names. However these
6
- // are the names in use by many people. Changing them for the sake of clean
7
- // of clean code would cause a mess for our users. Because of this we
8
- // override the titles the editor gives them in the settings pane.
9
8
execPath : {
10
9
type : 'string' ,
11
10
default : 'clang' ,
@@ -38,53 +37,51 @@ export default {
38
37
type : 'integer' ,
39
38
default : 0 ,
40
39
} ,
41
- verboseDebug : {
42
- type : 'boolean' ,
43
- default : false ,
44
- } ,
45
40
} ,
46
41
47
42
activate ( ) {
48
43
require ( 'atom-package-deps' ) . install ( 'linter-clang' ) ;
49
44
} ,
50
45
51
46
provideLinter ( ) {
52
- const helpers = require ( 'atom-linter' ) ;
53
- const clangFlags = require ( 'clang-flags' ) ;
54
47
const regex = '(?<file>.+):(?<line>\\d+):(?<col>\\d+):({(?<lineStart>\\d+):(?<colStart>\\d+)-(?<lineEnd>\\d+):(?<colEnd>\\d+)}.*:)? (?<type>[\\w \\-]+): (?<message>.*)' ;
55
48
return {
56
49
name : 'clang' ,
57
50
grammarScopes : [ 'source.c' , 'source.cpp' , 'source.objc' , 'source.objcpp' ] ,
58
51
scope : 'file' ,
59
52
lintOnFly : false ,
60
53
lint : ( activeEditor ) => {
54
+ if ( helpers === null ) {
55
+ helpers = require ( 'atom-linter' ) ;
56
+ }
57
+ if ( clangFlags === null ) {
58
+ clangFlags = require ( 'clang-flags' ) ;
59
+ }
61
60
const command = atom . config . get ( 'linter-clang.execPath' ) ;
62
- const file = activeEditor . getPath ( ) ;
63
- const args = [ '-fsyntax-only' ,
61
+ const filePath = activeEditor . getPath ( ) ;
62
+ const args = [
63
+ '-fsyntax-only' ,
64
64
'-fno-caret-diagnostics' ,
65
65
'-fno-diagnostics-fixit-info' ,
66
66
'-fdiagnostics-print-source-range-info' ,
67
- '-fexceptions' ] ;
67
+ '-fexceptions' ,
68
+ ] ;
68
69
69
70
const grammar = activeEditor . getGrammar ( ) . name ;
70
71
71
72
if ( / ^ C \+ \+ / . test ( grammar ) ) {
72
- // const language = "c++";
73
73
args . push ( '-xc++' ) ;
74
74
args . push ( ...atom . config . get ( 'linter-clang.clangDefaultCppFlags' ) . split ( / \s + / ) ) ;
75
75
}
76
76
if ( grammar === 'Objective-C++' ) {
77
- // const language = "objective-c++";
78
77
args . push ( '-xobjective-c++' ) ;
79
78
args . push ( ...atom . config . get ( 'linter-clang.clangDefaultObjCppFlags' ) . split ( / \s + / ) ) ;
80
79
}
81
80
if ( grammar === 'C' ) {
82
- // const language = "c";
83
81
args . push ( '-xc' ) ;
84
82
args . push ( ...atom . config . get ( 'linter-clang.clangDefaultCFlags' ) . split ( / \s + / ) ) ;
85
83
}
86
84
if ( grammar === 'Objective-C' ) {
87
- // const language = "objective-c";
88
85
args . push ( '-xobjective-c' ) ;
89
86
args . push ( ...atom . config . get ( 'linter-clang.clangDefaultObjCFlags' ) . split ( / \s + / ) ) ;
90
87
}
@@ -93,7 +90,7 @@ export default {
93
90
if ( atom . config . get ( 'linter-clang.clangSuppressWarnings' ) ) {
94
91
args . push ( '-w' ) ;
95
92
}
96
- if ( atom . config . get ( 'linter-clang.verboseDebug' ) ) {
93
+ if ( atom . inDevMode ( ) ) {
97
94
args . push ( '--verbose' ) ;
98
95
}
99
96
@@ -102,23 +99,23 @@ export default {
102
99
) ;
103
100
104
101
try {
105
- const flags = clangFlags . getClangFlags ( activeEditor . getPath ( ) ) ;
102
+ const flags = clangFlags . getClangFlags ( filePath ) ;
106
103
if ( flags ) {
107
104
args . push ( ...flags ) ;
108
105
}
109
106
} catch ( error ) {
110
- if ( atom . config . get ( 'linter-clang.verboseDebug' ) ) {
107
+ if ( atom . inDevMode ( ) ) {
111
108
// eslint-disable-next-line no-console
112
109
console . log ( error ) ;
113
110
}
114
111
}
112
+ args . push ( filePath ) ;
115
113
116
- // The file is added to the arguments last.
117
- args . push ( file ) ;
118
114
const execOpts = {
119
115
stream : 'stderr' ,
120
116
allowEmptyStderr : true ,
121
117
} ;
118
+
122
119
return helpers . exec ( command , args , execOpts ) . then ( output =>
123
120
helpers . parse ( output , regex ) ,
124
121
) ;
0 commit comments