Skip to content

Commit 9ca9fe8

Browse files
committed
Minor code quality improvements
1 parent 8e53c36 commit 9ca9fe8

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

src/decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ConfigurationTarget, workspace } from "vscode";
2-
import util = require("util");
2+
import * as util from "util";
33
import { IEquatable, ValueEqualsSet } from "./utilities/hashset";
44
import { LogLevel, logMessage } from "./logger";
55

src/hover.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -192,30 +192,32 @@ export function getDefinitionFromFile(filename: string, line: number): Navigatio
192192
try {
193193
const data = fs.readFileSync(filepath, "utf-8");
194194
const lines = data.split("\n");
195-
if (line <= lines.length) {
196-
let text = lines[line - 1].trim();
197-
if (text.endsWith(":")) {
198-
text = text.slice(0, -1);
199-
} else if (text.endsWith("(")) {
200-
text = text + ")";
201-
} else if (text.endsWith("[")) {
202-
text = text + "]";
203-
} else if (text.endsWith("{")) {
204-
text = text + "}";
205-
}
195+
if (line >= lines.length) {
196+
return undefined;
197+
}
206198

207-
let docs = "";
208-
docs = getPyDocsAtLine(lines, line - 1);
199+
let text = lines[line - 1].trim();
200+
if (text.endsWith(":")) {
201+
text = text.slice(0, -1);
202+
} else if (text.endsWith("(")) {
203+
text = text + ")";
204+
} else if (text.endsWith("[")) {
205+
text = text + "]";
206+
} else if (text.endsWith("{")) {
207+
text = text + "}";
208+
}
209209

210-
let args = "";
211-
if (text.indexOf("(") > 0) {
212-
args = text.substring(text.indexOf("("));
213-
args = args.replace("(self, ", "(");
214-
args = args.replace("(self)", "()");
215-
}
210+
let docs = "";
211+
docs = getPyDocsAtLine(lines, line - 1);
216212

217-
return new Navigation("workspace", text, filename, line, docs, args, "", 0);
213+
let args = "";
214+
if (text.indexOf("(") > 0) {
215+
args = text.substring(text.indexOf("("));
216+
args = args.replace("(self, ", "(");
217+
args = args.replace("(self)", "()");
218218
}
219+
220+
return new Navigation("workspace", text, filename, line, docs, args, "", 0);
219221
} catch (error) {
220222
return undefined;
221223
}

src/navigation-data.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,16 @@ export class NavigationData {
201201
if (locations && locations.length > 0) {
202202
return locations;
203203
}
204+
205+
return undefined;
204206
}
205207

206208
static getNavigationDumpEntry(keyword: string): Navigation | undefined {
207209
const data = NavigationData.getNavigationDumpEntries(keyword);
208210
if (data) {
209211
return data[0];
210212
}
213+
return undefined;
211214
}
212215

213216
static getNavigationDumpEntries(keyword: string): Navigation[] | undefined {
@@ -416,6 +419,7 @@ export class NavigationData {
416419
}
417420
}
418421
}
422+
return;
419423
}
420424

421425
static getClassData(location: Navigation): Navigation {

src/utilities/hashset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IEquatable<T> {
1212
* The current implementation is not very efficient, but it works.
1313
*/
1414
export class ValueEqualsSet<T extends IEquatable<T>> extends Set<T> {
15-
add(value: T) {
15+
override add(value: T) {
1616
if (!this.has(value)) {
1717
super.add(value);
1818
}
@@ -26,7 +26,7 @@ export class ValueEqualsSet<T extends IEquatable<T>> extends Set<T> {
2626
return this;
2727
}
2828

29-
has(otherValue: T): boolean {
29+
override has(otherValue: T): boolean {
3030
for (const value of this.values()) {
3131
if (value.equals(otherValue)) {
3232
return true;

tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
/* Additional Checks */
2424
"noUnusedLocals": true, // Report errors on unused locals.
2525
// "noUnusedParameters": true, // Report errors on unused parameters.
26-
//"noImplicitReturns": true, // Report error when not all code paths in function return a value.
2726
// "noFallthroughCasesInSwitch": true, // Report errors for fallthrough cases in switch statement.
2827
// "noUncheckedIndexedAccess": true, // Include 'undefined' in index signature results
2928
// "noPropertyAccessFromIndexSignature": true, // Require undeclared properties from index signatures to use element accesses.
29+
"noImplicitReturns": true, // Report error when not all code paths in function return a value.
30+
"noImplicitOverride": true, // Ensure overriding members in derived classes are marked with an 'override' modifier.
31+
"noImplicitThis": true, // Raise error on 'this' expressions with an implied 'any' type.
3032
"exactOptionalPropertyTypes": true, // Force exact optional types. (Aka. undefined needs to be added to optionals)
3133

3234
/* Module Resolution Options */

0 commit comments

Comments
 (0)