Skip to content

Commit

Permalink
Added new tslint rules (#410)
Browse files Browse the repository at this point in the history
  • Loading branch information
itoys committed May 30, 2018
1 parent e5db4fa commit 68c8bfd
Show file tree
Hide file tree
Showing 21 changed files with 955 additions and 963 deletions.
2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ gulp.task('tslint-test', function () {
.pipe(tslint.report());
});

gulp.task('build-src', ['compile-src'/*, 'tslint-src'*/]);
gulp.task('build-src', ['compile-src', 'tslint-src']);
gulp.task('build-test', ['compile-test'/*, 'tslint-test'*/]);
gulp.task('build', ['build-src'/*, 'build-test'*/]);
gulp.task('tslint', ['tslint-src', 'tslint-test']);
Expand Down
4 changes: 2 additions & 2 deletions src/common/extensionMessaging.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import {Hash} from "../utils/hash"
import {Hash} from "../utils/hash";
import * as Q from "q";
import * as net from "net";

Expand All @@ -18,7 +18,7 @@ export enum ExtensionMessage {
SIMULATE,
START_SIMULATE_SERVER,
GET_RUN_ARGUMENTS,
GET_SIMULATOR_IN_EXTERNAL_BROWSER_SETTING
GET_SIMULATOR_IN_EXTERNAL_BROWSER_SETTING,
}

export interface MessageWithArguments {
Expand Down
2 changes: 1 addition & 1 deletion src/common/simulationInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
export interface SimulationInfo {
appHostUrl: string;
simHostUrl: string;
urlRoot: string
urlRoot: string;
}
140 changes: 73 additions & 67 deletions src/cordova.ts

Large diffs are not rendered by default.

678 changes: 339 additions & 339 deletions src/debugger/cordovaDebugAdapter.ts

Large diffs are not rendered by default.

146 changes: 73 additions & 73 deletions src/debugger/cordovaIosDeviceLauncher.ts

Large diffs are not rendered by default.

19 changes: 9 additions & 10 deletions src/debugger/cordovaPathTransformer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import {DebugProtocol} from 'vscode-debugprotocol';
import {utils, logger, chromeUtils, ISetBreakpointsArgs, IDebugTransformer, IStackTraceResponseBody} from 'vscode-chrome-debug-core';
import {ICordovaLaunchRequestArgs, ICordovaAttachRequestArgs} from './cordovaDebugAdapter';
import {utils, logger, chromeUtils, ISetBreakpointsArgs, IStackTraceResponseBody} from "vscode-chrome-debug-core";
import {ICordovaLaunchRequestArgs, ICordovaAttachRequestArgs} from "./cordovaDebugAdapter";

import {BasePathTransformer} from 'vscode-chrome-debug-core';
import {BasePathTransformer} from "vscode-chrome-debug-core";

import * as path from 'path';
import * as fs from 'fs';
import * as path from "path";
import * as fs from "fs";

interface IPendingBreakpoint {
resolve: () => void;
Expand Down Expand Up @@ -130,16 +129,16 @@ export class CordovaPathTransformer extends BasePathTransformer {
}

public getClientPath(sourceUrl: string): string {
let wwwRoot = path.join(this._cordovaRoot, 'www');
let wwwRoot = path.join(this._cordovaRoot, "www");

// Given an absolute file:/// (such as from the iOS simulator) vscode-chrome-debug's
// default behavior is to use that exact file, if it exists. We don't want that,
// since we know that those files are copies of files in the local folder structure.
// A simple workaround for this is to convert file:// paths to bogus http:// paths
sourceUrl = sourceUrl.replace('file:///', 'http://localhost/');
sourceUrl = sourceUrl.replace("file:///", "http://localhost/");

// Find the mapped local file. Try looking first in the user-specified webRoot, then in the project root, and then in the www folder
let defaultPath = '';
let defaultPath = "";
[this._webRoot, this._cordovaRoot, wwwRoot].find((searchFolder) => {
let mappedPath = chromeUtils.targetUrlToClientPath(searchFolder, sourceUrl);

Expand All @@ -154,7 +153,7 @@ export class CordovaPathTransformer extends BasePathTransformer {
if (defaultPath.toLowerCase().indexOf(wwwRoot.toLowerCase()) === 0) {
// If the path appears to be in www, check to see if it exists in /merges/<platform>/<relative path>
let relativePath = path.relative(wwwRoot, defaultPath);
let mergesPath = path.join(this._cordovaRoot, 'merges', this._platform, relativePath);
let mergesPath = path.join(this._cordovaRoot, "merges", this._platform, relativePath);
if (fs.existsSync(mergesPath)) {
// This file is overriden by a merge: Use that one
if (fs.existsSync(defaultPath)) {
Expand Down
10 changes: 5 additions & 5 deletions src/debugger/debugCordova.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import {ChromeDebugSession, BaseSourceMapTransformer, BasePathTransformer} from 'vscode-chrome-debug-core';
import {CordovaDebugAdapter} from './cordovaDebugAdapter';
import {CordovaPathTransformer} from './cordovaPathTransformer';
import {ChromeDebugSession, BaseSourceMapTransformer, BasePathTransformer} from "vscode-chrome-debug-core";
import {CordovaDebugAdapter} from "./cordovaDebugAdapter";
import {CordovaPathTransformer} from "./cordovaPathTransformer";

ChromeDebugSession.run(ChromeDebugSession.getSession({
adapter: CordovaDebugAdapter,
extensionName: 'cordova-tools',
extensionName: "cordova-tools",
pathTransformer: <typeof BasePathTransformer><any>CordovaPathTransformer,
sourceMapTransformer: BaseSourceMapTransformer
sourceMapTransformer: BaseSourceMapTransformer,
}));
77 changes: 37 additions & 40 deletions src/debugger/extension.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as child_process from 'child_process';
import {CordovaProjectHelper} from '../utils/cordovaProjectHelper';
import * as os from 'os';
import * as Q from 'q';
import * as path from 'path';
import * as util from 'util';
import { ExtensionMessageSender, ExtensionMessage } from '../common/extensionMessaging';
import { CordovaCommandHelper } from '../utils/cordovaCommandHelper';
import * as child_process from "child_process";
import {CordovaProjectHelper} from "../utils/cordovaProjectHelper";
import * as Q from "q";
import * as path from "path";
import * as util from "util";

// suppress the following strings because they are not actual errors:
const errorsToSuppress = ['Run an Ionic project on a connected device'];
const errorsToSuppress = ["Run an Ionic project on a connected device"];

export function execCommand(command: string, args: string[], errorLogger: (message: string) => void): Q.Promise<string> {
let deferred = Q.defer<string>();
let proc = child_process.spawn(command, args, { stdio: 'pipe' });
let stderr = '';
let stdout = '';
proc.stderr.on('data', (data: Buffer) => {
let proc = child_process.spawn(command, args, { stdio: "pipe" });
let stderr = "";
let stdout = "";
proc.stderr.on("data", (data: Buffer) => {
stderr += data.toString();
});
proc.stdout.on('data', (data: Buffer) => {
proc.stdout.on("data", (data: Buffer) => {
stdout += data.toString();
});
proc.on('error', (err: Error) => {
proc.on("error", (err: Error) => {
deferred.reject(err);
});
proc.on('close', (code: number) => {
proc.on("close", (code: number) => {
if (code !== 0) {
errorLogger(stderr);
errorLogger(stdout);
deferred.reject(`Error running '${command} ${args.join(' ')}'`);
deferred.reject(`Error running '${command} ${args.join(" ")}'`);
}
deferred.resolve(stdout);
});
Expand All @@ -42,54 +39,54 @@ export function execCommand(command: string, args: string[], errorLogger: (messa
export function cordovaRunCommand(args: string[], cordovaRootPath: string): Q.Promise<string[]> {
let defer = Q.defer<string[]>();
let isIonicProject = CordovaProjectHelper.isIonicProject(cordovaRootPath);
let cliName = isIonicProject ? 'ionic' : 'cordova';
let output = '';
let stderr = '';
let cliName = isIonicProject ? "ionic" : "cordova";
let output = "";
let stderr = "";
let cordovaProcess = cordovaStartCommand(args, cordovaRootPath);

// Prevent these lines to be shown more than once
// to prevent debug console pollution
let isShown = {
'Running command': false,
'cordova prepare': false,
'cordova platform add': false
"Running command": false,
"cordova prepare": false,
"cordova platform add": false,
};

cordovaProcess.stderr.on('data', data => {
cordovaProcess.stderr.on("data", data => {
stderr += data.toString();
for (var i = 0; i < errorsToSuppress.length; i++) {
for (let i = 0; i < errorsToSuppress.length; i++) {
if (data.toString().indexOf(errorsToSuppress[i]) >= 0) {
return;
}
}
defer.notify([data.toString(), 'stderr']);
defer.notify([data.toString(), "stderr"]);
});
cordovaProcess.stdout.on('data', (data: Buffer) => {
let str = data.toString().replace(/\u001b/g, '').replace(/\[2K\[G/g, ''); // Erasing `[2K[G` artifacts from DEBUG CONSOLE output
cordovaProcess.stdout.on("data", (data: Buffer) => {
let str = data.toString().replace(/\u001b/g, "").replace(/\[2K\[G/g, ""); // Erasing `[2K[G` artifacts from DEBUG CONSOLE output
output += str;
for (let message in isShown) {
if (str.indexOf(message) > -1) {
if (!isShown[message]) {
isShown[message] = true;
defer.notify([str, 'stdout']);
defer.notify([str, "stdout"]);
}
return;
}
}
defer.notify([str, 'stdout']);
defer.notify([str, "stdout"]);

if (isIonicProject && str.indexOf('LAUNCH SUCCESS') >= 0) {
if (isIonicProject && str.indexOf("LAUNCH SUCCESS") >= 0) {
defer.resolve([output, stderr]);
}
});
cordovaProcess.on('exit', exitCode => {
cordovaProcess.on("exit", exitCode => {
if (exitCode) {
defer.reject(new Error(util.format('\'%s %s\' failed with exit code %d', cliName, args.join(' '), exitCode)));
defer.reject(new Error(util.format("'%s %s' failed with exit code %d", cliName, args.join(" "), exitCode)));
} else {
defer.resolve([output, stderr]);
}
});
cordovaProcess.on('error', error => {
cordovaProcess.on("error", error => {
defer.reject(error);
});

Expand All @@ -99,29 +96,29 @@ export function cordovaRunCommand(args: string[], cordovaRootPath: string): Q.Pr
export function cordovaStartCommand(args: string[], cordovaRootPath: string): child_process.ChildProcess {
const command = CordovaProjectHelper.getCliCommand(cordovaRootPath);
const isIonic = CordovaProjectHelper.isIonicProject(cordovaRootPath);
const isIonicServe: boolean = args.indexOf('serve') >= 0;
const isIonicServe: boolean = args.indexOf("serve") >= 0;

if (isIonic && !isIonicServe) {
const isIonicCliVersionGte3 = CordovaProjectHelper.isIonicCliVersionGte3(cordovaRootPath);

if (isIonicCliVersionGte3) {
args.unshift('cordova');
args.unshift("cordova");
}
}

if (isIonic) {
args.push('--no-interactive');
args.push("--no-interactive");
} else {
args.push('--no-update-notifier');
args.push("--no-update-notifier");
}

return child_process.spawn(command, args, { cwd: cordovaRootPath });
}

export function killTree(processId: number): void {
const cmd = process.platform === 'win32' ?
const cmd = process.platform === "win32" ?
`taskkill.exe /F /T /PID` :
path.join(__dirname, '../../../scripts/terminateProcess.sh')
path.join(__dirname, "../../../scripts/terminateProcess.sh");

try {
child_process.execSync(`${cmd} ${processId}`);
Expand Down
18 changes: 8 additions & 10 deletions src/extension/completionProviders.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

import * as fs from 'fs';
import * as fs from "fs";
import {
CompletionItem, CompletionItemKind, CompletionItemProvider,
DocumentSelector, CancellationToken, TextDocument, SnippetString, Position
} from 'vscode';
DocumentSelector, SnippetString
} from "vscode";

// Types to outline TextMate snippets format, used in this extension's snippet files
type TMSnippet = { prefix: string, body: string[], description: string };
type TMSnippets = { [name: string]: TMSnippet };

export class IonicCompletionProvider implements CompletionItemProvider {
public static HTML_DOCUMENT_SELECTOR: DocumentSelector = 'html';
public static JS_DOCUMENT_SELECTOR: DocumentSelector = 'javascript';
public static HTML_DOCUMENT_SELECTOR: DocumentSelector = "html";
public static JS_DOCUMENT_SELECTOR: DocumentSelector = "javascript";

private snippetCompletions: CompletionItem[];

constructor(private completionsSource: string) { }

public provideCompletionItems(document: TextDocument,
position: Position,
token: CancellationToken): CompletionItem[] {
public provideCompletionItems(): CompletionItem[] {

if (this.snippetCompletions) {
return this.snippetCompletions;
Expand All @@ -30,7 +28,7 @@ export class IonicCompletionProvider implements CompletionItemProvider {
this.snippetCompletions = [];

try {
let rawSnippets: TMSnippets = JSON.parse(fs.readFileSync(this.completionsSource, 'utf8'));
let rawSnippets: TMSnippets = JSON.parse(fs.readFileSync(this.completionsSource, "utf8"));
this.snippetCompletions = Object.keys(rawSnippets)
.map(name => makeCompletionItem(rawSnippets[name]));

Expand All @@ -47,7 +45,7 @@ function makeCompletionItem(rawSnippet: TMSnippet): CompletionItem {
const item = new CompletionItem(rawSnippet.prefix);
item.documentation = rawSnippet.description;
item.kind = CompletionItemKind.Snippet;
item.insertText = new SnippetString(rawSnippet.body.join('\n'));
item.insertText = new SnippetString(rawSnippet.body.join("\n"));

return item;
}
6 changes: 3 additions & 3 deletions src/extension/extensionServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as net from "net";
import * as Q from "q";
import {PluginSimulator} from "./simulate";
import {SimulationInfo} from '../common/simulationInfo';
import {SimulationInfo} from "../common/simulationInfo";
import {SimulateOptions} from "cordova-simulate";
import * as vscode from "vscode";

Expand All @@ -20,8 +20,8 @@ import {Telemetry} from "../utils/telemetry";
import { CordovaCommandHelper } from "../utils/cordovaCommandHelper";

export class ExtensionServer implements vscode.Disposable {
private serverInstance: net.Server = null;
public pluginSimulator: PluginSimulator;
private serverInstance: net.Server = null;
private messageHandlerDictionary: { [id: number]: ((...argArray: any[]) => Q.Promise<any>) } = {};
private pipePath: string;

Expand Down Expand Up @@ -158,7 +158,7 @@ export class ExtensionServer implements vscode.Disposable {
};

socket.on("data", dataCallback);
};
}

/**
* Recovers the server in case the named socket we use already exists, but no other instance of VSCode is active.
Expand Down
Loading

0 comments on commit 68c8bfd

Please sign in to comment.