Skip to content

Commit

Permalink
Running prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
muiriswoulfe committed Sep 5, 2024
1 parent 811dd0b commit fbefe2d
Show file tree
Hide file tree
Showing 14 changed files with 775 additions and 763 deletions.
640 changes: 321 additions & 319 deletions eslint.config.mjs

Large diffs are not rendered by default.

31 changes: 18 additions & 13 deletions src/task/src/metrics/codeMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,13 +392,17 @@ export default class CodeMetrics {

// Condense file and folder names that were renamed, e.g., "F{a => i}leT{b => e}st.d{c => l}l" or "FaleTbst.dcl => FileTest.dll".
const fileName: string = elements[2]
.replace(/\{.*? => (?<newName>[^}]+?)\}/gu, '$<newName>')
.replace(/.*? => (?<newName>[^}]+?)/gu, '$<newName>')
.replace(/\{.*? => (?<newName>[^}]+?)\}/gu, "$<newName>")
.replace(/.*? => (?<newName>[^}]+?)/gu, "$<newName>");

result.push({
fileName,
linesAdded: CodeMetrics.parseChangedLines(elements[0], line, "added"),
linesDeleted: CodeMetrics.parseChangedLines(elements[1], line, "deleted"),
linesDeleted: CodeMetrics.parseChangedLines(
elements[1],
line,
"deleted",
),
});
}

