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

Commit 17cd211

Browse files
committed
Some more code cleanup
Since the grammar can only ever be a single value, it made no sense to have multiple if statements allowing for that case.
1 parent 8877bb6 commit 17cd211

File tree

1 file changed

+26
-19
lines changed

1 file changed

+26
-19
lines changed

lib/main.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,46 +63,52 @@ export default {
6363
scope: 'file',
6464
lintOnFly: false,
6565
grammarScopes: ['source.c', 'source.cpp', 'source.objc', 'source.objcpp'],
66-
lint: (activeEditor) => {
66+
lint: (editor) => {
6767
if (helpers === null) {
6868
helpers = require('atom-linter');
6969
}
7070
if (clangFlags === null) {
7171
clangFlags = require('clang-flags');
7272
}
7373

74-
const filePath = activeEditor.getPath();
74+
const filePath = editor.getPath();
75+
7576
const args = [
7677
'-fsyntax-only',
7778
'-fno-caret-diagnostics',
7879
'-fno-diagnostics-fixit-info',
7980
'-fdiagnostics-print-source-range-info',
8081
'-fexceptions',
82+
`-ferror-limit=${this.clangErrorLimit}`,
8183
];
8284

83-
const grammar = activeEditor.getGrammar().name;
85+
const grammar = editor.getGrammar().name;
8486

85-
if (/^C\+\+/.test(grammar)) {
86-
args.push('-xc++');
87-
args.push(...this.clangDefaultCppFlags.split(/\s+/));
88-
}
89-
if (grammar === 'Objective-C++') {
90-
args.push('-xobjective-c++');
91-
args.push(...this.clangDefaultObjCppFlags.split(/\s+/));
92-
}
93-
if (grammar === 'C') {
94-
args.push('-xc');
95-
args.push(...this.clangDefaultCFlags.split(/\s+/));
96-
}
97-
if (grammar === 'Objective-C') {
98-
args.push('-xobjective-c');
99-
args.push(...this.clangDefaultObjCFlags.split(/\s+/));
87+
switch (grammar) {
88+
case 'Objective-C++':
89+
args.push('-xobjective-c++');
90+
args.push(...this.clangDefaultObjCppFlags.split(/\s+/));
91+
break;
92+
case 'C':
93+
args.push('-xc');
94+
args.push(...this.clangDefaultCFlags.split(/\s+/));
95+
break;
96+
case 'Objective-C':
97+
args.push('-xobjective-c');
98+
args.push(...this.clangDefaultObjCFlags.split(/\s+/));
99+
break;
100+
default:
101+
case 'C++':
102+
case 'C++14':
103+
args.push('-xc++');
104+
args.push(...this.clangDefaultCppFlags.split(/\s+/));
105+
break;
100106
}
101107

102-
args.push(`-ferror-limit=${this.clangErrorLimit}`);
103108
if (this.clangSuppressWarnings) {
104109
args.push('-w');
105110
}
111+
106112
if (atom.inDevMode()) {
107113
args.push('--verbose');
108114
}
@@ -122,6 +128,7 @@ export default {
122128
console.log(error);
123129
}
124130
}
131+
125132
args.push(filePath);
126133

127134
const execOpts = {

0 commit comments

Comments
 (0)