Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 10b5845

Browse files
committed
Some general code cleanup
1 parent 5f633c6 commit 10b5845

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

lib/main.js

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
'use babel';
22

3+
let helpers = null;
4+
let clangFlags = null;
5+
36
export default {
47
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.
98
execPath: {
109
type: 'string',
1110
default: 'clang',
@@ -38,53 +37,51 @@ export default {
3837
type: 'integer',
3938
default: 0,
4039
},
41-
verboseDebug: {
42-
type: 'boolean',
43-
default: false,
44-
},
4540
},
4641

4742
activate() {
4843
require('atom-package-deps').install('linter-clang');
4944
},
5045

5146
provideLinter() {
52-
const helpers = require('atom-linter');
53-
const clangFlags = require('clang-flags');
5447
const regex = '(?<file>.+):(?<line>\\d+):(?<col>\\d+):({(?<lineStart>\\d+):(?<colStart>\\d+)-(?<lineEnd>\\d+):(?<colEnd>\\d+)}.*:)? (?<type>[\\w \\-]+): (?<message>.*)';
5548
return {
5649
name: 'clang',
5750
grammarScopes: ['source.c', 'source.cpp', 'source.objc', 'source.objcpp'],
5851
scope: 'file',
5952
lintOnFly: false,
6053
lint: (activeEditor) => {
54+
if (helpers === null) {
55+
helpers = require('atom-linter');
56+
}
57+
if (clangFlags === null) {
58+
clangFlags = require('clang-flags');
59+
}
6160
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',
6464
'-fno-caret-diagnostics',
6565
'-fno-diagnostics-fixit-info',
6666
'-fdiagnostics-print-source-range-info',
67-
'-fexceptions'];
67+
'-fexceptions',
68+
];
6869

6970
const grammar = activeEditor.getGrammar().name;
7071

7172
if (/^C\+\+/.test(grammar)) {
72-
// const language = "c++";
7373
args.push('-xc++');
7474
args.push(...atom.config.get('linter-clang.clangDefaultCppFlags').split(/\s+/));
7575
}
7676
if (grammar === 'Objective-C++') {
77-
// const language = "objective-c++";
7877
args.push('-xobjective-c++');
7978
args.push(...atom.config.get('linter-clang.clangDefaultObjCppFlags').split(/\s+/));
8079
}
8180
if (grammar === 'C') {
82-
// const language = "c";
8381
args.push('-xc');
8482
args.push(...atom.config.get('linter-clang.clangDefaultCFlags').split(/\s+/));
8583
}
8684
if (grammar === 'Objective-C') {
87-
// const language = "objective-c";
8885
args.push('-xobjective-c');
8986
args.push(...atom.config.get('linter-clang.clangDefaultObjCFlags').split(/\s+/));
9087
}
@@ -93,7 +90,7 @@ export default {
9390
if (atom.config.get('linter-clang.clangSuppressWarnings')) {
9491
args.push('-w');
9592
}
96-
if (atom.config.get('linter-clang.verboseDebug')) {
93+
if (atom.inDevMode()) {
9794
args.push('--verbose');
9895
}
9996

@@ -102,23 +99,23 @@ export default {
10299
);
103100

104101
try {
105-
const flags = clangFlags.getClangFlags(activeEditor.getPath());
102+
const flags = clangFlags.getClangFlags(filePath);
106103
if (flags) {
107104
args.push(...flags);
108105
}
109106
} catch (error) {
110-
if (atom.config.get('linter-clang.verboseDebug')) {
107+
if (atom.inDevMode()) {
111108
// eslint-disable-next-line no-console
112109
console.log(error);
113110
}
114111
}
112+
args.push(filePath);
115113

116-
// The file is added to the arguments last.
117-
args.push(file);
118114
const execOpts = {
119115
stream: 'stderr',
120116
allowEmptyStderr: true,
121117
};
118+
122119
return helpers.exec(command, args, execOpts).then(output =>
123120
helpers.parse(output, regex),
124121
);

0 commit comments

Comments
 (0)