Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit 78ef90f

Browse files
committed
Migrate from TSLint to ESlint
- Removed TSLint and tslint.json configuration file - Added ESLint with `recommended` TypeScript configurations. - Removed all `I` prefix from type declarations (per ESLint recommendation) - Have added return types to all function declarations (per ESLint recommendation) - To have minimal conflict with integration, many of the recommended ESLint rules have been disabled on a per-page/line basis. - We should attempt to remove these `/* eslint-disable ...` lines as we refactor code and conform completely to the recommended linting rules.
1 parent 46d63e6 commit 78ef90f

File tree

121 files changed

+1582
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+1582
-1222
lines changed

Diff for: .eslintrc.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = {
2+
root: true,
3+
parser: "@typescript-eslint/parser",
4+
plugins: ["@typescript-eslint"],
5+
extends: [
6+
"eslint:recommended",
7+
"plugin:@typescript-eslint/eslint-recommended",
8+
"plugin:@typescript-eslint/recommended"
9+
]
10+
};

Diff for: package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
"scripts": {
99
"build": "shx rm -rf dist && webpack && pkg -t node12-linux-x64,node12-macos-x64,node12-win-x64 dist/spk.js && shx mv spk-{linux,macos,win.exe} dist",
1010
"build-cmd-docs": "ts-node tools/generateDoc.ts",
11-
"lint": "tslint 'src/**/*.ts{,x}'",
11+
"lint": "eslint 'src/**/*.ts{,x}'",
1212
"lint-fix": "tslint --fix 'src/**/*.ts{,x}'",
13-
"test": "jest --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html",
13+
"test": "jest --rootDir src --reporters=jest-junit --reporters=default --coverage --coverageReporters=cobertura --coverageReporters=html",
1414
"test-watch": "jest --watchAll",
1515
"postinstall": "cd node_modules/azure-devops-node-api && git apply ../../patches/001-azure-devops-node.patch || true",
1616
"test-coverage-html": "jest --coverage --coverageReporters=html"
@@ -29,6 +29,9 @@
2929
"@types/node-emoji": "^1.8.1",
3030
"@types/shelljs": "^0.8.5",
3131
"@types/uuid": "^3.4.5",
32+
"@typescript-eslint/eslint-plugin": "^2.23.0",
33+
"@typescript-eslint/parser": "^2.23.0",
34+
"eslint": "^6.8.0",
3235
"husky": ">=1",
3336
"jest": "^24.9.0",
3437
"jest-junit": "^9.0.0",
@@ -42,7 +45,6 @@
4245
"ts-jest": "^24.2.0",
4346
"ts-loader": "^6.2.1",
4447
"ts-node": "^8.5.4",
45-
"tslint": "^5.20.0",
4648
"tslint-config-prettier": "^1.18.0",
4749
"typescript": "^3.7.4",
4850
"url-loader": "^3.0.0",

Diff for: src/commands/command.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-use-before-define */
12
import commander from "commander";
23
import { enableVerboseLogging, logger } from "../logger";
34

@@ -9,11 +10,11 @@ import { enableVerboseLogging, logger } from "../logger";
910
* Warning: Avoid implementing this interface directly; use Command() function
1011
* to generate concrete implementations.
1112
*/
12-
interface ICommand {
13+
interface Command {
1314
name: string;
1415
description: string;
1516
command: commander.Command;
16-
subCommands: ICommand[];
17+
subCommands: Command[];
1718
}
1819

1920
/**
@@ -39,8 +40,8 @@ export const Command = (
3940
name: string,
4041
description: string,
4142
decorators: Array<(c: commander.Command) => void> = [],
42-
subCommands: ICommand[] = []
43-
): ICommand => {
43+
subCommands: Command[] = []
44+
): Command => {
4445
// Initialize default command
4546
const cmd = new commander.Command();
4647
cmd
@@ -95,7 +96,7 @@ const decrementArgv = (argv: string[]): string[] => {
9596
* @param cmd ICommand object to execute against
9697
* @param argv Array of arguments, flags *must* come at the end (limitation of using git-style sub-commands)
9798
*/
98-
export const executeCommand = (cmd: ICommand, argv: string[]): void => {
99+
export const executeCommand = (cmd: Command, argv: string[]): void => {
99100
const targetCommandName = argv.slice(2, 3)[0];
100101
const targetCommand = cmd.subCommands.find(
101102
sc => sc.name === targetCommandName
@@ -129,7 +130,7 @@ export const executeCommand = (cmd: ICommand, argv: string[]): void => {
129130
*
130131
* @param c ICommand object to prepare
131132
*/
132-
const linkSubCommands = (c: ICommand): ICommand => {
133+
const linkSubCommands = (c: Command): Command => {
133134
const { command, subCommands } = c;
134135
// Add all sub-commands
135136
for (const subCommand of subCommands) {

Diff for: src/commands/deployment/create.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import uuid = require("uuid");
22
import * as azure from "../../lib/azure/deploymenttable";
33
import { deepClone } from "../../lib/util";
44
import { disableVerboseLogging, enableVerboseLogging } from "../../logger";
5-
import { execute, ICommandOptions } from "./create";
5+
import { execute, CommandOptions } from "./create";
66

77
beforeAll(() => {
88
enableVerboseLogging();
@@ -12,7 +12,7 @@ afterAll(() => {
1212
disableVerboseLogging();
1313
});
1414

15-
const MOCKED_VALS: ICommandOptions = {
15+
const MOCKED_VALS: CommandOptions = {
1616
accessKey: undefined,
1717
commitId: undefined,
1818
env: undefined,
@@ -30,7 +30,7 @@ const MOCKED_VALS: ICommandOptions = {
3030
tableName: undefined
3131
};
3232

33-
const getMockedValues = (withKeyValue = false): ICommandOptions => {
33+
const getMockedValues = (withKeyValue = false): CommandOptions => {
3434
const vals = deepClone(MOCKED_VALS);
3535

3636
if (withKeyValue) {

Diff for: src/commands/deployment/create.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
12
import commander from "commander";
23
import {
34
addSrcToACRPipeline,
4-
IDeploymentTable,
5+
DeploymentTable,
56
updateACRToHLDPipeline,
67
updateHLDToManifestPipeline,
78
updateManifestCommitId
@@ -14,7 +15,7 @@ import decorator from "./create.decorator.json";
1415
/**
1516
* Command Line values from the commander
1617
*/
17-
export interface ICommandOptions {
18+
export interface CommandOptions {
1819
accessKey: string | undefined;
1920
commitId: string | undefined;
2021
env: string | undefined;
@@ -37,7 +38,7 @@ export interface ICommandOptions {
3738
*
3839
* @param opts values from commander
3940
*/
40-
export const validateValues = (opts: ICommandOptions) => {
41+
export const validateValues = (opts: CommandOptions): void => {
4142
if (
4243
!hasValue(opts.accessKey) ||
4344
!hasValue(opts.name) ||
@@ -51,9 +52,9 @@ export const validateValues = (opts: ICommandOptions) => {
5152
};
5253

5354
export const handlePipeline1 = async (
54-
tableInfo: IDeploymentTable,
55-
opts: ICommandOptions
56-
) => {
55+
tableInfo: DeploymentTable,
56+
opts: CommandOptions
57+
): Promise<void> => {
5758
if (
5859
!hasValue(opts.imageTag) ||
5960
!hasValue(opts.commitId) ||
@@ -74,9 +75,9 @@ export const handlePipeline1 = async (
7475
};
7576

7677
export const handlePipeline2 = async (
77-
tableInfo: IDeploymentTable,
78-
opts: ICommandOptions
79-
) => {
78+
tableInfo: DeploymentTable,
79+
opts: CommandOptions
80+
): Promise<void> => {
8081
if (
8182
!hasValue(opts.hldCommitId) ||
8283
!hasValue(opts.env) ||
@@ -105,13 +106,13 @@ export const handlePipeline2 = async (
105106
* @param exitFn exit function
106107
*/
107108
export const execute = async (
108-
opts: ICommandOptions,
109+
opts: CommandOptions,
109110
exitFn: (status: number) => Promise<void>
110-
) => {
111+
): Promise<void> => {
111112
try {
112113
validateValues(opts);
113114

114-
const tableInfo: IDeploymentTable = {
115+
const tableInfo: DeploymentTable = {
115116
accountKey: opts.accessKey!,
116117
accountName: opts.name!,
117118
partitionKey: opts.partitionKey!,
@@ -153,7 +154,7 @@ export const execute = async (
153154
* @param command
154155
*/
155156
export const commandDecorator = (command: commander.Command): void => {
156-
buildCmd(command, decorator).action(async (opts: ICommandOptions) => {
157+
buildCmd(command, decorator).action(async (opts: CommandOptions) => {
157158
await execute(opts, async (status: number) => {
158159
await exitCmd(logger, process.exit, status);
159160
});

Diff for: src/commands/deployment/dashboard.test.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
/* eslint-disable @typescript-eslint/camelcase */
13
jest.mock("open");
24
import open from "open";
35
jest.mock("../../config");
@@ -28,7 +30,7 @@ afterAll(() => {
2830
disableVerboseLogging();
2931
});
3032

31-
const mockConfig = () => {
33+
const mockConfig = (): void => {
3234
(Config as jest.Mock).mockReturnValueOnce({
3335
azure_devops: {
3436
access_token: uuid(),

Diff for: src/commands/deployment/dashboard.ts

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable @typescript-eslint/camelcase */
2+
/* eslint-disable @typescript-eslint/no-use-before-define */
3+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
14
import commander from "commander";
25
import GitUrlParse from "git-url-parse";
36
import open = require("open");
@@ -7,18 +10,18 @@ import { getRepositoryName } from "../../lib/gitutils";
710
import { exec } from "../../lib/shell";
811
import { isPortNumberString, validatePrereqs } from "../../lib/validator";
912
import { logger } from "../../logger";
10-
import { IConfigYaml } from "../../types";
13+
import { ConfigYaml } from "../../types";
1114
import decorator from "./dashboard.decorator.json";
1215

13-
export interface IIntrospectionManifest {
16+
export interface IntrospectionManifest {
1417
githubUsername?: string;
1518
manifestRepoName: string;
1619
}
1720

1821
/**
1922
* Command line option values from commander
2023
*/
21-
export interface ICommandOptions {
24+
export interface CommandOptions {
2225
port: string;
2326
removeAll: boolean;
2427
}
@@ -29,7 +32,10 @@ export interface ICommandOptions {
2932
* @param config SPK Configuration
3033
* @param opts Command Line option values
3134
*/
32-
export const validateValues = (config: IConfigYaml, opts: ICommandOptions) => {
35+
export const validateValues = (
36+
config: ConfigYaml,
37+
opts: CommandOptions
38+
): void => {
3339
if (opts.port) {
3440
if (!isPortNumberString(opts.port)) {
3541
throw new Error("value for port option has to be a valid port number");
@@ -61,9 +67,9 @@ export const validateValues = (config: IConfigYaml, opts: ICommandOptions) => {
6167
* @param exitFn exit function
6268
*/
6369
export const execute = async (
64-
opts: ICommandOptions,
70+
opts: CommandOptions,
6571
exitFn: (status: number) => Promise<void>
66-
) => {
72+
): Promise<void> => {
6773
try {
6874
const config = Config();
6975
validateValues(config, opts);
@@ -84,7 +90,7 @@ export const execute = async (
8490
* @param command Commander command object to decorate
8591
*/
8692
export const commandDecorator = (command: commander.Command): void => {
87-
buildCmd(command, decorator).action(async (opts: ICommandOptions) => {
93+
buildCmd(command, decorator).action(async (opts: CommandOptions) => {
8894
await execute(opts, async (status: number) => {
8995
await exitCmd(logger, process.exit, status);
9096
});
@@ -94,7 +100,9 @@ export const commandDecorator = (command: commander.Command): void => {
94100
/**
95101
* Cleans previously launched spk dashboard docker containers
96102
*/
97-
export const cleanDashboarContainers = async (config: IConfigYaml) => {
103+
export const cleanDashboardContainers = async (
104+
config: ConfigYaml
105+
): Promise<void> => {
98106
let dockerOutput = await exec("docker", [
99107
"ps",
100108
"-a",
@@ -120,7 +128,7 @@ export const cleanDashboarContainers = async (config: IConfigYaml) => {
120128
* @param removeAll true to remove all previously launched instances of the dashboard
121129
*/
122130
export const launchDashboard = async (
123-
config: IConfigYaml,
131+
config: ConfigYaml,
124132
port: number,
125133
removeAll: boolean
126134
): Promise<string> => {
@@ -130,7 +138,7 @@ export const launchDashboard = async (
130138
}
131139

132140
if (removeAll) {
133-
await cleanDashboarContainers(config);
141+
await cleanDashboardContainers(config);
134142
}
135143

136144
const dockerRepository = config.introspection!.dashboard!.image!;
@@ -157,7 +165,7 @@ export const launchDashboard = async (
157165
* Creates and returns an array of env vars that need to be passed into the
158166
* docker run command
159167
*/
160-
export const getEnvVars = async (config: IConfigYaml): Promise<string[]> => {
168+
export const getEnvVars = async (config: ConfigYaml): Promise<string[]> => {
161169
const key = await config.introspection!.azure!.key;
162170
const envVars = [];
163171
envVars.push("-e");
@@ -236,8 +244,8 @@ export const getEnvVars = async (config: IConfigYaml): Promise<string[]> => {
236244
* information on dashboard
237245
*/
238246
export const extractManifestRepositoryInformation = (
239-
config: IConfigYaml
240-
): IIntrospectionManifest | undefined => {
247+
config: ConfigYaml
248+
): IntrospectionManifest | undefined => {
241249
const { azure_devops } = config;
242250
if (azure_devops!.manifest_repository) {
243251
const manifestRepoName = getRepositoryName(

Diff for: src/commands/deployment/get.test.ts

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
2+
/* eslint-disable @typescript-eslint/camelcase */
13
import path from "path";
24
import { duration, IDeployment, status } from "spektate/lib/IDeployment";
35
import * as Deployment from "spektate/lib/IDeployment";
4-
import { IAzureDevOpsRepo } from "spektate/lib/repository/IAzureDevOpsRepo";
56
import * as AzureDevOpsRepo from "spektate/lib/repository/IAzureDevOpsRepo";
6-
import { IGitHub } from "spektate/lib/repository/IGitHub";
77
import * as GitHub from "spektate/lib/repository/IGitHub";
88
import { ITag } from "spektate/lib/repository/Tag";
99
import { loadConfiguration } from "../../config";
@@ -18,10 +18,10 @@ import {
1818
getClusterSyncStatuses,
1919
getDeployments,
2020
getStatus,
21-
ICommandOptions,
22-
IInitObject,
21+
CommandOptions,
22+
InitObject,
2323
initialize,
24-
IValidatedOptions,
24+
ValidatedOptions,
2525
OUTPUT_FORMAT,
2626
printDeployments,
2727
processOutputFormat,
@@ -30,7 +30,7 @@ import {
3030
} from "./get";
3131
import * as get from "./get";
3232

33-
const MOCKED_INPUT_VALUES: ICommandOptions = {
33+
const MOCKED_INPUT_VALUES: CommandOptions = {
3434
buildId: "",
3535
commitId: "",
3636
deploymentId: "",
@@ -42,7 +42,7 @@ const MOCKED_INPUT_VALUES: ICommandOptions = {
4242
watch: false
4343
};
4444

45-
const MOCKED_VALUES: IValidatedOptions = {
45+
const MOCKED_VALUES: ValidatedOptions = {
4646
buildId: "",
4747
commitId: "",
4848
deploymentId: "",
@@ -56,18 +56,18 @@ const MOCKED_VALUES: IValidatedOptions = {
5656
watch: false
5757
};
5858

59-
const getMockedInputValues = (): ICommandOptions => {
59+
const getMockedInputValues = (): CommandOptions => {
6060
return deepClone(MOCKED_INPUT_VALUES);
6161
};
6262

63-
const getMockedValues = (): IValidatedOptions => {
63+
const getMockedValues = (): ValidatedOptions => {
6464
return deepClone(MOCKED_VALUES);
6565
};
6666

67-
// tslint:disable-next-line: no-var-requires
67+
// eslint-disable-next-line @typescript-eslint/no-var-requires
6868
const data = require("./mocks/data.json");
6969
const fakeDeployments = data;
70-
// tslint:disable-next-line: no-var-requires
70+
// eslint-disable-next-line @typescript-eslint/no-var-requires
7171
const fakeClusterSyncs = require("./mocks/cluster-sync.json");
7272
const mockedDeps: IDeployment[] = fakeDeployments.data.map(
7373
(dep: IDeployment) => {
@@ -97,7 +97,7 @@ jest
9797
.spyOn(AzureDevOpsRepo, "getManifestSyncState")
9898
.mockReturnValue(Promise.resolve(mockedClusterSyncs));
9999

100-
let initObject: IInitObject;
100+
let initObject: InitObject;
101101

102102
beforeAll(async () => {
103103
enableVerboseLogging();

0 commit comments

Comments
 (0)