From 60e46e6d8877a6810383e1b49bc4699b3ace727f Mon Sep 17 00:00:00 2001 From: Max Reichmann Date: Thu, 4 Apr 2024 12:48:01 +0200 Subject: [PATCH] refactor: Fix ESLint + Add comments --- src/linter/yaml/UI5YamlLinter.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/linter/yaml/UI5YamlLinter.ts b/src/linter/yaml/UI5YamlLinter.ts index 67bfe923f..0fe0c7284 100644 --- a/src/linter/yaml/UI5YamlLinter.ts +++ b/src/linter/yaml/UI5YamlLinter.ts @@ -25,9 +25,18 @@ const deprecatedLibraries: string[] = [ // TODO: outsource as constant (for reus "sap.zen.dsh", ]; +// file content schema of 'UI5Yaml' with only relevant properties +interface UI5YamlContentSchema { // extend for further detections + framework: { + libraries: { + name: string; + }[]; + }; +} + export default class UI5YamlLinter { #content = ""; - #fromYamlContent: DataWithPosition = ""; + #fromYamlContent: DataWithPosition; #path = ""; #messages: LintMessage[] = []; #coverageInfo: CoverageInfo[] = []; @@ -39,9 +48,10 @@ export default class UI5YamlLinter { // eslint-disable-next-line @typescript-eslint/require-await async getReport(): Promise { - const source: any = this.#parseUI5Yaml(this.#content); + const source: UI5YamlContentSchema = this.#parseUI5Yaml(this.#content); this.#analyzeUI5Yaml(source); + // Calculate error counts let errorCount = 0; let warningCount = 0; let fatalErrorCount = 0; @@ -66,15 +76,17 @@ export default class UI5YamlLinter { }; } - #parseUI5Yaml(fileContent: string) { + #parseUI5Yaml(fileContent: string): UI5YamlContentSchema { + // Create JS object from YAML content with position information this.#fromYamlContent = fromYaml(fileContent); - return yaml.load(fileContent); + // Convert YAML content to JS object + return yaml.load(fileContent) as UI5YamlContentSchema; } - #analyzeUI5Yaml(ui5YamlObject: {framework: {libraries: {name: any}[]}}) { // maybe add ui5.yaml specific schema (https://sap.github.io/ui5-tooling/schema/ui5.yaml.json)? + #analyzeUI5Yaml(ui5YamlObject: UI5YamlContentSchema) { // Check for deprecated libraries if (ui5YamlObject?.framework?.libraries?.length) { - ui5YamlObject.framework.libraries.forEach((lib: {name: any}, index: number) => { + ui5YamlObject.framework.libraries.forEach((lib, index: number) => { if (deprecatedLibraries.includes(lib.name)) { const positionInfo = getPosition(this.#fromYamlContent.framework.libraries[index]); this.#messages.push({