Skip to content

Commit

Permalink
fix: Eslint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Mar 25, 2024
1 parent b4276f8 commit 7b684a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/detectors/transpilers/html/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function initSaxWasm() {
}

async function parseHtml(contentStream: ReadStream, parseHandler: (type: SaxEventType, tag: Detail) => void) {
const options = { highWaterMark: 32 * 1024 }; // 32k chunks
const options = {highWaterMark: 32 * 1024}; // 32k chunks
const saxWasmBuffer = await initSaxWasm();
const saxParser = new SAXParser(SaxEventType.OpenTag | SaxEventType.CloseTag, options);

Expand Down Expand Up @@ -56,4 +56,4 @@ export async function extractScriptTags(contentStream: ReadStream) {
});

return scriptTags;
}
}
12 changes: 5 additions & 7 deletions src/linter/html/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import {extractScriptTags} from "../../detectors/transpilers/html/parser.js";
import {LintMessageSeverity} from "../../detectors/AbstractDetector.js";
import Reporter from "../../detectors/Reporter.js";

import type { TranspileResult } from "../../detectors/transpilers/AbstractTranspiler.js";
import type { ReadStream } from "node:fs";

import type {TranspileResult} from "../../detectors/transpilers/AbstractTranspiler.js";
import type {ReadStream} from "node:fs";

export async function lintHtml(resourceName: string, contentStream: ReadStream): Promise<TranspileResult> {
const taskLintEnd = taskStart("Static lint", resourceName);
Expand All @@ -14,16 +13,15 @@ export async function lintHtml(resourceName: string, contentStream: ReadStream):
const scriptTags = await extractScriptTags(contentStream);
const jsScriptTags = scriptTags.filter((tag) => tag.attributes.every((attr) => {
// The "type" attribute of the script tag should be
// 1. not set (default),
// 2. an empty string,
// 1. not set (default),
// 2. an empty string,
// 3. or a JavaScript MIME type (text/javascript)
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type#attribute_is_not_set_default_an_empty_string_or_a_javascript_mime_type
return attr.name.value !== "type" ||
(attr.name.value === "type" &&
(attr.value.value === "" || attr.value.value === "text/javascript"));
(attr.value.value === "" || attr.value.value === "text/javascript"));
}));


jsScriptTags.forEach((tag) => {
const scriptContent = tag.textNodes?.map((tNode) => tNode.value).join("").trim();

Expand Down

0 comments on commit 7b684a0

Please sign in to comment.