Skip to content

Commit 36d1430

Browse files
committed
Integrate tslint and fixes warnings
1 parent b6b2d99 commit 36d1430

24 files changed

+497
-393
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"editor.insertSpaces": true,
33
"files.trimTrailingWhitespace": true,
4+
"editor.renderWhitespace": "all",
45
"files.exclude": {
56
".git": true,
67
"bin": true,

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
"@types/mocha": "2.2.41",
3838
"@types/node": "6.0.46",
3939
"mocha": "2.5.3",
40+
"tslint": "5.10.0",
41+
"tslint-eslint-rules": "^5.3.1",
4042
"typescript": "2.6.2",
4143
"vsce": "~1.36.0",
4244
"vscode": "~1.1.10",
@@ -52,7 +54,8 @@
5254
"launch-as-server": "node --nolazy ./out/debug-adapter/nativeScriptDebug.js --server=4712",
5355
"test-mac": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/mac.json ./out/tests",
5456
"test-win": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/win.json ./out/tests",
55-
"test-custom": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/custom.json ./out/tests"
57+
"test-custom": "mocha --opts ./src/tests/config/mocha.opts --config ../../src/tests/config/custom.json ./out/tests",
58+
"tslint": "tslint -p ./src/tsconfig.json -c tslint.json"
5659
},
5760
"main": "./out/main",
5861
"activationEvents": [

src/analytics/analyticsBaseInfo.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ export enum OperatingSystem {
22
Windows,
33
Linux,
44
OSX,
5-
Other
5+
Other,
66
}
77

8-
export interface AnalyticsBaseInfo {
9-
operatingSystem: OperatingSystem,
10-
cliVersion: string,
11-
extensionVersion: string,
12-
clientId: string
13-
}
8+
export interface IAnalyticsBaseInfo {
9+
operatingSystem: OperatingSystem;
10+
cliVersion: string;
11+
extensionVersion: string;
12+
clientId: string;
13+
}

src/analytics/analyticsService.ts

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,91 @@
1-
import * as os from 'os';
2-
import { GUAService } from './guaService';
3-
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
4-
import { Services } from '../services/extensionHostServices';
5-
import * as utils from '../common/utilities';
1+
import * as _ from 'lodash';
2+
import * as uuid from 'uuid';
63
import * as vscode from 'vscode';
7-
import * as uuid from "uuid";
4+
import { ILogger } from '../common/logger';
5+
import { services } from '../services/extensionHostServices';
6+
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
7+
import { GUAService } from './guaService';
88

99
export class AnalyticsService {
10-
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = "nativescript.hasAnalyticsPromptShown";
11-
private static CLIENT_ID_KEY = "nativescript.analyticsClientId";
10+
private static HAS_ANALYTICS_PROMPT_SHOWN_KEY = 'nativescript.hasAnalyticsPromptShown';
11+
private static CLIENT_ID_KEY = 'nativescript.analyticsClientId';
12+
private static DOCS_LINK = 'https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics';
1213
private static ANALYTICS_PROMPT_MESSAGE = `Help us improve the NativeScript extension by allowing Progress to collect anonymous usage data.
13-
For more information about the gathered information and how it is used, read our [privacy statement](https://www.progress.com/legal/privacy-policy).
14-
You can [disable the analytics and data collection](https://github.com/NativeScript/nativescript-vscode-extension/blob/master/README.md#how-to-disable-the-analytics) at any given time.
14+
For more information about the gathered information and how it is used,
15+
read our [privacy statement](https://www.progress.com/legal/privacy-policy).
16+
You can [disable the analytics and data collection](${AnalyticsService.DOCS_LINK}) at any given time.
1517
Do you want to enable analytics?`;
16-
private static ANALYTICS_PROMPT_ACCEPT_ACTION = "Yes";
17-
private static ANALYTICS_PROMPT_DENY_ACTION = "No";
18+
19+
private static ANALYTICS_PROMPT_ACCEPT_ACTION = 'Yes';
20+
private static ANALYTICS_PROMPT_DENY_ACTION = 'No';
21+
22+
private static getOperatingSystem(): OperatingSystem {
23+
switch (process.platform) {
24+
case 'win32':
25+
return OperatingSystem.Windows;
26+
case 'darwin':
27+
return OperatingSystem.OSX;
28+
case 'linux':
29+
case 'freebsd':
30+
return OperatingSystem.Linux;
31+
default:
32+
return OperatingSystem.Other;
33+
}
34+
}
1835

1936
private _globalState: vscode.Memento;
20-
private _baseInfo: AnalyticsBaseInfo;
37+
private _logger: ILogger;
38+
private _baseInfo: IAnalyticsBaseInfo;
2139
private _gua: GUAService;
2240
private _analyticsEnabled: boolean;
2341

24-
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string) {
42+
constructor(globalState: vscode.Memento, cliVersion: string, extensionVersion: string, logger: ILogger) {
2543
this._globalState = globalState;
44+
this._logger = logger;
2645

2746
vscode.workspace.onDidChangeConfiguration(() => this.updateAnalyticsEnabled());
2847

2948
this._baseInfo = {
3049
cliVersion,
50+
clientId: this.getOrGenerateClientId(),
3151
extensionVersion,
3252
operatingSystem: AnalyticsService.getOperatingSystem(),
33-
clientId: this.getOrGenerateClientId()
3453
};
3554
}
3655

3756
public launchDebugger(request: string, platform: string): Promise<any> {
38-
if(this._analyticsEnabled) {
57+
if (this._analyticsEnabled) {
3958
try {
4059
return this._gua.launchDebugger(request, platform);
41-
} catch(e) {}
60+
} catch (e) {
61+
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
62+
}
4263
}
4364

4465
return Promise.resolve();
4566
}
4667

4768
public runRunCommand(platform: string): Promise<any> {
48-
if(this._analyticsEnabled) {
69+
if (this._analyticsEnabled) {
4970
try {
5071
return this._gua.runRunCommand(platform);
51-
} catch(e) { }
72+
} catch (e) {
73+
this._logger.log(`Analytics error: ${_.isString(e) ? e : e.message}`);
74+
}
5275
}
5376

5477
return Promise.resolve();
5578
}
5679

57-
private static getOperatingSystem() : OperatingSystem {
58-
switch(process.platform) {
59-
case 'win32':
60-
return OperatingSystem.Windows;
61-
case 'darwin':
62-
return OperatingSystem.OSX;
63-
case 'linux':
64-
case 'freebsd':
65-
return OperatingSystem.Linux;
66-
default:
67-
return OperatingSystem.Other;
68-
};
69-
}
70-
71-
public initialize() : void {
80+
public initialize(): void {
7281
const hasAnalyticsPromptShown = this._globalState.get<boolean>(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY);
73-
if(!hasAnalyticsPromptShown) {
82+
83+
if (!hasAnalyticsPromptShown) {
7484
vscode.window.showInformationMessage(AnalyticsService.ANALYTICS_PROMPT_MESSAGE,
7585
AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION,
76-
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION
86+
AnalyticsService.ANALYTICS_PROMPT_DENY_ACTION,
7787
)
78-
.then(result => this.onAnalyticsMessageConfirmation(result));
88+
.then((result) => this.onAnalyticsMessageConfirmation(result));
7989

8090
return;
8191
}
@@ -86,28 +96,28 @@ export class AnalyticsService {
8696
private getOrGenerateClientId(): string {
8797
let clientId = this._globalState.get<string>(AnalyticsService.CLIENT_ID_KEY);
8898

89-
if(!clientId) {
99+
if (!clientId) {
90100
clientId = uuid.v4();
91101
this._globalState.update(AnalyticsService.CLIENT_ID_KEY, clientId);
92102
}
93103

94104
return clientId;
95105
}
96106

97-
private onAnalyticsMessageConfirmation(result: string) : void {
107+
private onAnalyticsMessageConfirmation(result: string): void {
98108
const shouldEnableAnalytics = result === AnalyticsService.ANALYTICS_PROMPT_ACCEPT_ACTION ? true : false;
99109

100110
this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY, true);
101111

102-
Services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
112+
services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
103113
this.updateAnalyticsEnabled();
104114
}
105115

106116
private updateAnalyticsEnabled() {
107-
this._analyticsEnabled = Services.workspaceConfigService.isAnalyticsEnabled;
117+
this._analyticsEnabled = services.workspaceConfigService.isAnalyticsEnabled;
108118

109-
if(this._analyticsEnabled && !this._gua) {
119+
if (this._analyticsEnabled && !this._gua) {
110120
this._gua = new GUAService('UA-111455-29', this._baseInfo);
111121
}
112122
}
113-
}
123+
}

src/analytics/guaService.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ua from 'universal-analytics';
2-
import { AnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
2+
import { IAnalyticsBaseInfo, OperatingSystem } from './analyticsBaseInfo';
33

44
/**
55
* Google Universal Analytics Service
@@ -8,38 +8,42 @@ export class GUAService {
88
private _visitor: any;
99
private _getBasePayload: () => any;
1010

11-
constructor(trackingId: string, baseInfo: AnalyticsBaseInfo) {
11+
constructor(trackingId: string, baseInfo: IAnalyticsBaseInfo) {
1212
this._visitor = ua(trackingId, baseInfo.clientId, { requestOptions: {}, strictCidFormat: false });
1313
this._getBasePayload = () => {
1414
return {
15-
cid: baseInfo.clientId,
16-
dh: 'ns-vs-extension.org',
1715
cd5: baseInfo.cliVersion,
1816
cd6: OperatingSystem[baseInfo.operatingSystem],
19-
cd7: baseInfo.extensionVersion
17+
cd7: baseInfo.extensionVersion,
18+
cid: baseInfo.clientId,
19+
dh: 'ns-vs-extension.org',
2020
};
2121
};
2222
}
2323

2424
public launchDebugger(request: string, platform: string): Promise<any> {
25-
let payload = this._getBasePayload();
25+
const payload = this._getBasePayload();
26+
2627
payload.ec = 'vscode-extension-debug'; // event category
2728
payload.ea = `debug-${request}-on-${platform}`; // event action
29+
2830
return this.sendEvent(payload);
2931
}
3032

3133
public runRunCommand(platform: string): Promise<any> {
32-
let payload = this._getBasePayload();
34+
const payload = this._getBasePayload();
35+
3336
payload.ec = 'vscode-extension-command'; // event category
3437
payload.ea = `command-run-on-${platform}`; // event action
38+
3539
return this.sendEvent(payload);
3640
}
3741

3842
private sendEvent(params): Promise<any> {
3943
return new Promise<any>((res, rej) => {
40-
this._visitor.event(params, err => {
44+
this._visitor.event(params, (err) => {
4145
return err ? rej(err) : res();
4246
});
4347
});
4448
}
45-
}
49+
}

src/common/extensionProtocol.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
export interface Request {
1+
export interface IRequest {
22
id: string;
33
service: string;
44
method: string;
55
args: any[];
66
}
77

8-
export interface Response {
8+
export interface IResponse {
99
requestId: string;
10-
result: Object;
10+
result: object;
1111
}
1212

13-
export const BEFORE_DEBUG_START = "before-debug-start";
14-
export const NS_DEBUG_ADAPTER_MESSAGE = "ns-debug-adapter-message";
13+
export const BEFORE_DEBUG_START = 'before-debug-start';
14+
export const NS_DEBUG_ADAPTER_MESSAGE = 'ns-debug-adapter-message';

src/common/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ interface ILogger {
1010
log(msg: string, level?: LogLevel): void;
1111
}
1212

13-
export { ILogger, LogLevel }
13+
export { ILogger, LogLevel };

src/common/utilities.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import {ChildProcess, exec} from 'child_process';
1+
import { ChildProcess, exec } from 'child_process';
22
import * as os from 'os';
33

4-
export function killProcess(childProcess: ChildProcess) : void {
4+
export function killProcess(childProcess: ChildProcess): void {
55
switch (process.platform) {
6-
case "win32":
6+
case 'win32':
77
exec(`taskkill /pid ${childProcess.pid} /T /F`);
88
break;
99

1010
default:
11-
childProcess.kill("SIGINT");
11+
childProcess.kill('SIGINT');
1212
break;
1313
}
1414
}
1515

1616
export const enum Platform {
17-
Windows, OSX, Linux
17+
Windows, OSX, Linux,
1818
}
1919

2020
export function getPlatform(): Platform {
2121
const platform = os.platform();
22+
2223
return platform === 'darwin' ? Platform.OSX :
2324
platform === 'win32' ? Platform.Windows :
2425
Platform.Linux;

src/common/workspaceConfigService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ export class WorkspaceConfigService {
1212
public get tnsPath(): string {
1313
return vscode.workspace.getConfiguration('nativescript').get('tnsPath') as string;
1414
}
15-
}
15+
}
Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,21 @@
1-
import { chromeConnection, chromeTargetDiscoveryStrategy, ChromeDebugAdapter, telemetry, logger, ChromeDebugSession, UrlPathTransformer } from 'vscode-chrome-debug-core';
2-
import * as path from 'path';
31
import * as os from 'os';
2+
import * as path from 'path';
3+
import { chromeConnection, ChromeDebugSession } from 'vscode-chrome-debug-core';
44
import { NativeScriptDebugAdapter } from './nativeScriptDebugAdapter';
55
import { NativeScriptPathTransformer } from './nativeScriptPathTransformer';
6-
import * as uuid from "uuid";
7-
8-
class Discovery extends chromeTargetDiscoveryStrategy.ChromeTargetDiscovery {
9-
constructor() {
10-
super(logger, new telemetry.TelemetryReporter())
11-
}
12-
13-
public getTarget(address: string, port: number, targetFilter?: any, targetUrl?: string): Promise<chromeConnection.ITarget> {
14-
return Promise.resolve({
15-
webSocketDebuggerUrl: `ws://${address}:${port}`,
16-
description: "NS Debug Target",
17-
id: uuid.v4(),
18-
title: "NS Debug Target",
19-
type: "node",
20-
devtoolsFrontendUrl: `chrome-devtools://devtools/bundled/inspector.html?experiments=true&ws=${address}:${port}`
21-
});
22-
}
23-
24-
async getAllTargets(address: string, port: number, targetFilter?: chromeConnection.ITargetFilter, targetUrl?: string): Promise<chromeConnection.ITarget[]> {
25-
const target = await this.getTarget(address, port);
26-
return Promise.resolve([ target ]);
27-
}
28-
}
6+
import { NativeScriptTargetDiscovery } from './nativeScriptTargetDiscovery';
297

308
class NSAndroidConnection extends chromeConnection.ChromeConnection {
319
constructor() {
32-
super(new Discovery());
10+
super(new NativeScriptTargetDiscovery());
3311
}
3412
}
3513

3614
ChromeDebugSession.run(ChromeDebugSession.getSession(
3715
{
38-
logFilePath: path.join(os.tmpdir(), 'nativescript-extension.txt'),
3916
adapter: NativeScriptDebugAdapter,
40-
extensionName: 'nativescript-extension',
4117
chromeConnection: NSAndroidConnection,
42-
pathTransformer: NativeScriptPathTransformer
18+
extensionName: 'nativescript-extension',
19+
logFilePath: path.join(os.tmpdir(), 'nativescript-extension.txt'),
20+
pathTransformer: NativeScriptPathTransformer,
4321
}));

0 commit comments

Comments
 (0)