From 34bb533af2ff0178c5aff302249e4b15a0e036aa Mon Sep 17 00:00:00 2001 From: Matt Carvin <90224411+mcarvin8@users.noreply.github.com> Date: Thu, 9 Jan 2025 18:02:20 -0500 Subject: [PATCH] refactor: normalize path to unix when found --- src/handlers/cloverCoverageHandler.ts | 3 +-- src/handlers/coberturaCoverageHandler.ts | 3 +-- src/handlers/lcovCoverageHandler.ts | 3 +-- src/handlers/sonarCoverageHandler.ts | 3 +-- src/helpers/findFilePath.ts | 2 ++ 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/handlers/cloverCoverageHandler.ts b/src/handlers/cloverCoverageHandler.ts index 003e087..c7f287a 100644 --- a/src/handlers/cloverCoverageHandler.ts +++ b/src/handlers/cloverCoverageHandler.ts @@ -1,7 +1,6 @@ 'use strict'; import { CloverCoverageObject, CloverFile, CoverageHandler } from '../helpers/types.js'; -import { normalizePathToUnix } from '../helpers/normalizePathToUnix.js'; export class CloverCoverageHandler implements CoverageHandler { private readonly coverageObj: CloverCoverageObject; @@ -45,7 +44,7 @@ export class CloverCoverageHandler implements CoverageHandler { ): void { const fileObj: CloverFile = { '@name': fileName, - '@path': normalizePathToUnix(filePath), + '@path': filePath, metrics: { '@statements': uncoveredLines.length + coveredLines.length, '@coveredstatements': coveredLines.length, diff --git a/src/handlers/coberturaCoverageHandler.ts b/src/handlers/coberturaCoverageHandler.ts index f75b2c0..402ed13 100644 --- a/src/handlers/coberturaCoverageHandler.ts +++ b/src/handlers/coberturaCoverageHandler.ts @@ -1,7 +1,6 @@ 'use strict'; import { CoberturaCoverageObject, CoberturaPackage, CoberturaClass, CoverageHandler } from '../helpers/types.js'; -import { normalizePathToUnix } from '../helpers/normalizePathToUnix.js'; export class CoberturaCoverageHandler implements CoverageHandler { private readonly coverageObj: CoberturaCoverageObject; @@ -41,7 +40,7 @@ export class CoberturaCoverageHandler implements CoverageHandler { ): void { const classObj: CoberturaClass = { '@name': fileName, - '@filename': normalizePathToUnix(filePath), + '@filename': filePath, '@line-rate': '0', '@branch-rate': '1', methods: {}, diff --git a/src/handlers/lcovCoverageHandler.ts b/src/handlers/lcovCoverageHandler.ts index 6e0e0a2..edb2a51 100644 --- a/src/handlers/lcovCoverageHandler.ts +++ b/src/handlers/lcovCoverageHandler.ts @@ -1,7 +1,6 @@ 'use strict'; import { CoverageHandler, LcovCoverageObject, LcovFile } from '../helpers/types.js'; -import { normalizePathToUnix } from '../helpers/normalizePathToUnix.js'; export class LcovCoverageHandler implements CoverageHandler { private readonly coverageObj: LcovCoverageObject; @@ -18,7 +17,7 @@ export class LcovCoverageHandler implements CoverageHandler { coveredLines: number[], ): void { const lcovFile: LcovFile = { - sourceFile: normalizePathToUnix(filePath), + sourceFile: filePath, lines: [], totalLines: uncoveredLines.length + coveredLines.length, coveredLines: coveredLines.length, diff --git a/src/handlers/sonarCoverageHandler.ts b/src/handlers/sonarCoverageHandler.ts index d614f68..aac2596 100644 --- a/src/handlers/sonarCoverageHandler.ts +++ b/src/handlers/sonarCoverageHandler.ts @@ -1,7 +1,6 @@ 'use strict'; import { SonarCoverageObject, SonarClass, CoverageHandler } from '../helpers/types.js'; -import { normalizePathToUnix } from '../helpers/normalizePathToUnix.js'; export class SonarCoverageHandler implements CoverageHandler { private readonly coverageObj: SonarCoverageObject; @@ -16,7 +15,7 @@ export class SonarCoverageHandler implements CoverageHandler { lines: Record, ): void { const fileObj: SonarClass = { - '@path': normalizePathToUnix(filePath), + '@path': filePath, lineToCover: [], }; for (const lineNumberString in lines) { diff --git a/src/helpers/findFilePath.ts b/src/helpers/findFilePath.ts index fabc3cd..e472bca 100644 --- a/src/helpers/findFilePath.ts +++ b/src/helpers/findFilePath.ts @@ -3,6 +3,7 @@ import { readdir, stat } from 'node:fs/promises'; import { join, relative } from 'node:path'; +import { normalizePathToUnix } from './normalizePathToUnix.js'; export async function findFilePath( fileName: string, @@ -13,6 +14,7 @@ export async function findFilePath( for (const directory of packageDirectories) { relativeFilePath = await findFilePathinDirectory(fileName, directory, repoRoot); if (relativeFilePath !== undefined) { + relativeFilePath = normalizePathToUnix(relativeFilePath) break; } }