Skip to content

Commit

Permalink
refactor: Fix ESLint + Add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
maxreichmann committed Apr 4, 2024
1 parent cb2e207 commit 60e46e6
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/linter/yaml/UI5YamlLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];
Expand All @@ -39,9 +48,10 @@ export default class UI5YamlLinter {

// eslint-disable-next-line @typescript-eslint/require-await
async getReport(): Promise<LintResult> {
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;
Expand All @@ -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({
Expand Down

0 comments on commit 60e46e6

Please sign in to comment.