Skip to content

Commit

Permalink
feat: Detect test resources in HTML test files
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Dec 16, 2024
1 parent 64d6356 commit 6af9955
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/linter/html/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default async function transpileHtml(
if (!hasSrc && tag.textNodes?.length > 0) {
report.addMessage(MESSAGE.CSP_UNSAFE_INLINE_SCRIPT, tag);
}

detectTestStarter(resourcePath, tag, context);
});

stylesheetLinkTags.forEach((tag) => {
Expand All @@ -52,6 +54,28 @@ export default async function transpileHtml(
}
}

function detectTestStarter(resourcePath: ResourcePath, tag: Tag, context: LinterContext) {
if (resourcePath.includes("testsuite.qunit.html")) {
const hasCreateSuite = tag.attributes.some((attr) => {
return attr.name.value.toLowerCase() === "src" &&
attr.value.value.includes("resources/sap/ui/test/starter/createSuite.js");
});

if (!hasCreateSuite) {
context.addLintingMessage(resourcePath, MESSAGE.PREFER_TEST_STARTER, {message: "Prefer test starter"});
}
} else if (resourcePath.includes("qunit.html")) {
// resources/sap/ui/test/starter/runTest.js
const hasRunTest = tag.attributes.some((attr) => {
return attr.name.value.toLowerCase() === "src" &&
attr.value.value.includes("resources/sap/ui/test/starter/runTest.js");
});
if (!hasRunTest) {
context.addLintingMessage(resourcePath, MESSAGE.PREFER_TEST_STARTER, {message: "Prefer test starter"});
}
}
}

function findBootstrapTag(tags: Tag[]): Tag | undefined {
// First search for script tag with id "sap-ui-bootstrap"
for (const tag of tags) {
Expand Down
10 changes: 10 additions & 0 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const RULES = {
"no-pseudo-modules": "no-pseudo-modules",
"parsing-error": "parsing-error",
"ui5-class-declaration": "ui5-class-declaration",
"prefer-test-starter": "prefer-test-starter",
} as const;

export enum LintMessageSeverity {
Expand Down Expand Up @@ -62,6 +63,7 @@ export enum MESSAGE {
PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY,
PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY_PROPERTIES_ARRAY,
PARTIALLY_DEPRECATED_PARAMETERS_GET,
PREFER_TEST_STARTER,
REDUNDANT_BOOTSTRAP_PARAM,
REDUNDANT_VIEW_CONFIG_PROPERTY,
SPELLING_BOOTSTRAP_PARAM,
Expand Down Expand Up @@ -529,4 +531,12 @@ export const MESSAGE_INFO = {
},
},

[MESSAGE.PREFER_TEST_STARTER]: {
severity: LintMessageSeverity.Warning,
ruleId: RULES["prefer-test-starter"],

message: ({message}: {message?: string}) => message,
details: () => undefined,
},

} as const;

0 comments on commit 6af9955

Please sign in to comment.