Skip to content

Commit ec95d4a

Browse files
committed
tslint: Enable one-line
I'm not sure what is your preference here, but I've seen both styles: } else { and { else { I think it would be nice to have a consistent style, and the former is more common.
1 parent 9a942c5 commit ec95d4a

File tree

9 files changed

+72
-145
lines changed

9 files changed

+72
-145
lines changed

src/backend/gdb_expansion.ts

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
7575
name = name.substr(1);
7676
}
7777
namespace = namespace + pointerCombineChar + name;
78-
}
79-
else
78+
} else
8079
namespace = name;
8180
}
8281
}
@@ -151,45 +150,35 @@ export function expandValue(variableCreate: Function, value: string, root: strin
151150
else if (value.startsWith("true")) {
152151
primitive = "true";
153152
value = value.substr(4).trim();
154-
}
155-
else if (value.startsWith("false")) {
153+
} else if (value.startsWith("false")) {
156154
primitive = "false";
157155
value = value.substr(5).trim();
158-
}
159-
else if (match = nullpointerRegex.exec(value)) {
156+
} else if (match = nullpointerRegex.exec(value)) {
160157
primitive = "<nullptr>";
161158
value = value.substr(match[0].length).trim();
162-
}
163-
else if (match = referenceStringRegex.exec(value)) {
159+
} else if (match = referenceStringRegex.exec(value)) {
164160
value = value.substr(match[1].length).trim();
165161
primitive = parseCString();
166-
}
167-
else if (match = referenceRegex.exec(value)) {
162+
} else if (match = referenceRegex.exec(value)) {
168163
primitive = "*" + match[0];
169164
value = value.substr(match[0].length).trim();
170-
}
171-
else if (match = cppReferenceRegex.exec(value)) {
165+
} else if (match = cppReferenceRegex.exec(value)) {
172166
primitive = match[0];
173167
value = value.substr(match[0].length).trim();
174-
}
175-
else if (match = charRegex.exec(value)) {
168+
} else if (match = charRegex.exec(value)) {
176169
primitive = match[1];
177170
value = value.substr(match[0].length - 1);
178171
primitive += " " + parseCString();
179-
}
180-
else if (match = numberRegex.exec(value)) {
172+
} else if (match = numberRegex.exec(value)) {
181173
primitive = match[0];
182174
value = value.substr(match[0].length).trim();
183-
}
184-
else if (match = variableRegex.exec(value)) {
175+
} else if (match = variableRegex.exec(value)) {
185176
primitive = match[0];
186177
value = value.substr(match[0].length).trim();
187-
}
188-
else if (match = errorRegex.exec(value)) {
178+
} else if (match = errorRegex.exec(value)) {
189179
primitive = match[0];
190180
value = value.substr(match[0].length).trim();
191-
}
192-
else {
181+
} else {
193182
primitive = value;
194183
}
195184
return primitive;
@@ -225,22 +214,18 @@ export function expandValue(variableCreate: Function, value: string, root: strin
225214
if (typeof val == "object") {
226215
ref = variableCreate(val);
227216
val = "Object";
228-
}
229-
else if (typeof val == "string" && val.startsWith("*0x")) {
217+
} else if (typeof val == "string" && val.startsWith("*0x")) {
230218
if (extra && MINode.valueOf(extra, "arg") == "1") {
231219
ref = variableCreate(getNamespace("*(" + name), { arg: true });
232220
val = "<args>";
233-
}
234-
else {
221+
} else {
235222
ref = variableCreate(getNamespace("*" + name));
236223
val = "Object@" + val;
237224
}
238-
}
239-
else if (typeof val == "string" && val.startsWith("@0x")) {
225+
} else if (typeof val == "string" && val.startsWith("@0x")) {
240226
ref = variableCreate(getNamespace("*&" + name.substr));
241227
val = "Ref" + val;
242-
}
243-
else if (typeof val == "string" && val.startsWith("<...>")) {
228+
} else if (typeof val == "string" && val.startsWith("<...>")) {
244229
ref = variableCreate(getNamespace(name));
245230
val = "...";
246231
}

src/backend/mi2/mi2.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ export class MI2 extends EventEmitter implements IBackend {
7171
this.emit("debug-ready");
7272
resolve();
7373
}, reject);
74-
}
75-
else {
74+
} else {
7675
if (separateConsole !== undefined) {
7776
linuxTerm.spawnTerminalEmulator(separateConsole).then(tty => {
7877
promises.push(this.sendCommand("inferior-tty-set " + tty));
@@ -81,8 +80,7 @@ export class MI2 extends EventEmitter implements IBackend {
8180
resolve();
8281
}, reject);
8382
});
84-
}
85-
else {
83+
} else {
8684
Promise.all(promises).then(() => {
8785
this.emit("debug-ready");
8886
resolve();
@@ -187,8 +185,7 @@ export class MI2 extends EventEmitter implements IBackend {
187185
if (ssh) {
188186
if (!path.isAbsolute(target))
189187
target = path.join(cwd, target);
190-
}
191-
else {
188+
} else {
192189
if (!nativePath.isAbsolute(target))
193190
target = nativePath.join(cwd, target);
194191
}
@@ -318,8 +315,7 @@ export class MI2 extends EventEmitter implements IBackend {
318315
if (couldBeOutput(line)) {
319316
if (!gdbMatch.exec(line))
320317
this.log("stdout", line);
321-
}
322-
else {
318+
} else {
323319
const parsed = parseMI(line);
324320
if (this.debugOutput)
325321
this.log("log", "GDB -> App: " + JSON.stringify(parsed));
@@ -360,8 +356,7 @@ export class MI2 extends EventEmitter implements IBackend {
360356
else if (reason == "exited") { // exit with error code != 0
361357
this.log("stderr", "Program exited with code " + parsed.record("exit-code"));
362358
this.emit("exited-normally", parsed);
363-
}
364-
else {
359+
} else {
365360
this.log("console", "Not implemented stop reason (assuming exception): " + reason);
366361
this.emit("stopped", parsed);
367362
}
@@ -410,8 +405,7 @@ export class MI2 extends EventEmitter implements IBackend {
410405
clearTimeout(to);
411406
});
412407
this.sendRaw("-gdb-exit");
413-
}
414-
else {
408+
} else {
415409
const proc = this.process;
416410
const to = setTimeout(() => {
417411
process.kill(-proc.pid);
@@ -521,8 +515,7 @@ export class MI2 extends EventEmitter implements IBackend {
521515
if (match.length != breakpoint.countCondition.length) {
522516
this.log("stderr", "Unsupported break count expression: '" + breakpoint.countCondition + "'. Only supports 'X' for breaking once after X times or '>X' for ignoring the first X breaks");
523517
location += "-t ";
524-
}
525-
else if (parseInt(match) != 0)
518+
} else if (parseInt(match) != 0)
526519
location += "-t -i " + parseInt(match) + " ";
527520
}
528521
}
@@ -547,13 +540,11 @@ export class MI2 extends EventEmitter implements IBackend {
547540
resolve([false, undefined]);
548541
}
549542
}, reject);
550-
}
551-
else {
543+
} else {
552544
this.breakpoints.set(newBrk, bkptNum);
553545
resolve([true, newBrk]);
554546
}
555-
}
556-
else {
547+
} else {
557548
reject(result);
558549
}
559550
}, reject);
@@ -570,8 +561,7 @@ export class MI2 extends EventEmitter implements IBackend {
570561
if (result.resultRecords.resultClass == "done") {
571562
this.breakpoints.delete(breakpoint);
572563
resolve(true);
573-
}
574-
else resolve(false);
564+
} else resolve(false);
575565
});
576566
});
577567
}
@@ -584,8 +574,7 @@ export class MI2 extends EventEmitter implements IBackend {
584574
if (result.resultRecords.resultClass == "done") {
585575
this.breakpoints.clear();
586576
resolve(true);
587-
}
588-
else resolve(false);
577+
} else resolve(false);
589578
}, () => {
590579
resolve(false);
591580
});
@@ -739,8 +728,7 @@ export class MI2 extends EventEmitter implements IBackend {
739728
sendUserInput(command: string, threadId: number = 0, frameLevel: number = 0): Thenable<any> {
740729
if (command.startsWith("-")) {
741730
return this.sendCommand(command.substr(1));
742-
}
743-
else {
731+
} else {
744732
return this.sendCliCommand(command, threadId, frameLevel);
745733
}
746734
}
@@ -771,11 +759,9 @@ export class MI2 extends EventEmitter implements IBackend {
771759
if (suppressFailure) {
772760
this.log("stderr", `WARNING: Error executing command '${command}'`);
773761
resolve(node);
774-
}
775-
else
762+
} else
776763
reject(new MIError(node.result("msg") || "Internal error", command));
777-
}
778-
else
764+
} else
779765
resolve(node);
780766
};
781767
this.sendRaw(sel + "-" + command);

