Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

L✔ ◾ Enhancing linting #537

Merged
merged 73 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 66 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
1429fa2
Updating list
muiriswoulfe Aug 15, 2024
8242d09
Updating linting
muiriswoulfe Aug 16, 2024
8d6b710
Clarifying suppressions
muiriswoulfe Aug 16, 2024
5d676c4
Removing unused file
muiriswoulfe Aug 16, 2024
dd9938c
@typescript-eslint/no-floating-promises
muiriswoulfe Aug 16, 2024
d3971f5
@typescript-eslint/no-empty-function
muiriswoulfe Aug 16, 2024
0aab9a2
@typescript-eslint/no-unsafe-return
muiriswoulfe Aug 16, 2024
918a806
@typescript-eslint/require-await
muiriswoulfe Aug 16, 2024
589e03e
@typescript-eslint/no-unnecessary-type-assertion
muiriswoulfe Aug 16, 2024
100c687
@typescript-eslint/consistent-indexed-object-style
muiriswoulfe Aug 16, 2024
1b14c96
Arranging suppressions
muiriswoulfe Aug 16, 2024
6742879
Arranging suppressions
muiriswoulfe Aug 16, 2024
4e778b2
@typescript-eslint/no-non-null-asserted-optional-chain
muiriswoulfe Aug 19, 2024
5b1892d
@typescript-eslint/no-unsafe-call
muiriswoulfe Aug 19, 2024
67f3558
@typescript-eslint/no-inferrable-types
muiriswoulfe Aug 19, 2024
208e8c4
@typescript-eslint/no-unnecessary-type-parameters
muiriswoulfe Aug 19, 2024
bb65d0b
@typescript-eslint/no-redundant-type-constituents
muiriswoulfe Aug 19, 2024
31d55bb
@typescript-eslint/no-non-null-assertion
muiriswoulfe Aug 19, 2024
2327fdc
@typescript-eslint/no-unused-vars partial
muiriswoulfe Aug 19, 2024
174475b
@typescript-eslint/no-unused-vars partial
muiriswoulfe Aug 19, 2024
a087d96
@typescript-eslint/no-unsafe-call
muiriswoulfe Aug 22, 2024
1c99564
@typescript-eslint/no-unnecessary-condition
muiriswoulfe Aug 22, 2024
ef8279e
@typescript-eslint/no-unsafe-assignment partial
muiriswoulfe Aug 22, 2024
1099c4b
@typescript-eslint/no-unsafe-assignment partial
muiriswoulfe Aug 22, 2024
5ddb268
@typescript-eslint/no-unsafe-assignment
muiriswoulfe Aug 23, 2024
0e9bb13
Renaming constants
muiriswoulfe Aug 23, 2024
3996ce0
@typescript-eslint/restrict-template-expressions
muiriswoulfe Aug 26, 2024
9a50680
@typescript-eslint/no-unsafe-argument partial
muiriswoulfe Aug 26, 2024
1ef1efb
@typescript-eslint/no-unsafe-argument partial
muiriswoulfe Aug 27, 2024
165536e
@typescript-eslint/no-unsafe-argument
muiriswoulfe Aug 28, 2024
3d8dfe6
Renaming interfaces
muiriswoulfe Aug 28, 2024
b74f110
toString to String
muiriswoulfe Aug 29, 2024
018dade
@typescript-eslint/no-unsafe-argument
muiriswoulfe Aug 29, 2024
86a0c9e
foreach to for
muiriswoulfe Aug 29, 2024
1b56835
foreach to for completed
muiriswoulfe Aug 29, 2024
576634f
Formatting improvements
muiriswoulfe Aug 29, 2024
5b3c6d9
@typescript-eslint/no-unsafe-member-access starting
muiriswoulfe Aug 29, 2024
acfc5f5
@typescript-eslint/no-unsafe-member-access partial
muiriswoulfe Aug 30, 2024
b606350
@typescript-eslint/no-unsafe-member-access
muiriswoulfe Aug 30, 2024
4294577
Merging main into branch
muiriswoulfe Sep 2, 2024
dc161a2
Applying linting
muiriswoulfe Sep 2, 2024
d459042
@typescript-eslint/no-explicit-any
muiriswoulfe Sep 2, 2024
a9b6c4c
@typescript-eslint/no-confusing-void-expression partial
muiriswoulfe Sep 2, 2024
0d0375b
Refining config
muiriswoulfe Sep 2, 2024
4cfb322
Refining config
muiriswoulfe Sep 2, 2024
6de8119
prefer-named-capture-group
muiriswoulfe Sep 3, 2024
29bd789
@typescript-eslint/no-unused-vars
muiriswoulfe Sep 3, 2024
028e51b
@typescript-eslint/no-unused-vars
muiriswoulfe Sep 3, 2024
6d8ed75
@typescript-eslint/consistent-type-imports
muiriswoulfe Sep 3, 2024
f690391
@typescript-eslint/strict-boolean-expressions
muiriswoulfe Sep 3, 2024
4f9c6b3
Updating linting
muiriswoulfe Sep 3, 2024
17844bf
Resolution
muiriswoulfe Sep 3, 2024
8008673
@typescript-eslint/naming-convention
muiriswoulfe Sep 4, 2024
a501701
Linting
muiriswoulfe Sep 4, 2024
046f2ff
Linting
muiriswoulfe Sep 4, 2024
e383748
no-negated-condition
muiriswoulfe Sep 4, 2024
fa08f77
no-ternary
muiriswoulfe Sep 4, 2024
f0c32c3
no-undefined partial
muiriswoulfe Sep 4, 2024
2558af8
no-undef
muiriswoulfe Sep 5, 2024
360f856
Updating linting
muiriswoulfe Sep 5, 2024
ac1f52e
sort-keys
muiriswoulfe Sep 5, 2024
802e543
Linting
muiriswoulfe Sep 5, 2024
ddb33a8
no-magic-numbers
muiriswoulfe Sep 5, 2024
572fb6c
@typescript-eslint/member-ordering
muiriswoulfe Sep 5, 2024
811dd0b
Finalising linting design
muiriswoulfe Sep 5, 2024
fbefe2d
Running prettier
muiriswoulfe Sep 5, 2024
d3d623f
Fixing linting, Updating dist folder
github-actions[bot] Sep 5, 2024
69e7d71
Reverting change for official linter
muiriswoulfe Sep 5, 2024
4d7c806
Regenerating files
muiriswoulfe Sep 5, 2024
fba1f43
Forcing rebuild
muiriswoulfe Sep 5, 2024
672e29d
Forcing rebuild
muiriswoulfe Sep 5, 2024
b99859c
Fixing build issue
muiriswoulfe Sep 5, 2024
ddd7e93
Fixing linting, Updating dist folder
github-actions[bot] Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
391 changes: 332 additions & 59 deletions eslint.config.mjs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build": "npm run build:release && npm run build:package && npm run build:docs",
"clean": "rimraf debug && rimraf release",
"deploy": "npm run build:release && exitzero tfx build tasks delete --task-id 907d3b28-6b37-4ac7-ac75-9631ee53e512 --no-prompt && tfx build tasks upload --task-path release/task --no-prompt",
"lint": "eslint --fix",
"lint": "eslint --fix **/*.ts",
"test": "npm run build:debug && cd debug/task && c8 --reporter=text --reporter=text-summary mocha tests/**/*.spec.js",
"test:fast": "cross-env-shell \"mkdirp debug && ncp src debug\" && cd debug/task && tsc --sourceMap && c8 --reporter=text --reporter=text-summary mocha tests/**/*.spec.js",
"update:package": "npm update"
Expand Down Expand Up @@ -52,6 +52,7 @@
"axios": "1.7.4",
"azure-devops-node-api": "14.0.2",
"azure-pipelines-task-lib": "4.16.0",
"http-status-codes": "2.3.0",
"isomorphic-fetch": "3.0.0",
"octokit": "3.2.1",
"parse-git-diff": "0.0.15",
Expand Down
5 changes: 4 additions & 1 deletion src/task/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import "reflect-metadata";
import PullRequestMetrics from "./src/pullRequestMetrics";
import { container } from "tsyringe";
import { exitCodeForFailure } from "./src/utilities/constants";

