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.
This commit is contained in:
Simon Marchi 2018-07-18 11:17:55 -04:00
commit ec95d4a433
9 changed files with 72 additions and 145 deletions

View file

@ -75,8 +75,7 @@ export function expandValue(variableCreate: Function, value: string, root: strin
name = name.substr(1);
}
namespace = namespace + pointerCombineChar + name;
}
else
} else
namespace = name;
}
}
@ -151,45 +150,35 @@ export function expandValue(variableCreate: Function, value: string, root: strin
else if (value.startsWith("true")) {
primitive = "true";
value = value.substr(4).trim();
}
else if (value.startsWith("false")) {
} else if (value.startsWith("false")) {
primitive = "false";
value = value.substr(5).trim();
}
else if (match = nullpointerRegex.exec(value)) {
} else if (match = nullpointerRegex.exec(value)) {
primitive = "<nullptr>";
value = value.substr(match[0].length).trim();
}
else if (match = referenceStringRegex.exec(value)) {
} else if (match = referenceStringRegex.exec(value)) {
value = value.substr(match[1].length).trim();
primitive = parseCString();
}
else if (match = referenceRegex.exec(value)) {
} else if (match = referenceRegex.exec(value)) {
primitive = "*" + match[0];
value = value.substr(match[0].length).trim();
}
else if (match = cppReferenceRegex.exec(value)) {
} else if (match = cppReferenceRegex.exec(value)) {
primitive = match[0];
value = value.substr(match[0].length).trim();
}
else if (match = charRegex.exec(value)) {
} else if (match = charRegex.exec(value)) {
primitive = match[1];
value = value.substr(match[0].length - 1);
primitive += " " + parseCString();
}
else if (match = numberRegex.exec(value)) {
} else if (match = numberRegex.exec(value)) {
primitive = match[0];
value = value.substr(match[0].length).trim();
}
else if (match = variableRegex.exec(value)) {
} else if (match = variableRegex.exec(value)) {
primitive = match[0];
value = value.substr(match[0].length).trim();
}
else if (match = errorRegex.exec(value)) {
} else if (match = errorRegex.exec(value)) {
primitive = match[0];
value = value.substr(match[0].length).trim();
}
else {
} else {
primitive = value;
}
return primitive;
@ -225,22 +214,18 @@ export function expandValue(variableCreate: Function, value: string, root: strin
if (typeof val == "object") {
ref = variableCreate(val);
val = "Object";
}
else if (typeof val == "string" && val.startsWith("*0x")) {
} else if (typeof val == "string" && val.startsWith("*0x")) {
if (extra && MINode.valueOf(extra, "arg") == "1") {
ref = variableCreate(getNamespace("*(" + name), { arg: true });
val = "<args>";
}
else {
} else {
ref = variableCreate(getNamespace("*" + name));
val = "Object@" + val;
}
}
else if (typeof val == "string" && val.startsWith("@0x")) {
} else if (typeof val == "string" && val.startsWith("@0x")) {
ref = variableCreate(getNamespace("*&" + name.substr));
val = "Ref" + val;
}
else if (typeof val == "string" && val.startsWith("<...>")) {
} else if (typeof val == "string" && val.startsWith("<...>")) {
ref = variableCreate(getNamespace(name));
val = "...";
}

View file

@ -71,8 +71,7 @@ export class MI2 extends EventEmitter implements IBackend {
this.emit("debug-ready");
resolve();
}, reject);
}
else {
} else {
if (separateConsole !== undefined) {
linuxTerm.spawnTerminalEmulator(separateConsole).then(tty => {
promises.push(this.sendCommand("inferior-tty-set " + tty));
@ -81,8 +80,7 @@ export class MI2 extends EventEmitter implements IBackend {
resolve();
}, reject);
});
}
else {
} else {
Promise.all(promises).then(() => {
this.emit("debug-ready");
resolve();
@ -187,8 +185,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (ssh) {
if (!path.isAbsolute(target))
target = path.join(cwd, target);
}
else {
} else {
if (!nativePath.isAbsolute(target))
target = nativePath.join(cwd, target);
}
@ -318,8 +315,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (couldBeOutput(line)) {
if (!gdbMatch.exec(line))
this.log("stdout", line);
}
else {
} else {
const parsed = parseMI(line);
if (this.debugOutput)
this.log("log", "GDB -> App: " + JSON.stringify(parsed));
@ -360,8 +356,7 @@ export class MI2 extends EventEmitter implements IBackend {
else if (reason == "exited") { // exit with error code != 0
this.log("stderr", "Program exited with code " + parsed.record("exit-code"));
this.emit("exited-normally", parsed);
}
else {
} else {
this.log("console", "Not implemented stop reason (assuming exception): " + reason);
this.emit("stopped", parsed);
}
@ -410,8 +405,7 @@ export class MI2 extends EventEmitter implements IBackend {
clearTimeout(to);
});
this.sendRaw("-gdb-exit");
}
else {
} else {
const proc = this.process;
const to = setTimeout(() => {
process.kill(-proc.pid);
@ -521,8 +515,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (match.length != breakpoint.countCondition.length) {
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");
location += "-t ";
}
else if (parseInt(match) != 0)
} else if (parseInt(match) != 0)
location += "-t -i " + parseInt(match) + " ";
}
}
@ -547,13 +540,11 @@ export class MI2 extends EventEmitter implements IBackend {
resolve([false, undefined]);
}
}, reject);
}
else {
} else {
this.breakpoints.set(newBrk, bkptNum);
resolve([true, newBrk]);
}
}
else {
} else {
reject(result);
}
}, reject);
@ -570,8 +561,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (result.resultRecords.resultClass == "done") {
this.breakpoints.delete(breakpoint);
resolve(true);
}
else resolve(false);
} else resolve(false);
});
});
}
@ -584,8 +574,7 @@ export class MI2 extends EventEmitter implements IBackend {
if (result.resultRecords.resultClass == "done") {
this.breakpoints.clear();
resolve(true);
}
else resolve(false);
} else resolve(false);
}, () => {
resolve(false);
});
@ -739,8 +728,7 @@ export class MI2 extends EventEmitter implements IBackend {
sendUserInput(command: string, threadId: number = 0, frameLevel: number = 0): Thenable<any> {
if (command.startsWith("-")) {
return this.sendCommand(command.substr(1));
}
else {
} else {
return this.sendCliCommand(command, threadId, frameLevel);
}
}
@ -771,11 +759,9 @@ export class MI2 extends EventEmitter implements IBackend {
if (suppressFailure) {
this.log("stderr", `WARNING: Error executing command '${command}'`);
resolve(node);
}
else
} else
reject(new MIError(node.result("msg") || "Internal error", command));
}
else
} else
resolve(node);
};
this.sendRaw(sel + "-" + command);

