Skip to content

Commit

Permalink
Enable eslint for nni_manager (microsoft#1845)
Browse files Browse the repository at this point in the history
* enable eslint

* remove tslint
  • Loading branch information
chicm-ms authored Dec 11, 2019
1 parent a221043 commit cb15be4
Show file tree
Hide file tree
Showing 42 changed files with 37 additions and 209 deletions.
5 changes: 5 additions & 0 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ jobs:
- script: |
source install.sh
displayName: 'Install nni toolkit via source code'
- script: |
set -e
cd src/nni_manager
yarn eslint
displayName: 'Run eslint'
- script: |
python3 -m pip install torch==0.4.1 --user
python3 -m pip install torchvision==0.2.1 --user
Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/common/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import * as ioc from 'typescript-ioc';

// tslint:disable-next-line:no-any
const Inject: (...args: any[]) => any = ioc.Inject;
const Singleton: (target: Function) => void = ioc.Singleton;
const Container = ioc.Container;
Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/common/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

'use strict';
/* tslint:disable:no-any */

import * as fs from 'fs';
import * as path from 'path';
Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/common/restServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export abstract class RestServer {
}

get endPoint(): string {
// tslint:disable-next-line:no-http-string
return `http://${this.hostName}:${this.port}`;
}

Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ function uniqueString(len: number): string {
function randomSelect<T>(a: T[]): T {
assert(a !== undefined);

// tslint:disable-next-line:insecure-random
return a[Math.floor(Math.random() * a.length)];
}
function parseArg(names: string[]): string {
Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/core/nniDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ class NNIDataStore implements DataStore {
}
}

// tslint:disable-next-line:cyclomatic-complexity
private getTrialJobsByReplayEvents(trialJobEvents: TrialJobEventRecord[]): Map<string, TrialJobInfo> {
this.log.debug('getTrialJobsByReplayEvents begin');

Expand Down
2 changes: 0 additions & 2 deletions src/nni_manager/core/sqlDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { getLogger, Logger } from '../common/log';
import { ExperimentProfile } from '../common/manager';
import { TrialJobDetail } from '../common/trainingService';

/* tslint:disable:no-any */

const createTables: string = `
create table TrialJobEvent (timestamp integer, trialJobId text, event text, data text, logPath text, sequenceId integer);
Expand Down Expand Up @@ -91,7 +90,6 @@ class SqlDB implements Database {
this.log.debug(`Database directory: ${dbDir}`);
assert(fs.existsSync(dbDir));

// tslint:disable-next-line:no-bitwise
const mode: number = createNew ? (sqlite3.OPEN_CREATE | sqlite3.OPEN_READWRITE) : sqlite3.OPEN_READWRITE;
const dbFileName: string = path.join(dbDir, 'nni.sqlite');

Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/core/test/dataStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ describe('Unit test for dataStore', () => {
}
];

// tslint:disable-next-line:no-any
const metricsData: any = [
{
trial_job_id: '111',
Expand Down
2 changes: 1 addition & 1 deletion src/nni_manager/core/test/ipcInterfaceTerminate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function startProcess(): void {
// create IPC interface
dispatcher = createDispatcherInterface(proc);
(<IpcInterface>dispatcher).onCommand((commandType: string, content: string): void => {
console.log(commandType, content); // tslint:disable-line:no-console
console.log(commandType, content);
});
}

Expand Down
4 changes: 1 addition & 3 deletions src/nni_manager/core/test/sqlDatabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,17 @@ const metrics: MetricDataRecord[] = [
{ timestamp: Date.now(), trialJobId: 'C', parameterId: '2', type: 'FINAL', sequence: 0, data: 2.2 } // 5
];

// tslint:disable-next-line:no-any
function assertRecordEqual(record: any, value: any): void {
assert.ok(record.timestamp > new Date(2018, 6, 1).getTime());
assert.ok(record.timestamp < Date.now());

for (const key in value) { // tslint:disable-line:no-for-in
for (const key in value) {
if (key !== 'timestamp') {
assert.equal(record[key], value[key]);
}
}
}

// tslint:disable-next-line:no-any
function assertRecordsEqual(records: any[], inputs: any[], indices: number[]): void {
assert.equal(records.length, indices.length);
for (let i: number = 0; i < records.length; i++) {
Expand Down
2 changes: 0 additions & 2 deletions src/nni_manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@
"rmdir": "^1.2.0",
"tmp": "^0.0.33",
"ts-node": "^7.0.0",
"tslint": "^5.12.0",
"tslint-microsoft-contrib": "^6.0.0",
"typescript": "^3.2.2"
},
"resolutions": {
Expand Down
2 changes: 0 additions & 2 deletions src/nni_manager/rest_server/restHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NNIRestHandler {
public createRestHandler(): Router {
const router: Router = Router();

// tslint:disable-next-line:typedef
router.use((req: Request, res: Response, next) => {
this.log.debug(`${req.method}: ${req.url}: body:\n${JSON.stringify(req.body, undefined, 4)}`);
res.header('Access-Control-Allow-Origin', '*');
Expand Down Expand Up @@ -179,7 +178,6 @@ class NNIRestHandler {
router.put(
'/experiment/cluster-metadata', expressJoi(ValidationSchemas.SETCLUSTERMETADATA),
async (req: Request, res: Response) => {
// tslint:disable-next-line:no-any
const metadata: any = req.body;
const keys: string[] = Object.keys(metadata);
try {
Expand Down
1 change: 0 additions & 1 deletion src/nni_manager/rest_server/test/mockedNNIManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ export class MockedNNIManager extends Manager {
startTime: Date.now(),
endTime: Date.now(),
tags: ['test'],
// tslint:disable-next-line:no-http-string
url: 'http://test',
workingDirectory: '/tmp/mocked',
form: {
Expand Down
4 changes: 0 additions & 4 deletions src/nni_manager/rest_server/test/restserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@

'use strict';

// tslint:disable-next-line:no-implicit-dependencies
import { assert, expect } from 'chai';
// tslint:disable-next-line:no-implicit-dependencies
import * as request from 'request';
import { Container } from 'typescript-ioc';

Expand Down Expand Up @@ -54,7 +52,6 @@ describe('Unit test for rest server', () => {
});

it('Test GET trial-jobs/:id', (done: Mocha.Done) => {
// tslint:disable-next-line:no-any
request.get(`${ROOT_URL}/trial-jobs/1234`, (err: Error, res: request.Response, body: any) => {
if (err) {
assert.fail(err.message);
Expand Down Expand Up @@ -88,7 +85,6 @@ describe('Unit test for rest server', () => {
});

it('Test change concurrent-trial-jobs', (done: Mocha.Done) => {
// tslint:disable-next-line:no-any
request.get(`${ROOT_URL}/experiment`, (err: Error, res: request.Response, body: any) => {
if (err) {
assert.fail(err.message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
'use strict';

import * as assert from 'assert';
// tslint:disable-next-line:no-implicit-dependencies
import * as bodyParser from 'body-parser';
import { Request, Response, Router } from 'express';
import * as fs from 'fs';
Expand Down Expand Up @@ -71,10 +70,8 @@ export abstract class ClusterJobRestServer extends RestServer {
}

// Abstract method to handle trial metrics data
// tslint:disable-next-line:no-any
protected abstract handleTrialMetrics(jobId: string, trialMetrics: any[]): void;

// tslint:disable: no-unsafe-any no-any
protected createRestHandler(): Router {
const router: Router = Router();

Expand Down Expand Up @@ -146,7 +143,6 @@ export abstract class ClusterJobRestServer extends RestServer {

if (!skipLogging) {
// Construct write stream to write remote trial's log into local file
// tslint:disable-next-line:non-literal-fs-path
const writeStream: Writable = fs.createWriteStream(trialLogPath, {
flags: 'a+',
encoding: 'utf8',
Expand All @@ -166,5 +162,4 @@ export abstract class ClusterJobRestServer extends RestServer {

return router;
}
// tslint:enable: no-unsafe-any no-any
}
1 change: 0 additions & 1 deletion src/nni_manager/training_service/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { GPU_INFO_COLLECTOR_FORMAT_WINDOWS } from './gpuData';
* @param codeDir codeDir in nni config file
* @returns file number under codeDir
*/
// tslint:disable: no-redundant-jsdoc
export async function validateCodeDir(codeDir: string): Promise<number> {
let fileCount: number | undefined;
let fileNameValid: boolean = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { String } from 'typescript-string-operations';
import { getLogger } from '../../common/log';
import { mkDirP } from '../../common/utils';

// tslint:disable: no-redundant-jsdoc no-any no-unsafe-any
export namespace AzureStorageClientUtility {

/**
Expand Down Expand Up @@ -114,7 +113,6 @@ export namespace AzureStorageClientUtility {
async function downloadFile(fileServerClient: any, azureDirectory: string, azureFileName: any, azureShare: any,
localFilePath: string): Promise<boolean> {
const deferred: Deferred<boolean> = new Deferred<boolean>();
// tslint:disable-next-line:non-literal-fs-path
await fileServerClient.getFileToStream(azureShare, azureDirectory, azureFileName, fs.createWriteStream(localFilePath),
(error: any, result: any, response: any) => {
if (error) {
Expand All @@ -136,7 +134,6 @@ export namespace AzureStorageClientUtility {
* @param azureShare : the azure share used
* @param localDirectory : local directory to be uploaded
*/
// tslint:disable:non-literal-fs-path
export async function uploadDirectory(fileServerClient: azureStorage.FileService, azureDirectory: string, azureShare: any,
localDirectory: string): Promise<boolean> {
const deferred: Deferred<boolean> = new Deferred<boolean>();
Expand Down Expand Up @@ -221,4 +218,3 @@ export namespace AzureStorageClientUtility {
return deferred.promise;
}
}
// tslint:enable: no-redundant-jsdoc no-any no-unsafe-any
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,13 @@
import * as fs from 'fs';
import { GeneralK8sClient, KubernetesCRDClient } from '../kubernetesApiClient';

/**
* FrameworkController Client
*/
class FrameworkControllerClientFactory {
/**
* Factory method to generate operator client
*/
// tslint:disable-next-line:function-name
public static createClient(): KubernetesCRDClient {
return new FrameworkControllerClientV1();
}
}

/**
* FrameworkController ClientV1
*/
class FrameworkControllerClientV1 extends KubernetesCRDClient {
/**
* constructor, to initialize frameworkcontroller CRD definition
*/
// tslint:disable: no-unsafe-any no-any
public constructor() {
super();
this.crdSchema = JSON.parse(fs.readFileSync('./config/frameworkcontroller/frameworkcontrollerjob-crd-v1.json', 'utf8'));
Expand All @@ -36,11 +22,22 @@ class FrameworkControllerClientV1 extends KubernetesCRDClient {
protected get operator(): any {
return this.client.apis['frameworkcontroller.microsoft.com'].v1.namespaces('default').frameworks;
}
// tslint:enable: no-unsafe-any no-any

public get containerName(): string {
return 'framework';
}
}

/**
* FrameworkController Client
*/
class FrameworkControllerClientFactory {
/**
* Factory method to generate operator client
*/
public static createClient(): KubernetesCRDClient {
return new FrameworkControllerClientV1();
}
}

export { FrameworkControllerClientFactory, GeneralK8sClient };
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { AzureStorage, KeyVaultConfig, KubernetesClusterConfig, KubernetesCluste
KubernetesStorageKind, KubernetesTrialConfig, KubernetesTrialConfigTemplate, NFSConfig, StorageConfig
} from '../kubernetesConfig';

// tslint:disable:completed-docs
export class FrameworkAttemptCompletionPolicy {
public readonly minFailedTaskCount: number;
public readonly minSucceededTaskCount: number;
Expand Down Expand Up @@ -54,7 +53,6 @@ export class FrameworkControllerClusterConfig extends KubernetesClusterConfig {
}
}

// tslint:disable:function-name
export class FrameworkControllerClusterConfigNFS extends KubernetesClusterConfigNFS {
public readonly serviceAccountName: string;
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class FrameworkControllerJobInfoCollector extends KubernetesJobInfoCollec
return Promise.reject('kubernetesCRDClient is undefined');
}

// tslint:disable-next-line:no-any
let kubernetesJobInfo: any;
try {
kubernetesJobInfo = await kubernetesCRDClient.getKubernetesJob(kubernetesTrialJob.kubernetesJobName);
Expand All @@ -37,9 +36,9 @@ export class FrameworkControllerJobInfoCollector extends KubernetesJobInfoCollec
return Promise.resolve();
}

// tslint:disable: no-unsafe-any
if (kubernetesJobInfo.status && kubernetesJobInfo.status.state) {
const frameworkJobType: FrameworkControllerJobStatus = <FrameworkControllerJobStatus>kubernetesJobInfo.status.state;
/* eslint-disable require-atomic-updates */
switch (frameworkJobType) {
case 'AttemptCreationPending':
case 'AttemptCreationRequested':
Expand Down Expand Up @@ -69,9 +68,9 @@ export class FrameworkControllerJobInfoCollector extends KubernetesJobInfoCollec
}
default:
}
/* eslint-enable require-atomic-updates */
}

return Promise.resolve();
}
// tslint:enable: no-unsafe-any
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple
this.trialJobsMap.set(trialJobId, trialJobDetail);

// Create frameworkcontroller job based on generated frameworkcontroller job resource config
// tslint:disable-next-line:no-any
const frameworkcontrollerJobConfig: any = await this.prepareFrameworkControllerConfig(
trialJobId, trialWorkingFolder, frameworkcontrollerJobName);
await this.kubernetesCRDClient.createKubernetesJob(frameworkcontrollerJobConfig);
Expand All @@ -112,7 +111,6 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple
return Promise.resolve(trialJobDetail);
}

// tslint:disable:no-redundant-jsdoc no-any no-unsafe-any
public async setClusterMetadata(key: string, value: string): Promise<void> {
switch (key) {
case TrialConfigMetadataKey.NNI_MANAGER_IP:
Expand Down Expand Up @@ -171,7 +169,6 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple

return Promise.resolve();
}
// tslint:enable: no-any no-unsafe-any

/**
* upload code files to nfs or azureStroage
Expand Down Expand Up @@ -256,7 +253,6 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple
}
}

// tslint:disable: no-any no-unsafe-any
private async prepareFrameworkControllerConfig(trialJobId: string, trialWorkingFolder: string, frameworkcontrollerJobName: string):
Promise<any> {

Expand Down Expand Up @@ -447,7 +443,6 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple
}
};
}
// tslint:enable: no-any no-unsafe-any
}

export { FrameworkControllerTrainingService };
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { GeneralK8sClient, KubernetesCRDClient } from '../kubernetesApiClient';
import { KubeflowOperator } from './kubeflowConfig';


// tslint:disable: no-unsafe-any no-any completed-docs
class TFOperatorClientV1Alpha2 extends KubernetesCRDClient {
/**
* constructor, to initialize tfjob CRD definition
Expand Down Expand Up @@ -130,7 +129,6 @@ class KubeflowOperatorClientFactory {
/**
* Factory method to generate operator client
*/
// tslint:disable-next-line:function-name
public static createClient(kubeflowOperator: KubeflowOperator, operatorApiVersion: string): KubernetesCRDClient {
switch (kubeflowOperator) {
case 'tf-operator': {
Expand Down Expand Up @@ -169,5 +167,4 @@ class KubeflowOperatorClientFactory {
}
}

// tslint:enable: no-unsafe-any
export { KubeflowOperatorClientFactory, GeneralK8sClient };
Loading

0 comments on commit cb15be4

Please sign in to comment.