src/backend/mi2/mi2lldb.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ export class MI2_LLDB extends MI2 {
1010
if (ssh) {
1111
if (!path.isAbsolute(target))
1212
target = path.join(cwd, target);
13-
}
14-
else {
13+
} else {
1514
if (!nativePath.isAbsolute(target))
1615
target = nativePath.join(cwd, target);
1716
}

src/backend/mi_parse.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ function parseString(str: string): string {
3939
else if (m = octalMatch.exec(str.substr(i))) {
4040
ret.writeUInt8(parseInt(m[0], 8), bufIndex++);
4141
i += 2;
42-
}
43-
else
42+
} else
4443
bufIndex += ret.write(str[i], bufIndex);
4544
escaped = false;
4645
} else {
@@ -104,12 +103,10 @@ export class MINode implements MIInfo {
104103
current = found[0];
105104
} else return undefined;
106105
} else return undefined;
107-
}
108-
else if (path[0] == '@') {
106+
} else if (path[0] == '@') {
109107
current = [current];
110108
path = path.substr(1);
111-
}
112-
else {
109+
} else {
113110
target = indexRegex.exec(path);
114111
if (target) {
115112
path = path.substr(target[0].length);
@@ -118,8 +115,7 @@ export class MINode implements MIInfo {
118115
current = current[i];
119116
} else if (i == 0) {
120117
} else return undefined;
121-
}
122-
else return undefined;
118+
} else return undefined;
123119
}
124120
path = path.trim();
125121
} while (path);
@@ -188,8 +184,7 @@ export function parseMI(output: string): MINode {
188184
let str;
189185
try {
190186
str = parseString(output.substr(0, stringEnd));
191-
}
192-
catch (e) {
187+
} catch (e) {
193188
str = output.substr(0, stringEnd);
194189
}
195190
output = output.substr(stringEnd);
@@ -286,8 +281,7 @@ export function parseMI(output: string): MINode {
286281
while (result = parseCommaResult())
287282
asyncRecord.output.push(result);
288283
outOfBandRecord.push(asyncRecord);
289-
}
290-
else if (match[3]) {
284+
} else if (match[3]) {
291285
const streamRecord = {
292286
isStream: true,
293287
type: streamRecordType[match[3]],

src/frontend/extension.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ function getMemoryRange(range: string) {
4242
if (memoryLocationRegex.exec(length))
4343
length = parseInt(length.substr(2), 16).toString();
4444
return "from=" + encodeURIComponent(from) + "&length=" + encodeURIComponent(length);
45-
}
46-
else if ((index = range.indexOf("-")) != -1) {
45+
} else if ((index = range.indexOf("-")) != -1) {
4746
const from = range.substr(0, index);
4847
const to = range.substr(index + 1);
4948
if (!memoryLocationRegex.exec(from))
5049
return undefined;
5150
if (!memoryLocationRegex.exec(to))
5251
return undefined;
5352
return "from=" + encodeURIComponent(from) + "&to=" + encodeURIComponent(to);
54-
}
55-
else if (memoryLocationRegex.exec(range))
53+
} else if (memoryLocationRegex.exec(range))
5654
return "at=" + encodeURIComponent(range);
5755
else return undefined;
5856
}
@@ -100,18 +98,14 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
10098
highlightAt = 64;
10199
from = Math.max(loc - 64, 0);
102100
to = Math.max(loc + 768, 0);
103-
}
104-
else if (splits[0].split("=")[0] == "from") {
101+
} else if (splits[0].split("=")[0] == "from") {
105102
from = parseInt(splits[0].split("=")[1].substr(2), 16);
106103
if (splits[1].split("=")[0] == "to") {
107104
to = parseInt(splits[1].split("=")[1].substr(2), 16);
108-
}
109-
else if (splits[1].split("=")[0] == "length") {
105+
} else if (splits[1].split("=")[0] == "length") {
110106
to = from + parseInt(splits[1].split("=")[1]);
111-
}
112-
else return reject("Invalid Range");
113-
}
114-
else return reject("Invalid Range");
107+
} else return reject("Invalid Range");
108+
} else return reject("Invalid Range");
115109
if (to < from)
116110
return reject("Negative Range");
117111
conn.write("examineMemory " + JSON.stringify([from, to - from + 1]));

src/gdb.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ class GDBDebugSession extends MI2DebugSession {
9292
}, err => {
9393
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
9494
});
95-
}
96-
else {
95+
} else {
9796
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal).then(() => {
9897
if (args.autorun)
9998
args.autorun.forEach(command => {
@@ -153,8 +152,7 @@ class GDBDebugSession extends MI2DebugSession {
153152
}, err => {
154153
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
155154
});
156-
}
157-
else {
155+
} else {
158156
if (args.remote) {
159157
this.miDebugger.connect(args.cwd, args.executable, args.target).then(() => {
160158
if (args.autorun)
@@ -165,8 +163,7 @@ class GDBDebugSession extends MI2DebugSession {
165163
}, err => {
166164
this.sendErrorResponse(response, 102, `Failed to attach: ${err.toString()}`);
167165
});
168-
}
169-
else {
166+
} else {
170167
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
171168
if (args.autorun)
172169
args.autorun.forEach(command => {

src/lldb.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ class LLDBDebugSession extends MI2DebugSession {
8383
this.handlePause(undefined);
8484
});
8585
});
86-
}
87-
else {
86+
} else {
8887
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined).then(() => {
8988
if (args.autorun)
9089
args.autorun.forEach(command => {

0 commit comments

Comments
 (0)