How sap/ui5-linter works
Project Type and Purpose
• This is an open-source, TypeScript-based CLI tool and Node.js library (“UI5 Linter”) for statically analyzing UI5 applications.
• Its purpose is to scan UI5 JavaScript, TypeScript, XML, JSON, etc., detect deprecated APIs, globals, CSP violations, manifest errors, and optionally autofix certain issues.
High-Level Architecture
• Container: Node.js runtime
• Entrypoint: bin/ui5lint.js (CLI)
• Library API: src/index.ts (ui5lint function) and UI5LinterEngine class
• Core Engine
• ConfigManager (loads CLI flags, config file, UI5 YAML)
• File Scanner / Glob Resolver (builds list of files based on patterns and ignore-patterns)
• Linter Orchestrator (lintWorkspace, LinterContext)
• Parsers and Transpilers
• TypeScript Compiler API (parses JS/TS after optional ESM transpilation)
• XML/HTML transpiler (converts UI5 XML views to JS AST)
• AMD → ESM transpiler (rewrites sap.ui.require calls)
• Rules and Analyzers
• Rule modules (src/linter/...): binding, dotLibrary, manifestJson, HTML, YAML, UI5 types, XML templates, etc.
• Each rule registers with the LinterContext and returns Findings
• Autofix Pipeline
• Autofix runner (src/autofix) applies automatic solutions for fixable rules, then triggers a second lint pass
• Formatters and Output
• Formatter modules (src/formatter): text, JSON, Markdown, coverage reports
• CLI logger and middlewares (src/cli/middlewares) handle spinner, log-level, update notifications, perf logging
• External Dependencies
• UI5 Type Definitions (resources/types + api-extract.json)
• TypeScript Compiler (npm module)
• Node.js FS/Path modules
Relationships and Data Flows
• The CLI invokes the Library API with parsed options → ConfigManager → File Scanner
• File Scanner outputs a stream/list of file paths → Linter Orchestrator
• For each file:
a. Optional Transpiler
b. Parser (TS or XML → TS AST)
c. LinterContext dispatches AST to rule modules → collects findings
• Autofix pipeline may transform source files on disk and re-invoke the above steps
• Findings are passed to Formatter → CLI prints to console or file
Architectural Patterns and Principles
• Modular pipeline architecture (scan → parse → analyze → format)
• Dependency inversion: rules implement a common linter interface and register dynamically
• Separation of concerns: CLI parsing, config, scanning, parsing, linting, formatting, autofix are all separate layers
• Caching/Reusability: UI5LinterEngine caches common data for repeated runs
• Inside:
– CLI Layer (Parser → Middlewares)
– ConfigManager
– File Scanner
– Transpiler Layer
– Parser & AST Generator
– Linter Engine (LinterContext + Rule Modules)
– Autofix Module
– Formatter Module
• External Services/Resources around it:
– UI5 Type Definitions & api-extract.json
– TypeScript Compiler API
– Filesystem (Input: project files; Output: reports, modified files)