diff --git a/src/linter/ui5Types/TypeLinter.ts b/src/linter/ui5Types/TypeLinter.ts index 43578bc63..1b6c6f365 100644 --- a/src/linter/ui5Types/TypeLinter.ts +++ b/src/linter/ui5Types/TypeLinter.ts @@ -113,7 +113,9 @@ export default class TypeChecker { const sourceMaps = new Map(); // Maps a source path to source map content const apiExtract = await loadApiExtract(); const host = await createVirtualCompilerHost(this.#compilerOptions, files, sourceMaps, this.#context); - let {program, checker, pathsToLint} = await this.getProgram(host, files, sourceMaps); + const programInfo = await this.getProgram(host, files, sourceMaps); + let {program, checker} = programInfo; + const {pathsToLint} = programInfo; const reportCoverage = this.#context.getReportCoverage(); const messageDetails = this.#context.getIncludeMessageDetails(); diff --git a/src/linter/xmlTemplate/linter.ts b/src/linter/xmlTemplate/linter.ts index e6a3b9ae7..82b991b46 100644 --- a/src/linter/xmlTemplate/linter.ts +++ b/src/linter/xmlTemplate/linter.ts @@ -4,7 +4,7 @@ import transpileXml from "./transpiler.js"; import {LinterParameters} from "../LinterContext.js"; import ControllerByIdInfo from "./ControllerByIdInfo.js"; import {ControllerByIdDtsGenerator} from "./generator/ControllerByIdDtsGenerator.js"; -import { decodedMap, DecodedSourceMap, SourceMapInput, TraceMap } from "@jridgewell/trace-mapping"; +import {decodedMap, DecodedSourceMap, SourceMapInput, TraceMap} from "@jridgewell/trace-mapping"; // For usage in TypeLinter to write the file as part of the internal WRITE_TRANSFORMED_SOURCES debug mode export const CONTROLLER_BY_ID_DTS_PATH = "/types/@ui5/linter/virtual/ControllerById.d.ts"; @@ -24,17 +24,17 @@ export default async function lintXml({filePathsWorkspace, workspace, context}: const metadata = context.getMetadata(resourcePath); let xmlFromJsResourceMap; - // if (metadata.jsToXmlPosMapping) { - // xmlFromJsResourceMap = JSON.parse(map) as DecodedSourceMap; - // const {pos} = metadata.jsToXmlPosMapping; - // // If it's an XML snippet extracted from a JS file, adjust the source map positions - // // as they positions are relative to the extracted string, not to the real position in the JS file. - // // Add that missing line shift from the original JS file to the source map. - // xmlFromJsResourceMap = fixSourceMapIndices(xmlFromJsResourceMap, pos.line); - // // Replace the name of the source file in the source map with the original JS file name, - // // so that reporter will lead to the correct file. - // xmlFromJsResourceMap.sources.splice(0, 1, metadata.jsToXmlPosMapping.originalPath.split("/").pop() ?? null); - // } + if (metadata.jsToXmlPosMapping) { + xmlFromJsResourceMap = JSON.parse(map) as DecodedSourceMap; + const {pos} = metadata.jsToXmlPosMapping; + // If it's an XML snippet extracted from a JS file, adjust the source map positions + // as they positions are relative to the extracted string, not to the real position in the JS file. + // Add that missing line shift from the original JS file to the source map. + xmlFromJsResourceMap = fixSourceMapIndices(xmlFromJsResourceMap, pos.line); + // Replace the name of the source file in the source map with the original JS file name, + // so that reporter will lead to the correct file. + xmlFromJsResourceMap.sources.splice(0, 1, metadata.jsToXmlPosMapping.originalPath.split("/").pop() ?? null); + } // Write transpiled resource to workspace // TODO: suffix name to prevent clashes with existing files? @@ -77,10 +77,10 @@ function fixSourceMapIndices(map: SourceMapInput, lineShift = 0, columnShift = 0 const newMappings = mappings.map((segment) => segment.map(([genCol, srcIndex, origLine, origCol, nameIndex]) => { return (srcIndex !== undefined ? - [genCol + columnShift, srcIndex, origLine! + lineShift, origCol! + columnShift, nameIndex] : + [genCol + columnShift, srcIndex, origLine! + lineShift, origCol! + columnShift, nameIndex ?? 0] : [genCol + columnShift]); }) ); - return {...decodedTraceMap, mappings: newMappings}; + return {...decodedTraceMap, mappings: newMappings as DecodedSourceMap["mappings"]}; } diff --git a/test/lib/linter/_linterHelper.ts b/test/lib/linter/_linterHelper.ts index 6409f5a65..c146e5b68 100644 --- a/test/lib/linter/_linterHelper.ts +++ b/test/lib/linter/_linterHelper.ts @@ -8,6 +8,7 @@ import SourceFileLinter from "../../../src/linter/ui5Types/SourceFileLinter.js"; import {SourceFile, TypeChecker} from "typescript"; import LinterContext, {LinterOptions, LintResult} from "../../../src/linter/LinterContext.js"; import {ApiExtract} from "../../../src/utils/ApiExtract.js"; +import {AbstractAdapter} from "@ui5/fs"; util.inspect.defaultOptions.depth = 4; // Increase AVA's printing depth since coverageInfo objects are on level 4 @@ -33,12 +34,13 @@ export async function esmockDeprecationText() { reportCoverage: boolean | undefined = false, messageDetails: boolean | undefined = false, apiExtract: ApiExtract, + filePathsWorkspace: AbstractAdapter, manifestContent?: string ) { // Don't use sinon's stubs as it's hard to clean after them in this case and it leaks memory. const linter = new SourceFileLinter( context, filePath, sourceFile, sourceMaps, checker, reportCoverage, - messageDetails, apiExtract, manifestContent + messageDetails, apiExtract, filePathsWorkspace, manifestContent ); linter.getDeprecationText = () => "Deprecated test message"; return linter; diff --git a/test/lib/linter/xmlInJs/_helper.ts b/test/lib/linter/xmlInJs/_helper.ts index c17ca0818..836005cdd 100644 --- a/test/lib/linter/xmlInJs/_helper.ts +++ b/test/lib/linter/xmlInJs/_helper.ts @@ -1,11 +1,8 @@ import anyTest, {TestFn} from "ava"; import sinonGlobal from "sinon"; -import path from "node:path"; import util from "util"; import {readdirSync} from "node:fs"; -import fs from "node:fs/promises"; import {lintFile} from "../../../../src/linter/linter.js"; -import {extractXMLFromJs} from "../../../../src/linter/xmlInJs/transpile.js"; util.inspect.defaultOptions.depth = 4; // Increase AVA's printing depth since coverageInfo objects are on level 4 @@ -40,9 +37,9 @@ export function createTestsForFixtures(fixturesPath: string) { // Executing linting in parallel might lead to OOM errors in the CI // Therefore always use serial defineTest(`Transpile ${testName}`, async (t) => { - const filePath = path.join(fixturesPath, fileName); - const fileContent = await fs.readFile(filePath); - const extractedResource = extractXMLFromJs(testName, fileContent.toString()); + // const filePath = path.join(fixturesPath, fileName); + // const fileContent = await fs.readFile(filePath); + // const extractedResource = extractXMLFromJs(testName, fileContent.toString()); const resources = await lintFile({ rootDir: fixturesPath, @@ -51,7 +48,7 @@ export function createTestsForFixtures(fixturesPath: string) { details: true, }); - extractedResource?.forEach((resource) => t.snapshot(resource.xmlSnippet)); + // extractedResource?.forEach((resource) => t.snapshot(resource.xmlSnippet)); resources.forEach((res) => { res.messages.sort( (a, b) => (a.line! - b.line!) + (a.column! - b.column!));