View file

@ -10,8 +10,7 @@ export class MI2_LLDB extends MI2 {
if (ssh) {
if (!path.isAbsolute(target))
target = path.join(cwd, target);
}
else {
} else {
if (!nativePath.isAbsolute(target))
target = nativePath.join(cwd, target);
}

View file

@ -39,8 +39,7 @@ function parseString(str: string): string {
else if (m = octalMatch.exec(str.substr(i))) {
ret.writeUInt8(parseInt(m[0], 8), bufIndex++);
i += 2;
}
else
} else
bufIndex += ret.write(str[i], bufIndex);
escaped = false;
} else {
@ -104,12 +103,10 @@ export class MINode implements MIInfo {
current = found[0];
} else return undefined;
} else return undefined;
}
else if (path[0] == '@') {
} else if (path[0] == '@') {
current = [current];
path = path.substr(1);
}
else {
} else {
target = indexRegex.exec(path);
if (target) {
path = path.substr(target[0].length);
@ -118,8 +115,7 @@ export class MINode implements MIInfo {
current = current[i];
} else if (i == 0) {
} else return undefined;
}
else return undefined;
} else return undefined;
}
path = path.trim();
} while (path);
@ -188,8 +184,7 @@ export function parseMI(output: string): MINode {
let str;
try {
str = parseString(output.substr(0, stringEnd));
}
catch (e) {
} catch (e) {
str = output.substr(0, stringEnd);
}
output = output.substr(stringEnd);
@ -286,8 +281,7 @@ export function parseMI(output: string): MINode {
while (result = parseCommaResult())
asyncRecord.output.push(result);
outOfBandRecord.push(asyncRecord);
}
else if (match[3]) {
} else if (match[3]) {
const streamRecord = {
isStream: true,
type: streamRecordType[match[3]],

View file

@ -42,8 +42,7 @@ function getMemoryRange(range: string) {
if (memoryLocationRegex.exec(length))
length = parseInt(length.substr(2), 16).toString();
return "from=" + encodeURIComponent(from) + "&length=" + encodeURIComponent(length);
}
else if ((index = range.indexOf("-")) != -1) {
} else if ((index = range.indexOf("-")) != -1) {
const from = range.substr(0, index);
const to = range.substr(index + 1);
if (!memoryLocationRegex.exec(from))
@ -51,8 +50,7 @@ function getMemoryRange(range: string) {
if (!memoryLocationRegex.exec(to))
return undefined;
return "from=" + encodeURIComponent(from) + "&to=" + encodeURIComponent(to);
}
else if (memoryLocationRegex.exec(range))
} else if (memoryLocationRegex.exec(range))
return "at=" + encodeURIComponent(range);
else return undefined;
}
@ -100,18 +98,14 @@ class MemoryContentProvider implements vscode.TextDocumentContentProvider {
highlightAt = 64;
from = Math.max(loc - 64, 0);
to = Math.max(loc + 768, 0);
}
else if (splits[0].split("=")[0] == "from") {
} else if (splits[0].split("=")[0] == "from") {
from = parseInt(splits[0].split("=")[1].substr(2), 16);
if (splits[1].split("=")[0] == "to") {
to = parseInt(splits[1].split("=")[1].substr(2), 16);
}
else if (splits[1].split("=")[0] == "length") {
} else if (splits[1].split("=")[0] == "length") {
to = from + parseInt(splits[1].split("=")[1]);
}
else return reject("Invalid Range");
}
else return reject("Invalid Range");
} else return reject("Invalid Range");
} else return reject("Invalid Range");
if (to < from)
return reject("Negative Range");
conn.write("examineMemory " + JSON.stringify([from, to - from + 1]));

