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

Commit b160efe

Browse files
authored
[HOUSEKEEPING] resolve page wide no-non-null-assertion eslint-disable (#468)
* [HOUSEKEEPING] resolve page wide no-non-null-assertion eslint-disable * Update generate.test.ts * Update shell.ts
1 parent 9e4b663 commit b160efe

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

src/commands/infra/generate.test.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,11 @@ describe("fetch execute function", () => {
269269
jest
270270
.spyOn(generate, "validateDefinition")
271271
.mockReturnValueOnce(DefinitionYAMLExistence.PARENT_ONLY);
272-
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({});
272+
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({
273+
source: "",
274+
template: "",
275+
version: "",
276+
});
273277
jest.spyOn(generate, "validateRemoteSource").mockResolvedValueOnce();
274278
jest
275279
.spyOn(infraCommon, "getSourceFolderNameFromURL")
@@ -293,7 +297,11 @@ describe("fetch execute function", () => {
293297
.spyOn(generate, "validateDefinition")
294298
.mockReturnValueOnce(DefinitionYAMLExistence.BOTH_EXIST);
295299
jest.spyOn(generate, "validateRemoteSource").mockResolvedValueOnce();
296-
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({});
300+
jest.spyOn(generate, "validateTemplateSources").mockReturnValueOnce({
301+
source: "",
302+
template: "",
303+
version: "",
304+
});
297305
jest
298306
.spyOn(generate, "generateConfig")
299307
.mockReturnValueOnce(Promise.resolve());
@@ -324,6 +332,7 @@ describe("test validateRemoteSource function", () => {
324332

325333
await validateRemoteSource({
326334
source: "source",
335+
template: "",
327336
version: "0.1",
328337
});
329338
});
@@ -339,6 +348,7 @@ describe("test validateRemoteSource function", () => {
339348

340349
await validateRemoteSource({
341350
source: "source",
351+
template: "",
342352
version: "0.1",
343353
});
344354
});
@@ -354,6 +364,7 @@ describe("test validateRemoteSource function", () => {
354364

355365
await validateRemoteSource({
356366
source: "source",
367+
template: "",
357368
version: "0.1",
358369
});
359370
});
@@ -370,6 +381,7 @@ describe("test validateRemoteSource function", () => {
370381
try {
371382
await validateRemoteSource({
372383
source: "source",
384+
template: "",
373385
version: "0.1",
374386
});
375387
expect(true).toBe(false);

src/commands/infra/generate.ts

+25-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
21
/* eslint-disable @typescript-eslint/no-use-before-define */
32
import commander from "commander";
43
import fs from "fs";
@@ -31,9 +30,9 @@ interface CommandOptions {
3130
}
3231

3332
export interface SourceInformation {
34-
source?: string;
35-
template?: string;
36-
version?: string;
33+
source: string;
34+
template: string;
35+
version: string;
3736
}
3837

3938
export enum DefinitionYAMLExistence {
@@ -57,6 +56,8 @@ export const execute = async (
5756
parentPath,
5857
projectPath
5958
);
59+
// validateTemplateSources makes sure that
60+
// sourceConfig has values for source, template and version
6061
await validateRemoteSource(sourceConfig);
6162
await generateConfig(
6263
parentPath,
@@ -142,7 +143,11 @@ export const validateTemplateSources = (
142143
const sourceKeys = ["source", "template", "version"] as Array<
143144
keyof SourceInformation
144145
>;
145-
const source: SourceInformation = {};
146+
const source: SourceInformation = {
147+
source: "",
148+
template: "",
149+
version: "",
150+
};
146151
let parentInfraConfig: InfraConfigYaml;
147152
let leafInfraConfig: InfraConfigYaml;
148153

@@ -163,18 +168,18 @@ export const validateTemplateSources = (
163168
source[k] = parentInfraConfig[k];
164169
}
165170
});
166-
if (!source.source || !source.template || !source.version) {
167-
throw new Error(
168-
`The ${DEFINITION_YAML} file is invalid. \
169-
There is a missing field for it's sources. \
170-
Template: ${source.template} source: ${source.source} version: ${source.version}`
171+
if (source.source && source.template && source.version) {
172+
const safeLoggingUrl = safeGitUrlForLogging(source.source);
173+
logger.info(
174+
`Checking for locally stored template: ${source.template} from remote repository: ${safeLoggingUrl} at version: ${source.version}`
171175
);
176+
return source;
172177
}
173-
const safeLoggingUrl = safeGitUrlForLogging(source.source!);
174-
logger.info(
175-
`Checking for locally stored template: ${source.template} from remote repository: ${safeLoggingUrl} at version: ${source.version}`
178+
throw new Error(
179+
`The ${DEFINITION_YAML} file is invalid. \
180+
There is a missing field for it's sources. \
181+
Template: ${source.template} source: ${source.source} version: ${source.version}`
176182
);
177-
return source;
178183
};
179184

180185
export const checkRemoteGitExist = async (
@@ -226,8 +231,8 @@ export const gitCheckout = async (
226231
export const validateRemoteSource = async (
227232
sourceConfig: SourceInformation
228233
): Promise<void> => {
229-
const source = sourceConfig.source!;
230-
const version = sourceConfig.version!;
234+
const source = sourceConfig.source;
235+
const version = sourceConfig.version;
231236

232237
// Converting source name to storable folder name
233238
const sourceFolder = getSourceFolderNameFromURL(source);
@@ -378,11 +383,11 @@ export const generateConfig = async (
378383
outputPath: string
379384
): Promise<void> => {
380385
const parentDirectory = getParentGeneratedFolder(parentPath, outputPath);
381-
const sourceFolder = getSourceFolderNameFromURL(sourceConfig.source!);
386+
const sourceFolder = getSourceFolderNameFromURL(sourceConfig.source);
382387
const templatePath = path.join(
383388
spkTemplatesPath,
384389
sourceFolder,
385-
sourceConfig.template!
390+
sourceConfig.template
386391
);
387392
const childDirectory =
388393
projectPath === parentPath
@@ -405,7 +410,9 @@ export const generateConfig = async (
405410
}
406411

407412
combineVariable(
413+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
408414
parentInfraConfig.variables!,
415+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
409416
leafInfraConfig.variables!,
410417
childDirectory,
411418
SPK_TFVARS

src/lib/shell.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/camelcase */
21
import child_process from "child_process";
32
import { logger } from "../logger";
43

0 commit comments

Comments
 (0)