💄 use native endsWith, fyi @chrmarti

This commit is contained in:
Johannes Rieken 2022-01-05 11:46:05 +01:00
parent 986f163f9f
commit ffdb8427ed
No known key found for this signature in database
GPG key ID: 96634B5AF12F8798

View file

@ -77,7 +77,7 @@ export class ExtensionLinter {
private queue(document: TextDocument) {
const p = document.uri.path;
if (document.languageId === 'json' && endsWith(p, '/package.json')) {
if (document.languageId === 'json' && p.endsWith('/package.json')) {
this.packageJsonQ.add(document);
this.startTimer();
}
@ -86,7 +86,7 @@ export class ExtensionLinter {
private queueReadme(document: TextDocument) {
const p = document.uri.path;
if (document.languageId === 'markdown' && (endsWith(p.toLowerCase(), '/readme.md') || endsWith(p.toLowerCase(), '/changelog.md'))) {
if (document.languageId === 'markdown' && (p.toLowerCase().endsWith('/readme.md') || p.toLowerCase().endsWith('/changelog.md'))) {
this.readmeQ.add(document);
this.startTimer();
}
@ -348,7 +348,7 @@ export class ExtensionLinter {
diagnostics.push(new Diagnostic(range, message, DiagnosticSeverity.Warning));
}
if (endsWith(uri.path.toLowerCase(), '.svg') && !isTrustedSVGSource(uri)) {
if (uri.path.toLowerCase().endsWith('.svg') && !isTrustedSVGSource(uri)) {
const range = new Range(document.positionAt(begin), document.positionAt(end));
diagnostics.push(new Diagnostic(range, svgsNotValid, DiagnosticSeverity.Warning));
}
@ -365,17 +365,6 @@ export class ExtensionLinter {
}
}
function endsWith(haystack: string, needle: string): boolean {
let diff = haystack.length - needle.length;
if (diff > 0) {
return haystack.indexOf(needle, diff) === diff;
} else if (diff === 0) {
return haystack === needle;
} else {
return false;
}
}
function parseUri(src: string, base?: string, retry: boolean = true): Uri | null {
try {
let url = new URL(src, base);