Skip to content

Commit

Permalink
feat: Add directives
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomByte committed Oct 9, 2024
1 parent 63e59e8 commit 1e3a049
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/linter/ui5Types/SourceFileLinter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import {getPropertyName} from "./utils.js";

const log = getLogger("linter:ui5Types:SourceFileLinter");

/* Match things like:
ui5-lint-disable-next-line no-deprecated-api no-global
ui5-lint-disable
no-deprecated-api
no-global
ui5-lint-enable-next-line
*/
const disableCommentRegex = /\/[/*]\s*ui5lint-(enable|disable)((?:-next)?-line)?((?:\s+[\w-]+,)*(?:\s+[\w-]+))?\s*(?:\*\/|$)/mg;

interface DeprecationInfo {
symbol: ts.Symbol;
messageDetails: string;
Expand Down Expand Up @@ -72,6 +81,7 @@ export default class SourceFileLinter {
// eslint-disable-next-line @typescript-eslint/require-await
async lint() {
try {
this.collectPossibleComments(this.#sourceFile);
this.visitNode(this.#sourceFile);
this.#reporter.deduplicateMessages();
} catch (err) {
Expand Down Expand Up @@ -126,6 +136,22 @@ export default class SourceFileLinter {
ts.forEachChild(node, this.#boundVisitNode);
}

collectPossibleComments(sourceFile: ts.SourceFile) {
const text = sourceFile.getFullText();
let match;
const comments = new Set();
while ((match = disableCommentRegex.exec(text)) !== null) {
const [, action, nextLineOrLine, rules] = match;
const pos = match.index;
const length = match[0].length;
const ruleNames = rules?.trim().split(",") ?? [];
const isLine = nextLineOrLine === "-line";
const isNextLine = nextLineOrLine === "-next-line";
comments.add({action, isLine, isNextLine, ruleNames, pos, length});
}
return comments;
}

analyzeIdentifier(node: ts.Identifier) {
const type = this.#checker.getTypeAtLocation(node);
if (!type?.symbol || !this.isSymbolOfUi5OrThirdPartyType(type.symbol)) {
Expand Down

0 comments on commit 1e3a049

Please sign in to comment.