Skip to content

Commit

Permalink
Add lint rules (#202)
Browse files Browse the repository at this point in the history
* Fixed duplicate build:agent in build command

* Added additional lint spacing rules

* Fixed common, agent, and controller code for the new lint rules

* Added spacing and no-shadow lint rules to the guide results viewer

* Fixed lint issues in the guide

- Fixed no-shadow issues to match the version from the controller
  • Loading branch information
tkmcmaster authored Mar 14, 2024
1 parent 1e4f257 commit 898b234
Show file tree
Hide file tree
Showing 47 changed files with 322 additions and 297 deletions.
2 changes: 2 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
"space-before-function-paren": 1,
"spaced-comment": ["error", "always", { "block": { "balanced": true } }],
"space-infix-ops":"warn",
"space-before-blocks": "warn",
"keyword-spacing": "warn",
"strict": 1,
"comma-dangle": 1,
"triple-equals": 0,
Expand Down
2 changes: 1 addition & 1 deletion agent/acceptance/tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Tests Integration", () => {
done(new Error("Should have returned a 404"));
}).catch((error: unknown) => {
log(integrationUrl + "/tests/ error", LogLevel.DEBUG, error, { status: (error as AxiosError)?.response?.status });
if ((error as AxiosError)?.response?.status === 404){
if ((error as AxiosError)?.response?.status === 404) {
done();
} else {
done(error);
Expand Down
2 changes: 1 addition & 1 deletion agent/createtest/pewpewtest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe("PewPewTest Create Test", () => {
await test!.launch();
// Should have thrown
done(new Error("test.launch() should have failed with pewpew exited with kill"));
} catch(error) {
} catch (error) {
// Kill should throw
log("'Retrieve Test and launch, then kill should succeed' result", LogLevel.DEBUG, error);
try {
Expand Down
2 changes: 1 addition & 1 deletion agent/src/healthcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function pingS3 (): Promise<boolean> {
config.lastS3Access = new Date();
log("Pinging S3 succeeded at " + new Date(), LogLevel.DEBUG);
return true;
} catch(error) {
} catch (error) {
log("pingS3 failed}", LogLevel.ERROR, error);
// DO NOT REJECT. Just return false
return false;
Expand Down
16 changes: 8 additions & 8 deletions agent/src/pewpewtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ export class PewPewTest {
protected async writeTestStatus () {
try {
await this.ppaasTestStatus.writeStatus();
} catch(error) {
} catch (error) {
this.log("Could not write ppaasTestStatus", LogLevel.ERROR, error, { ppaasTestStatus: this.ppaasTestStatus });
}
}
Expand All @@ -316,7 +316,7 @@ export class PewPewTest {
const { testId } = this.testMessage;
const messageId = await new PpaasCommunicationsMessage({ testId, messageType, messageData }).send();
this.log(`Sent testStatus ${messageType}: " ${messageId}`, LogLevel.DEBUG, { messageData, messageId });
} catch(error) {
} catch (error) {
this.log("Could not send TestStatus", LogLevel.ERROR, error, { messageData });
}
}
Expand All @@ -325,7 +325,7 @@ export class PewPewTest {
try {
const messageId = await refreshTestScalingMessage();
this.log(`Sent refreshTestScalingMessage: " ${messageId}`, LogLevel.DEBUG, { messageId });
} catch(error) {
} catch (error) {
this.log("Error calling refreshTestScalingMessage", LogLevel.ERROR, error);
}
}
Expand All @@ -334,7 +334,7 @@ export class PewPewTest {
try {
const messageId = await deleteTestScalingMessage();
this.log(`deleteTestScalingMessage: " ${messageId}`, LogLevel.DEBUG, { messageId });
} catch(error) {
} catch (error) {
this.log("Error calling deleteTestScalingMessage", LogLevel.ERROR, error);
}
}
Expand Down Expand Up @@ -594,7 +594,7 @@ export class PewPewTest {
this.log(errorMessage, LogLevel.ERROR, error);
try {
await this.internalStop();
} catch(err) {
} catch (err) {
this.log("Could not stop the pewpew process", LogLevel.ERROR, err);
}
// Send failed communications message and update teststatus
Expand Down Expand Up @@ -758,7 +758,7 @@ export class PewPewTest {
await this.sendTestStatus();
// Keep alive every loop
await this.refreshTestScalingMessage();
} catch(error) {
} catch (error) {
this.log(`Polling PewPew Results Error. iteration: ${iteration}`, LogLevel.ERROR, error);
}
if (Date.now() < endLoop) {
Expand Down Expand Up @@ -915,7 +915,7 @@ export class PewPewTest {
this.writeTestStatus(),
this.internalStop()
]);
} catch(err) {
} catch (err) {
this.log("Could not stop the pewpew process", LogLevel.ERROR, err);
}
// Keep trying to check and kill the pewpew process?
Expand All @@ -928,7 +928,7 @@ export class PewPewTest {
if (this.pewpewRunning) {
await sleep(10000);
}
} catch(err) {
} catch (err) {
this.log("Could not stop the pewpew process", LogLevel.ERROR, err);
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/integration/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ describe("S3Util Integration", () => {
const objects = await listObjects(s3FileKey!);
return (objects && objects.Contents && objects.Contents.length > 0);
}, MAX_POLL_WAIT, (errMsg: string) => `${errMsg} Could not find the ${s3FileKey} in s3`);
} catch(error) {
} catch (error) {
log(`beforeEach error uploadFile(${UNIT_TEST_FILEPATH}, ${UNIT_TEST_KEY_PREFIX})`, LogLevel.ERROR, error);
throw error;
}
Expand Down Expand Up @@ -416,7 +416,7 @@ describe("S3Util Integration", () => {

afterEach (async () => {
// Delete the local file
if(localFile) {
if (localFile) {
await fs.unlink(localFile)
.catch((error) => log("Could not delete " + localFile, LogLevel.WARN, error));
}
Expand Down
6 changes: 3 additions & 3 deletions common/integration/s3file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe("PpaasS3File Integration", () => {
testPpaasS3FileUpload.setLastModifiedLocal(0);
testPpaasS3FileUpload.remoteUrl = "";
// As long as we don't throw, it passes
} catch(error) {
} catch (error) {
throw error;
}
});
Expand Down Expand Up @@ -238,7 +238,7 @@ describe("PpaasS3File Integration", () => {
log("testPpaasS3FileUpload.upload() succeeded", LogLevel.DEBUG);
s3FileKey = testPpaasS3FileUpload.key;
// As long as we don't throw, it passes
} catch(error) {
} catch (error) {
throw error;
}
});
Expand Down Expand Up @@ -361,7 +361,7 @@ describe("PpaasS3File Integration", () => {

afterEach (async () => {
// Delete the local file
if(localFile) {
if (localFile) {
await fs.unlink(localFile)
.catch((error) => log("Could not delete " + localFile, LogLevel.WARN, error));
}
Expand Down
2 changes: 1 addition & 1 deletion common/src/ppaascommessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class PpaasCommunicationsMessage implements CommunicationsMessage {
continue;
} else if (value.DataType === "String") { // "Number" also is stored as StringValue
log(`messageAttributes[${key}].StringValue = ${value.StringValue}`, LogLevel.DEBUG);
switch(key) {
switch (key) {
// If this is set, it isn't a real message and should be swallowed. It was from an integration test
case "UnitTestMessage":
unittestMessage = true;
Expand Down
2 changes: 1 addition & 1 deletion common/src/ppaastestmessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class PpaasTestMessage implements TestMessage {
continue;
} else if (value.DataType === "String") {
log(`messageAttributes[${key}].StringValue = ${value.StringValue}`, LogLevel.DEBUG);
switch(key) {
switch (key) {
// If this is set, it isn't a real message and should be swallowed. It was from an integration test
case "UnitTestMessage":
unittestMessage = true;
Expand Down
2 changes: 1 addition & 1 deletion common/test/ppaasteststatus.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe("PpaasTestStatus", () => {
// should have all the TestStatus + lastModifiedRemote && testId && url
expect(Object.keys(actualTestMessage).length, `Actual Keys: ${Object.keys(actualTestMessage).toString()}\nExpected Keys: ${Object.keys(testStatus).toString()}\nMessage keys length`).to.equal(Object.keys(testStatus).length + 3);
for (const key in actualTestMessage) {
switch(key) {
switch (key) {
case "lastModifiedRemote":
expect(JSON.stringify(actualTestMessage.lastModifiedRemote), key).to.equal(JSON.stringify(new Date(0)));
break;
Expand Down
2 changes: 1 addition & 1 deletion common/test/s3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe("S3Util", () => {

afterEach (async () => {
// Delete the local file
if(localFile) {
if (localFile) {
await fs.unlink(localFile)
.catch((error) => log("Could not delete " + localFile, LogLevel.WARN, error));
}
Expand Down
4 changes: 2 additions & 2 deletions common/test/s3file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ describe("PpaasS3File", () => {
testPpaasS3FileUpload.setLastModifiedLocal(0);
testPpaasS3FileUpload.remoteUrl = "";
// As long as we don't throw, it passes
} catch(error) {
} catch (error) {
throw error;
}
});
Expand Down Expand Up @@ -564,7 +564,7 @@ describe("PpaasS3File", () => {

afterEach (async () => {
// Delete the local file
if(localFile) {
if (localFile) {
await fs.unlink(localFile)
.catch((error) => log("Could not delete " + localFile, LogLevel.WARN, error));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/components/Calendar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const PPaaSCalendar = ({ ...calendarProps}: CalendarProps) => {
// It has to be client rendered so we get the local browser time zone
if (Array.isArray(calendarProps.events)) {
for (const event of calendarProps.events) {
if(typeof event.startRecur === "number") {
if (typeof event.startRecur === "number") {
event.startTime = getHourMinuteFromTimestamp(event.startRecur);
event.endTime = typeof event.testRunTimeMn === "number"
? getHourMinuteFromTimestamp(event.startRecur + (60000 * event.testRunTimeMn))
Expand Down
2 changes: 1 addition & 1 deletion controller/components/StartTestForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export const StartTestForm = ({
({ ...prevState, environmentVariables: [...environmentVariables, ...newEnvironmentVariables] })
);
}
} catch(error) {
} catch (error) {
log(`Could not parse file: ${file.name}`, LogLevel.ERROR, error);
setState({ error: `Could not parse file: ${file.name} - ${formatError(error)}` });
}
Expand Down
2 changes: 1 addition & 1 deletion controller/components/TestResults/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ const afterBuildTicks = (chart: any) => {
let lastLegendClick: [number, number, Chart] | undefined;

Chart.defaults.plugins.legend.onClick = function (
e: ChartEvent,
_e: ChartEvent,
legendItem: LegendItem,
legend: LegendElement<keyof ChartTypeRegistry>
) {
Expand Down
2 changes: 1 addition & 1 deletion controller/integration/ppaasencryptenvfile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ describe("PpaasEncryptEnvironmentFile Integration", () => {
log("testPpaasEncryptEnvironmentFileUpload.upload() succeeded", LogLevel.DEBUG);
s3FileKey = testPpaasEncryptEnvironmentFileUpload.key;
// As long as we don't throw, it passes
} catch(error) {
} catch (error) {
throw error;
}
});
Expand Down
2 changes: 1 addition & 1 deletion controller/integration/ppaasencrypts3file.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe("PpaasEncryptS3File Integration", () => {
log("testPpaasEncryptS3FileUpload.upload() succeeded", LogLevel.DEBUG);
s3FileKey = testPpaasEncryptS3FileUpload.key;
// As long as we don't throw, it passes
} catch(error) {
} catch (error) {
throw error;
}
});
Expand Down
2 changes: 1 addition & 1 deletion controller/integration/testmanager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ describe("TestManager Integration", () => {
expect(Array.isArray(tests.recentTests)).to.equal(true);
// Requested should have at least one now
expect(tests.runningTests.length + tests.recentTests.length, "tests.runningTests.length + tests.recentTests.length").to.be.greaterThan(0);
} catch(error) {
} catch (error) {
log("afterEach error", LogLevel.ERROR, error);
throw error;
}
Expand Down
4 changes: 2 additions & 2 deletions controller/pages/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async (req: NextApiRequest, res: NextApiResponse): Promise<void>
log(`${req.method} ${req.url} response: ${JSON.stringify(authPermissions)}`, LogLevel.DEBUG);
res.status(200).json(authPermissions);
} else if (req.query.refreshToken && !Array.isArray(req.query.refreshToken)) {
try{
try {
const tokenResponse: TokenResponse = await getTokenFromRefreshToken(req.query.refreshToken);
log(`${req.method} ${req.url} returning token: ${JSON.stringify(tokenResponse)}`);
res.status(200).json(tokenResponse);
Expand All @@ -34,7 +34,7 @@ export default async (req: NextApiRequest, res: NextApiResponse): Promise<void>
} else {
res.status(400).json({ message: `method ${req.method} must have a code or token queryparam` });
}
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error, LogLevel.ERROR));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default async (request: NextApiRequest, response: NextApiResponse<GetObje
} else {
response.status(400).json({ message: `method ${request.method} must have an yamlFile and dateString` });
}
} catch(error) {
} catch (error) {
log(`${request.method} ${request.url} failed: ${error}`, LogLevel.ERROR, error);
response.status(500).json(createErrorResponse(request, error));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default async (req: NextApiRequest, res: NextApiResponse<GetObjectCommand
} else {
res.status(400).json({ message: `method ${req.method} must have a json file` });
}
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async (req: NextApiRequest, res: NextApiResponse): Promise<void>
const authUrl: string = await getAuthUrl(req);
log(`${req.method} ${req.url} authUrl response: ${authUrl}`, LogLevel.DEBUG);
res.redirect(302, authUrl);
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error, LogLevel.ERROR));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default async (req: NextApiRequest, res: NextApiResponse): Promise<void>
const logoutUrl: string = await getLogoutUrl(req);
log(`${req.method} ${req.url} logoutUrl response: ${logoutUrl}`, LogLevel.DEBUG);
res.redirect(302, logoutUrl);
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error, LogLevel.ERROR));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/queuenames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default (req: NextApiRequest, res: NextApiResponse): void => {
try {
const queueNames: string[] = PpaasTestMessage.getAvailableQueueNames();
res.status(200).json({ queueNames });
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/queues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default (req: NextApiRequest, res: NextApiResponse): void => {
try {
const queues: AgentQueueDescription = PpaasTestMessage.getAvailableQueueMap();
res.status(200).json(queues);
} catch(error) {
} catch (error) {
log(`${req.method} ${req.url} failed: ${error}`, LogLevel.ERROR, error);
res.status(500).json(createErrorResponse(req, error));
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/util/clientutil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function formatError (error: unknown): string {
const methodText = `${axiosError.config?.method?.toUpperCase() || ""} ${axiosError.config?.url || "request"} failed`;
if (axiosError.response) {
let errorText: string;
if (typeof axiosError.response.data === "string"){
if (typeof axiosError.response.data === "string") {
// It's a string
errorText = axiosError.response.data;
} else if (typeof (axiosError.response.data as TestManagerError)?.message === "string") {
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/util/healthcheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export async function pingS3 (): Promise<boolean> {
await listObjects({ prefix: "ping", maxKeys: 1 }); // Limit 1 so we can get back fast
log("Pinging S3 succeeded at " + new Date(), LogLevel.DEBUG);
return true;
} catch(error) {
} catch (error) {
log("pingS3 failed", LogLevel.ERROR, error);
// DO NOT REJECT. Just return false
return false;
Expand Down
6 changes: 3 additions & 3 deletions controller/pages/api/util/testmanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ export async function validateYamlfile (
dummyEnvironmentVariables[splunkPath] = dummySplunkPath;
}
yamlParser = await YamlParser.parseYamlFile(yamlFile.filepath, dummyEnvironmentVariables);
} catch(error) {
} catch (error) {
return { json: { message: `yamlFile: ${yamlFile.originalFilename || yamlFile.filepath} failed to parse`, error: formatError(error) }, status: 400 };
}

Expand Down Expand Up @@ -1141,7 +1141,7 @@ export abstract class TestManager {
}
}
log("parsed environmentVariables", LogLevel.DEBUG, Object.keys(environmentVariablesFile));
} catch(error) {
} catch (error) {
log("Could not parse environmentVariables", LogLevel.TRACE, error, fields.environmentVariables);
// Don't log the actual error or environmentVariables since it could include passwords
return { json: { message: "Could not parse environmentVariables", error: formatError(error) }, status: 400 };
Expand Down Expand Up @@ -1541,7 +1541,7 @@ export abstract class TestManager {
}
try {
await YamlParser.parseYamlFile(yamlFile.filepath, environmentVariables);
} catch(error) {
} catch (error) {
return { json: { message: `yamlFile: ${yamlFile.originalFilename || yamlFile.filepath} failed to parse`, error: formatError(error) }, status: 400 };
}
}
Expand Down
2 changes: 1 addition & 1 deletion controller/pages/api/util/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export async function parseZip (formFiles: Files): Promise<void> {
formFiles.yamlFile = yamlFiles.length > 1 ? yamlFiles : yamlFiles[0];
}
// return formFiles;
} catch(error: any) {
} catch (error: any) {
log ("Error parsing files in incoming test form files for zips: " + (error?.msg || error?.message || `${error}`), LogLevel.WARN, error);
if (error instanceof Error && error.stack) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default async (request: NextApiRequest, response: NextApiResponse<GetObje
} else {
response.status(400).json({ message: `method ${request.method} must have a yaml file` });
}
} catch(error) {
} catch (error) {
log(`${request.method} ${request.url} failed: ${error}`, LogLevel.ERROR, error);
response.status(500).json(createErrorResponse(request, error));
}
Expand Down
Loading

0 comments on commit 898b234

Please sign in to comment.