View file

@ -92,8 +92,7 @@ class GDBDebugSession extends MI2DebugSession {
}, err => {
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
});
}
else {
} else {
this.miDebugger.load(args.cwd, args.target, args.arguments, args.terminal).then(() => {
if (args.autorun)
args.autorun.forEach(command => {
@ -153,8 +152,7 @@ class GDBDebugSession extends MI2DebugSession {
}, err => {
this.sendErrorResponse(response, 102, `Failed to SSH: ${err.toString()}`);
});
}
else {
} else {
if (args.remote) {
this.miDebugger.connect(args.cwd, args.executable, args.target).then(() => {
if (args.autorun)
@ -165,8 +163,7 @@ class GDBDebugSession extends MI2DebugSession {
}, err => {
this.sendErrorResponse(response, 102, `Failed to attach: ${err.toString()}`);
});
}
else {
} else {
this.miDebugger.attach(args.cwd, args.executable, args.target).then(() => {
if (args.autorun)
args.autorun.forEach(command => {

View file

@ -83,8 +83,7 @@ class LLDBDebugSession extends MI2DebugSession {
this.handlePause(undefined);
});
});
}
else {
} else {
this.miDebugger.load(args.cwd, args.target, args.arguments, undefined).then(() => {
if (args.autorun)
args.autorun.forEach(command => {

View file

@ -179,16 +179,14 @@ export class MI2DebugSession extends DebugSession {
response.body = {
value: res.result("value")
};
}
else {
} else {
await this.miDebugger.changeVariable(args.name, args.value);
response.body = {
value: args.value
};
}
this.sendResponse(response);
}
catch (err) {
} catch (err) {
this.sendErrorResponse(response, 11, `Could not continue: ${err}`);
}
}
@ -300,8 +298,7 @@ export class MI2DebugSession extends DebugSession {
if (this.isSSH) {
file = relative(this.switchCWD.replace(/\\/g, "/"), file.replace(/\\/g, "/"));
file = systemPath.resolve(this.trimCWD.replace(/\\/g, "/"), file.replace(/\\/g, "/"));
}
else if (process.platform === "win32") {
} else if (process.platform === "win32") {
if (file.startsWith("\\cygdrive\\") || file.startsWith("/cygdrive/")) {
file = file[10] + ":" + file.substr(11); // replaces /cygdrive/c/foo/bar.txt with c:/foo/bar.txt
}
@ -333,8 +330,7 @@ export class MI2DebugSession extends DebugSession {
}, msg => {
this.sendErrorResponse(response, 2, `Could not continue: ${msg}`);
});
}
else
} else
this.sendResponse(response);
}
@ -353,8 +349,7 @@ export class MI2DebugSession extends DebugSession {
let id: number | string | VariableObject | ExtendedVariable;
if (args.variablesReference < VAR_HANDLES_START) {
id = args.variablesReference - STACK_HANDLES_START;
}
else {
} else {
id = this.variableHandles.get(args.variablesReference);
}
@ -369,8 +364,7 @@ export class MI2DebugSession extends DebugSession {
let id: number;
if (this.variableHandlesReverse.hasOwnProperty(varObj.name)) {
id = this.variableHandlesReverse[varObj.name];
}
else {
} else {
id = createVariable(varObj);
this.variableHandlesReverse[varObj.name] = id;
}
@ -398,29 +392,25 @@ export class MI2DebugSession extends DebugSession {
});
const varId = this.variableHandlesReverse[varObjName];
varObj = this.variableHandles.get(varId) as any;
}
catch (err) {
} catch (err) {
if (err instanceof MIError && err.message == "Variable object not found") {
varObj = await this.miDebugger.varCreate(variable.name, varObjName);
const varId = findOrCreateVariable(varObj);
varObj.exp = variable.name;
varObj.id = varId;
}
else {
} else {
throw err;
}
}
variables.push(varObj.toProtocolVariable());
}
catch (err) {
} catch (err) {
variables.push({
name: variable.name,
value: `<${err}>`,
variablesReference: 0
});
}
}
else {
} else {
if (variable.valueStr !== undefined) {
let expanded = expandValue(createVariable, `{${variable.name}=${variable.valueStr})`, "", variable.raw);
if (expanded) {
@ -447,12 +437,10 @@ export class MI2DebugSession extends DebugSession {
variables: variables
};
this.sendResponse(response);
}
catch (err) {
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
}
else if (typeof id == "string") {
} else if (typeof id == "string") {
// Variable members
let variable;
try {
@ -462,8 +450,7 @@ export class MI2DebugSession extends DebugSession {
let expanded = expandValue(createVariable, variable.result("value"), id, variable);
if (!expanded) {
this.sendErrorResponse(response, 2, `Could not expand variable`);
}
else {
} else {
if (typeof expanded[0] == "string")
expanded = [
{
@ -477,16 +464,13 @@ export class MI2DebugSession extends DebugSession {
};
this.sendResponse(response);
}
}
catch (e) {
} catch (e) {
this.sendErrorResponse(response, 2, `Could not expand variable: ${e}`);
}
}
catch (err) {
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
}
else if (typeof id == "object") {
} else if (typeof id == "object") {
if (id instanceof VariableObject) {
// Variable members
let children: VariableObject[];
@ -502,12 +486,10 @@ export class MI2DebugSession extends DebugSession {
variables: vars
};
this.sendResponse(response);
}
catch (err) {
} catch (err) {
this.sendErrorResponse(response, 1, `Could not expand variable: ${err}`);
}
}
else if (id instanceof ExtendedVariable) {
} else if (id instanceof ExtendedVariable) {
const varReq = id;
if (varReq.options.arg) {
const strArr = [];
@ -526,16 +508,14 @@ export class MI2DebugSession extends DebugSession {
const expanded = expandValue(createVariable, variable.result("value"), varReq.name, variable);
if (!expanded) {
this.sendErrorResponse(response, 15, `Could not expand variable`);
}
else {
} else {
if (typeof expanded == "string") {
if (expanded == "<nullptr>") {
if (argsPart)
argsPart = false;
else
return submit();
}
else if (expanded[0] != '"') {
} else if (expanded[0] != '"') {
strArr.push({
name: "[err]",
value: expanded,
@ -549,8 +529,7 @@ export class MI2DebugSession extends DebugSession {
variablesReference: 0
});
addOne();
}
else {
} else {
strArr.push({
name: "[err]",
value: expanded,
@ -559,24 +538,20 @@ export class MI2DebugSession extends DebugSession {
submit();
}
}
}
catch (e) {
} catch (e) {
this.sendErrorResponse(response, 14, `Could not expand variable: ${e}`);
}
};
addOne();
}
else
} else
this.sendErrorResponse(response, 13, `Unimplemented variable request options: ${JSON.stringify(varReq.options)}`);
}
else {
} else {
response.body = {
variables: id
};
this.sendResponse(response);
}
}
else {
} else {
response.body = {
variables: variables
};
@ -678,6 +653,5 @@ function prettyStringArray(strings) {
return strings.join(", ");
else
return JSON.stringify(strings);
}
else return strings;
} else return strings;
}

View file

@ -26,7 +26,6 @@
"no-unnecessary-initializer": false,
"object-literal-shorthand": false,
"object-literal-sort-keys": false,
"one-line": false,
"one-variable-per-declaration": false,
"only-arrow-functions": false,
"ordered-imports": false,