const run = async (): Promise<void> => {
const pullRequestMetrics: PullRequestMetrics =
container.resolve(PullRequestMetrics);
await pullRequestMetrics.run(__dirname);
};

run().finally((): void => {});
run().catch((): void => {
process.exit(exitCodeForFailure);
});
164 changes: 82 additions & 82 deletions src/task/src/git/gitInvoker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

import * as Validator from "../utilities/validator";
import { DecimalRadix } from "../utilities/constants";
import ExecOutput from "../runners/execOutput";
import Logger from "../utilities/logger";
import RunnerInvoker from "../runners/runnerInvoker";
import { decimalRadix } from "../utilities/constants";
import { singleton } from "tsyringe";

/**
Expand All @@ -19,10 +19,10 @@ export default class GitInvoker {
private readonly _logger: Logger;
private readonly _runnerInvoker: RunnerInvoker;

private _isInitialized: boolean = false;
private _targetBranch: string = "";
private _pullRequestId: number = 0;
private _pullRequestIdInternal: string = "";
private _isInitialized = false;
private _targetBranch = "";
private _pullRequestId = 0;
private _pullRequestIdInternal = "";

/**
* Initializes a new instance of the `GitInvoker` class.
Expand All @@ -34,50 +34,6 @@ export default class GitInvoker {
this._runnerInvoker = runnerInvoker;
}

/**
* Gets a value indicating whether the current folder corresponds to a Git repo.
* @returns A promise containing a value indicating whether the current folder corresponds to a Git repo.
*/
public async isGitRepo(): Promise<boolean> {
this._logger.logDebug("* GitInvoker.isGitRepo()");

try {
await this.invokeGit("rev-parse --is-inside-work-tree");
return true;
} catch {
return false;
}
}

