Skip to content

Commit

Permalink
refactor: rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarvin8 committed Dec 19, 2024
1 parent e30cdd8 commit fbedda6
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/helpers/setCoveredLinesSonar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import { join } from 'node:path';

import { getTotalLines } from './getTotalLines.js';
import { FileObject } from './types.js';
import { SonarClass } from './types.js';

export async function setCoveredLinesSonar(
coveredLines: number[],
uncoveredLines: number[],
repoRoot: string,
filePath: string,
fileObj: FileObject
fileObj: SonarClass
): Promise<void> {
const randomLines: number[] = [];
const totalLines = await getTotalLines(join(repoRoot, filePath));
Expand Down
12 changes: 9 additions & 3 deletions src/helpers/transformDeployCoverageReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
/* eslint-disable no-await-in-loop */

import { create } from 'xmlbuilder2';
import { DeployCoverageData, CoverageObject, CoberturaCoverageObject, FileObject, CoberturaClass } from './types.js';
import {
DeployCoverageData,
SonarCoverageObject,
CoberturaCoverageObject,
SonarClass,
CoberturaClass,
} from './types.js';
import { getPackageDirectories } from './getPackageDirectories.js';
import { findFilePath } from './findFilePath.js';
import { setCoveredLinesSonar } from './setCoveredLinesSonar.js';
Expand All @@ -18,7 +24,7 @@ export async function transformDeployCoverageReport(
const { repoRoot, packageDirectories } = await getPackageDirectories();

if (format === 'sonar') {
const coverageObj: CoverageObject = { coverage: { '@version': '1', file: [] } };
const coverageObj: SonarCoverageObject = { coverage: { '@version': '1', file: [] } };

for (const fileName in data) {
if (!Object.hasOwn(data, fileName)) continue;
Expand All @@ -36,7 +42,7 @@ export async function transformDeployCoverageReport(
.filter((lineNumber) => fileInfo.s[lineNumber] === 1)
.map(Number);

const fileObj: FileObject = {
const fileObj: SonarClass = {
'@path': normalizePathToUnix(relativeFilePath),
lineToCover: uncoveredLines.map((lineNumber: number) => ({
'@lineNumber': lineNumber,
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/transformTestCoverageReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/* eslint-disable no-await-in-loop */

import { create } from 'xmlbuilder2';
import { TestCoverageData, CoverageObject, FileObject, CoberturaCoverageObject, CoberturaClass } from './types.js';
import { TestCoverageData, SonarCoverageObject, SonarClass, CoberturaCoverageObject, CoberturaClass } from './types.js';
import { getPackageDirectories } from './getPackageDirectories.js';
import { findFilePath } from './findFilePath.js';
import { normalizePathToUnix } from './normalizePathToUnix.js';
Expand All @@ -20,7 +20,7 @@ export async function transformTestCoverageReport(
}

if (format === 'sonar') {
const coverageObj: CoverageObject = { coverage: { '@version': '1', file: [] } };
const coverageObj: SonarCoverageObject = { coverage: { '@version': '1', file: [] } };

for (const data of coverageData) {
const name = data?.name;
Expand All @@ -35,7 +35,7 @@ export async function transformTestCoverageReport(
continue;
}

const fileObj: FileObject = {
const fileObj: SonarClass = {
'@path': normalizePathToUnix(relativeFilePath),
lineToCover: [],
};
Expand Down
12 changes: 6 additions & 6 deletions src/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,24 @@ export type SfdxProject = {
packageDirectories: Array<{ path: string }>;
};

type LineToCover = {
type SonarLine = {
'@lineNumber': number;
'@covered': string;
};

export type FileObject = {
export type SonarClass = {
'@path': string;
lineToCover: LineToCover[];
lineToCover: SonarLine[];
};

export type CoverageObject = {
export type SonarCoverageObject = {
coverage: {
file: FileObject[];
file: SonarClass[];
'@version': string;
};
};

export type ConfigFile = {
export type HookFile = {
deployCoverageJsonPath: string;
testCoverageJsonPath: string;
coverageXmlPath: string;
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/postrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { resolve } from 'node:path';
import { Hook } from '@oclif/core';

import TransformerTransform from '../commands/acc-transformer/transform.js';
import { ConfigFile } from '../helpers/types.js';
import { HookFile } from '../helpers/types.js';
import { getRepoRoot } from '../helpers/getRepoRoot.js';

export const postrun: Hook<'postrun'> = async function (options) {
Expand All @@ -23,7 +23,7 @@ export const postrun: Hook<'postrun'> = async function (options) {
} else {
return;
}
let configFile: ConfigFile;
let configFile: HookFile;
const { repoRoot } = await getRepoRoot();
if (!repoRoot) {
return;
Expand All @@ -32,7 +32,7 @@ export const postrun: Hook<'postrun'> = async function (options) {

try {
const jsonString: string = await readFile(configPath, 'utf-8');
configFile = JSON.parse(jsonString) as ConfigFile;
configFile = JSON.parse(jsonString) as HookFile;
} catch (error) {
return;
}
Expand Down

0 comments on commit fbedda6

Please sign in to comment.