Expand Down Expand Up @@ -451,16 +455,17 @@ export default class CodeMetrics {
const indexXL = 4;
const size = 5;

const indicators: FixedLengthArrayInterface<(prefix: string) => string, typeof size> =
[
(): string =>
this._runnerInvoker.loc("metrics.codeMetrics.titleSizeXS"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeS"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeM"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeL"),
(prefix: string): string =>
this._runnerInvoker.loc("metrics.codeMetrics.titleSizeXL", prefix),
];
const indicators: FixedLengthArrayInterface<
(prefix: string) => string,
typeof size
> = [
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeXS"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeS"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeM"),
(): string => this._runnerInvoker.loc("metrics.codeMetrics.titleSizeL"),
(prefix: string): string =>
this._runnerInvoker.loc("metrics.codeMetrics.titleSizeXL", prefix),
];

// Calculate the smaller size.
if (this._metrics.productCode < this._inputs.baseSize) {
Expand Down
5 changes: 4 additions & 1 deletion src/task/src/metrics/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ export default class Inputs {
): void {
this._logger.logDebug("* Inputs.initializeCodeFileExtensions()");

if (typeof codeFileExtensions !== "undefined" && codeFileExtensions.trim() !== "") {
if (
typeof codeFileExtensions !== "undefined" &&
codeFileExtensions.trim() !== ""
) {
const wildcardStart = "*.";
const periodStart = ".";

Expand Down
11 changes: 8 additions & 3 deletions src/task/src/pullRequests/pullRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ export default class PullRequest {
): string | null {
this._logger.logDebug("* PullRequest.getUpdatedDescription()");

if (typeof currentDescription !== "undefined" && currentDescription.trim() !== "") {
if (
typeof currentDescription !== "undefined" &&
currentDescription.trim() !== ""
) {
return null;
}

Expand Down Expand Up @@ -129,8 +132,10 @@ export default class PullRequest {
const completeRegExp = `^${this._runnerInvoker.loc("pullRequests.pullRequest.titleFormat", sizeIndicatorRegExp, "(?<originalTitle>.*)")}$`;

const prefixRegExp = new RegExp(completeRegExp, "u");
const prefixRegExpMatches: RegExpMatchArray | null = currentTitle.match(prefixRegExp);
const originalTitle: string = prefixRegExpMatches?.groups?.originalTitle ?? currentTitle;
const prefixRegExpMatches: RegExpMatchArray | null =
currentTitle.match(prefixRegExp);
const originalTitle: string =
prefixRegExpMatches?.groups?.originalTitle ?? currentTitle;
return this._runnerInvoker.loc(
"pullRequests.pullRequest.titleFormat",
sizeIndicator,
Expand Down
45 changes: 27 additions & 18 deletions src/task/src/repos/gitHubReposInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
}

public async createComment(
content: string,
fileName: string | null,
content: string,
fileName: string | null,
): Promise<void> {
this._logger.logDebug("* GitHubReposInvoker.createComment()");

Expand Down Expand Up @@ -275,14 +275,18 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
const options: OctokitOptions = {
auth: process.env.PR_METRICS_ACCESS_TOKEN,
log: {
debug: (message: string): void =>
{ this._logger.logDebug(`Octokit – ${message}`); },
error: (message: string): void =>
{ this._logger.logError(`Octokit – ${message}`); },
info: (message: string): void =>
{ this._logger.logInfo(`Octokit – ${message}`); },
warn: (message: string): void =>
{ this._logger.logWarning(`Octokit – ${message}`); },
debug: (message: string): void => {
this._logger.logDebug(`Octokit – ${message}`);
},
error: (message: string): void => {
this._logger.logError(`Octokit – ${message}`);
},
info: (message: string): void => {
this._logger.logInfo(`Octokit – ${message}`);
},
warn: (message: string): void => {
this._logger.logWarning(`Octokit – ${message}`);
},
},
userAgent: "PRMetrics/v1.6.1",
};
Expand Down Expand Up @@ -324,7 +328,7 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
);
}

[, this._repo] = gitHubRepositoryElements
[, this._repo] = gitHubRepositoryElements;
return baseUrl;
}

Expand All @@ -348,15 +352,18 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
}

// Handle GitHub Enterprise invocations.
let baseUrl: string
[, , baseUrl, this._owner, this._repo] = sourceRepositoryUriElements
if (baseUrl !== 'github.com') {
baseUrl = `https://${baseUrl}/api/v3`
let baseUrl: string;
[, , baseUrl, this._owner, this._repo] = sourceRepositoryUriElements;
if (baseUrl !== "github.com") {
baseUrl = `https://${baseUrl}/api/v3`;
}

const gitEnding = '.git'
const gitEnding = ".git";
if (this._repo.endsWith(gitEnding)) {
this._repo = this._repo.substring(0, this._repo.length - gitEnding.length)
this._repo = this._repo.substring(
0,
this._repo.length - gitEnding.length,
);
}

return baseUrl;
Expand Down Expand Up @@ -413,7 +420,9 @@ export default class GitHubReposInvoker extends BaseReposInvoker {
if (typeof result.headers.link !== "undefined") {
const commitsLink: string = result.headers.link;
const matches: RegExpMatchArray | null =
/<.+>; rel="next", <.+?page=(?<pageNumber>\d+)>; rel="last"/u.exec(commitsLink);
/<.+>; rel="next", <.+?page=(?<pageNumber>\d+)>; rel="last"/u.exec(
commitsLink,
);
if (typeof matches?.groups?.pageNumber === "undefined") {
throw new Error(
`The regular expression did not match '${commitsLink}'.`,
Expand Down
2 changes: 1 addition & 1 deletion src/task/src/utilities/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class Logger {
* @param error The error object to log.
*/
public logErrorObject(error: Error): void {
const {name} = error;
const { name } = error;
const properties: string[] = Object.getOwnPropertyNames(error);
const errorRecord: Record<string, unknown> = error as unknown as Record<
string,
Expand Down
7 changes: 6 additions & 1 deletion src/task/src/utilities/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ export const validateNumber = (
valueName: string,
methodName: string,
): number => {
if (value === null || typeof value === "undefined" || value === 0 || isNaN(value)) {
if (
value === null ||
typeof value === "undefined" ||
value === 0 ||
isNaN(value)
) {
throw new TypeError(
`'${valueName}', accessed within '${methodName}', is invalid, null, or undefined '${Converter.toString(value)}'.`,
);
Expand Down
6 changes: 5 additions & 1 deletion src/task/tests/metrics/codeMetricsCalculator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,11 @@ describe("codeMetricsCalculator.ts", (): void => {
logger.logDebug("* CodeMetricsCalculator.updateMetricsComment()"),
).once();
verify(
reposInvoker.createComment("Description", null, CommentThreadStatus.Active),
reposInvoker.createComment(
"Description",
null,
CommentThreadStatus.Active,
),
).once();
});

Expand Down
3 changes: 2 additions & 1 deletion src/task/tests/metrics/codeMetricsData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ describe("codeMetricsData.ts", (): void => {
const codeMetricsData: CodeMetricsData = new CodeMetricsData(1, 2, 4);

// Act
const { productCode, testCode, subtotal, ignoredCode, total } = codeMetricsData;
const { productCode, testCode, subtotal, ignoredCode, total } =
codeMetricsData;

// Assert
assert.equal(productCode, 1);
Expand Down
7 changes: 6 additions & 1 deletion src/task/tests/repos/azureReposInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import "reflect-metadata";
import * as AssertExtensions from "../testUtilities/assertExtensions";
import * as Converter from "../../src/utilities/converter";
import { type Comment, CommentThreadStatus, type GitPullRequest, type GitPullRequestCommentThread } from 'azure-devops-node-api/interfaces/GitInterfaces'
import {
type Comment,
CommentThreadStatus,
type GitPullRequest,
type GitPullRequestCommentThread,
} from "azure-devops-node-api/interfaces/GitInterfaces";
import { any, anyNumber } from "../testUtilities/mockito";
import { deepEqual, instance, mock, verify, when } from "ts-mockito";
import AzureDevOpsApiWrapper from "../../src/wrappers/azureDevOpsApiWrapper";
Expand Down
50 changes: 10 additions & 40 deletions src/task/tests/repos/gitHubReposInvoker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1246,10 +1246,7 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down Expand Up @@ -1310,10 +1307,7 @@ describe("gitHubReposInvoker.ts", (): void => {

// Act
const func: () => Promise<void> = async () =>
gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
await AssertExtensions.toThrowAsync(
Expand Down Expand Up @@ -1366,10 +1360,7 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down Expand Up @@ -1427,10 +1418,7 @@ describe("gitHubReposInvoker.ts", (): void => {

// Act
const func: () => Promise<void> = async () =>
gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
await AssertExtensions.toThrowAsync(
Expand Down Expand Up @@ -1470,14 +1458,8 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment("Content", "file.ts");
await gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down Expand Up @@ -1534,10 +1516,7 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down Expand Up @@ -1600,10 +1579,7 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
await gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down Expand Up @@ -1678,10 +1654,7 @@ describe("gitHubReposInvoker.ts", (): void => {

// Act
const func: () => Promise<void> = async () =>
gitHubReposInvoker.createComment(
"Content",
"file.ts",
);
gitHubReposInvoker.createComment("Content", "file.ts");

// Assert
await AssertExtensions.toThrowAsync(func, error.message);
Expand Down Expand Up @@ -1732,10 +1705,7 @@ describe("gitHubReposInvoker.ts", (): void => {
);

// Act
await gitHubReposInvoker.createComment(
"Content",
null,
);
await gitHubReposInvoker.createComment("Content", null);

// Assert
verify(octokitWrapper.initialize(any())).once();
Expand Down
Loading

0 comments on commit fbefe2d

Please sign in to comment.