/**
* Gets a value indicating whether the pull request ID is available.
* @returns A value indicating whether the pull request ID is available.
*/
public isPullRequestIdAvailable(): boolean {
this._logger.logDebug("* GitInvoker.isPullRequestIdAvailable()");

return !isNaN(parseInt(this.pullRequestIdInternal, DecimalRadix));
}

/**
* Gets a value indicating whether sufficient Git history is available to generate the PR metrics.
* @returns A promise containing a value indicating whether sufficient Git history is available to generate the PR metrics.
*/
public async isGitHistoryAvailable(): Promise<boolean> {
this._logger.logDebug("* GitInvoker.isGitHistoryAvailable()");

this.initialize();

try {
await this.invokeGit(
`rev-parse --branch origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
return true;
} catch {
return false;
}
}

/**
* Gets the ID of the pull request.
* @returns The ID of the pull request.
Expand All @@ -90,38 +46,13 @@ export default class GitInvoker {
}

this._pullRequestId = Validator.validateNumber(
parseInt(this.pullRequestIdInternal, DecimalRadix),
parseInt(this.pullRequestIdInternal, decimalRadix),
"Pull Request ID",
"GitInvoker.pullRequestId",
);
return this._pullRequestId;
}

/**
* Gets a diff summary related to the changes in the current branch.
* @returns A promise containing the diff summary.
*/
public async getDiffSummary(): Promise<string> {
this._logger.logDebug("* GitInvoker.getDiffSummary()");

this.initialize();
return this.invokeGit(
`diff --numstat --ignore-all-space origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
}

private initialize(): void {
this._logger.logDebug("* GitInvoker.initialize()");

if (this._isInitialized) {
return;
}

this._targetBranch = this.targetBranch;
this._pullRequestIdInternal = this.pullRequestIdInternal;
this._isInitialized = true;
}

private get pullRequestIdInternal(): string {
this._logger.logDebug("* GitInvoker.pullRequestIdInternal");

Expand All @@ -139,35 +70,35 @@ export default class GitInvoker {
this._logger.logDebug("* GitInvoker.pullRequestIdForGitHub");

const gitHubReference: string | undefined = process.env.GITHUB_REF;
if (!gitHubReference) {
if (typeof gitHubReference === "undefined") {
this._logger.logWarning("'GITHUB_REF' is undefined.");
return "";
}

const gitHubReferenceElements: string[] = gitHubReference.split("/");
if (gitHubReferenceElements.length < 3) {
if (typeof gitHubReferenceElements[2] === "undefined") {
this._logger.logWarning(
`'GITHUB_REF' is in an incorrect format '${gitHubReference}'.`,
);
return "";
}

return gitHubReferenceElements[2]!;
return gitHubReferenceElements[2];
}

private get pullRequestIdForAzurePipelines(): string {
this._logger.logDebug("* GitInvoker.pullRequestIdForAzurePipelines");

const variable: string | undefined = process.env.BUILD_REPOSITORY_PROVIDER;
if (!variable) {
if (typeof variable === "undefined") {
this._logger.logWarning("'BUILD_REPOSITORY_PROVIDER' is undefined.");
return "";
}

if (variable === "GitHub" || variable === "GitHubEnterprise") {
const result: string | undefined =
process.env.SYSTEM_PULLREQUEST_PULLREQUESTNUMBER;
if (!result) {
if (typeof result === "undefined") {
this._logger.logWarning(
"'SYSTEM_PULLREQUEST_PULLREQUESTNUMBER' is undefined.",
);
Expand All @@ -179,7 +110,7 @@ export default class GitInvoker {

const result: string | undefined =
process.env.SYSTEM_PULLREQUEST_PULLREQUESTID;
if (!result) {
if (typeof result === "undefined") {
this._logger.logWarning(
"'SYSTEM_PULLREQUEST_PULLREQUESTID' is undefined.",
);
Expand All @@ -203,7 +134,7 @@ export default class GitInvoker {
"SYSTEM_PULLREQUEST_TARGETBRANCH",
"GitInvoker.targetBranch",
);
const expectedStart: string = "refs/heads/";
const expectedStart = "refs/heads/";
if (variable.startsWith(expectedStart)) {
const startIndex: number = expectedStart.length;
return variable.substring(startIndex);
Expand All @@ -212,6 +143,75 @@ export default class GitInvoker {
return variable;
}

/**
* Gets a value indicating whether the current folder corresponds to a Git repo.
* @returns A promise containing a value indicating whether the current folder corresponds to a Git repo.
*/
public async isGitRepo(): Promise<boolean> {
this._logger.logDebug("* GitInvoker.isGitRepo()");

try {
await this.invokeGit("rev-parse --is-inside-work-tree");
return true;
} catch {
return false;
}
}

/**
* Gets a value indicating whether the pull request ID is available.
* @returns A value indicating whether the pull request ID is available.
*/
public isPullRequestIdAvailable(): boolean {
this._logger.logDebug("* GitInvoker.isPullRequestIdAvailable()");

return !isNaN(parseInt(this.pullRequestIdInternal, decimalRadix));
}

/**
* Gets a value indicating whether sufficient Git history is available to generate the PR metrics.
* @returns A promise containing a value indicating whether sufficient Git history is available to generate the PR metrics.
*/
public async isGitHistoryAvailable(): Promise<boolean> {
this._logger.logDebug("* GitInvoker.isGitHistoryAvailable()");

this.initialize();

try {
await this.invokeGit(
`rev-parse --branch origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
return true;
} catch {
return false;
}
}

/**
* Gets a diff summary related to the changes in the current branch.
* @returns A promise containing the diff summary.
*/
public async getDiffSummary(): Promise<string> {
this._logger.logDebug("* GitInvoker.getDiffSummary()");

this.initialize();
return this.invokeGit(
`diff --numstat --ignore-all-space origin/${this._targetBranch}...pull/${this._pullRequestIdInternal}/merge`,
);
}

private initialize(): void {
this._logger.logDebug("* GitInvoker.initialize()");

if (this._isInitialized) {
return;
}

this._targetBranch = this.targetBranch;
this._pullRequestIdInternal = this.pullRequestIdInternal;
this._isInitialized = true;
}

private async invokeGit(parameters: string): Promise<string> {
this._logger.logDebug("* GitInvoker.invokeGit()");

Expand Down
Loading
Loading