Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Commit

Permalink
Changed checks for null, undefined. (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
KalitaAlexey authored Feb 26, 2017
1 parent 30dbc43 commit 92e601e
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/components/cargo/cargo_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class UserDefinedArgs {
const configuration = getConfiguration();
const args = configuration.get<string[]>(property);

if (args === undefined) {
if (!args) {
throw new Error(`Failed to get args for property=${property}`);
}

Expand Down Expand Up @@ -465,7 +465,7 @@ export default class CargoManager {

vscode.window.showQuickPick(playgroundProjectTypes)
.then((playgroundProjectType: string | undefined) => {
if (playgroundProjectType === undefined) {
if (!playgroundProjectType) {
logger.debug('quick pick has been cancelled');

return;
Expand Down
2 changes: 1 addition & 1 deletion src/components/cargo/custom_configuration_chooser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class CustomConfigurationChooser {

const customConfigurations = configuration.get<CustomConfiguration[]>(propertyName);

if (customConfigurations === undefined) {
if (!customConfigurations) {
throw new Error(`No custom configurations for property=${propertyName}`);
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/cargo/diagnostic_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function addUniqueDiagnostic(diagnostic: FileDiagnostic, diagnostics: Dia

const fileDiagnostics = diagnostics.get(uri);

if (fileDiagnostics === undefined) {
if (!fileDiagnostics) {
// No diagnostics for the file
// The diagnostic is unique
diagnostics.set(uri, [diagnostic.diagnostic]);
Expand All @@ -51,5 +51,5 @@ export function isUniqueDiagnostic(diagnostic: Diagnostic, diagnostics: Diagnost
return true;
});

return foundDiagnostic === undefined;
return !foundDiagnostic;
}
2 changes: 1 addition & 1 deletion src/components/cargo/output_channel_task_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class OutputChannelTaskManager {
* which differs from the directory containing Cargo.toml.
*/
function prependArgsWithManifestPathIfRequired(): void {
if (cargoCwd === undefined || cargoCwd === cwd) {
if (!cargoCwd || cargoCwd === cwd) {
return;
}

Expand Down
10 changes: 5 additions & 5 deletions src/components/completion/completion_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export default class CompletionManager {
}

private stopDaemon(): void {
if (this.racerDaemon === undefined) {
if (!this.racerDaemon) {
return;
}
this.racerDaemon.kill();
Expand Down Expand Up @@ -306,7 +306,7 @@ export default class CompletionManager {
: results.find(parts => parts[2] === word);

// We actually found a completion instead of a definition, so we won't show the returned info.
if (result === undefined) {
if (!result) {
return undefined;
}

Expand Down Expand Up @@ -547,7 +547,7 @@ export default class CompletionManager {
// Get the first dangling parenthesis, so we don't stop on a function call used as a previous parameter
const startPos = this.firstDanglingParen(document, position);

if (startPos === undefined) {
if (!startPos) {
return undefined;
}

Expand All @@ -566,7 +566,7 @@ export default class CompletionManager {
}
}

if (parts === undefined) {
if (!parts) {
return undefined;
}

Expand Down Expand Up @@ -654,7 +654,7 @@ export default class CompletionManager {
}

private runCommand(document: TextDocument, command: string, args: any[]): Promise<string[]> {
if (this.racerDaemon === undefined) {
if (!this.racerDaemon) {
return Promise.reject(undefined);
}

Expand Down
6 changes: 3 additions & 3 deletions src/components/configuration/configuration_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class ConfigurationManager {

const rlsConfiguration: any | null = configuration['rls'];

if (rlsConfiguration === null) {
if (!rlsConfiguration) {
return undefined;
}

Expand Down Expand Up @@ -236,8 +236,8 @@ export class ConfigurationManager {
return envPath;
}

if (rustcSysRoot === undefined) {
return;
if (!rustcSysRoot) {
return undefined;
}

if (!rustcSysRoot.includes('.rustup')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default class CurrentWorkingDirectoryManager {
}

private checkWorkspaceCanBeUsedAsCwd(): Promise<boolean> {
if (workspace.rootPath === undefined) {
if (!workspace.rootPath) {
return Promise.resolve(false);
}

Expand All @@ -61,7 +61,7 @@ export default class CurrentWorkingDirectoryManager {

const fileName = window.activeTextEditor.document.fileName;

if (workspace.rootPath === undefined || !fileName.startsWith(workspace.rootPath)) {
if (!workspace.rootPath || !fileName.startsWith(workspace.rootPath)) {
return Promise.reject(new Error('Current document not in the workspace'));
}

Expand All @@ -72,11 +72,11 @@ export default class CurrentWorkingDirectoryManager {
const opts = { cwd: cwd };

return findUp('Cargo.toml', opts).then((cargoTomlDirPath: string) => {
if (cargoTomlDirPath === null) {
if (!cargoTomlDirPath) {
return Promise.reject(new Error('Cargo.toml hasn\'t been found'));
}

if (workspace.rootPath === undefined || !cargoTomlDirPath.startsWith(workspace.rootPath)) {
if (!workspace.rootPath || !cargoTomlDirPath.startsWith(workspace.rootPath)) {
return Promise.reject(new Error('Cargo.toml hasn\'t been found within the workspace'));
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/formatting/formatting_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default class FormattingManager implements DocumentFormattingEditProvider
currentFile = Uri.file(line.slice('Diff of '.length, -1));
}

if (currentFile === undefined) {
if (!currentFile) {
continue;
}

Expand Down Expand Up @@ -177,7 +177,7 @@ export default class FormattingManager implements DocumentFormattingEditProvider
continue;
}

if (currentPatch === undefined) {
if (!currentPatch) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/logging/root_logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class RootLogger extends Logger {
}

private log(message: string, severityAsString: string): void {
if (this.logFunction === undefined) {
if (!this.logFunction) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class SymbolInformationParser {
const symbolInformationList: (SymbolInformation | undefined)[] = rustSymbols.map(rustSymbol => {
const kind = this.getSymbolKind(rustSymbol.kind);

if (kind === undefined) {
if (!kind) {
return undefined;
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function addExecutingActionOnSave(

const actionOnSave = configurationManager.getActionOnSave();

if (actionOnSave === null) {
if (!actionOnSave) {
return;
}

Expand Down
6 changes: 3 additions & 3 deletions test/components/cargo/diagnostic_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ suite('Diagnostic Utils Tests', () => {

const fileDiagnostics = diagnostics.get(Uri.file('/1'));

if (fileDiagnostics === undefined) {
if (!fileDiagnostics) {
assert.notEqual(fileDiagnostics, undefined);
} else {
assert.equal(fileDiagnostics.length, 1);
Expand All @@ -109,7 +109,7 @@ suite('Diagnostic Utils Tests', () => {

const fileDiagnostics = diagnostics.get(Uri.file('/1'));

if (fileDiagnostics === undefined) {
if (!fileDiagnostics) {
assert.notEqual(fileDiagnostics, undefined);
} else {
assert.equal(fileDiagnostics.length, 3);
Expand All @@ -132,7 +132,7 @@ suite('Diagnostic Utils Tests', () => {

const fileDiagnostics = diagnostics.get(Uri.file('/1'));

if (fileDiagnostics === undefined) {
if (!fileDiagnostics) {
assert.notEqual(fileDiagnostics, undefined);
} else {
assert.equal(fileDiagnostics.length, 2);
Expand Down

0 comments on commit 92e601e

Please sign in to comment.