Skip to content

Commit

Permalink
fix(html): False positive for global function name in on-init bootstr…
Browse files Browse the repository at this point in the history
…ap param

Resolves #336
  • Loading branch information
RandomByte committed Oct 1, 2024
1 parent a881ff6 commit 2495cc0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/linter/html/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,19 @@ function checkCompatVersionAttr(attr: Attribute, report: HtmlReporter) {
function checkOnInitAttr(attr: Attribute, report: HtmlReporter) {
const value = attr.value.value.toLowerCase().trim();
if (!value.startsWith("module:")) {
report.addMessage(MESSAGE.DEPRECATED_BOOTSTRAP_PARAM, {
name: "data-sap-ui-on-init",
value,
details: `{@link topic:91f2d03b6f4d1014b6dd926db0e91070 Configuration Options and URL Parameters}`,
}, attr.value);
// Check whether value is a valid function/variable name.
// Anything that can't be a global function (accessible via "window[value]")
// should be reported as deprecated. E.g. "my.init-function" or "alert('Hello')"
// This is a very basic check and might report false positives for function assigned the global scope using
// string literals, e.g. window["my.init.function"] = function() {}
const validFunctionName = /^[$_\p{ID_Start}][$_\p{ID_Continue}]*$/u;
if (!validFunctionName.test(value)) {
report.addMessage(MESSAGE.DEPRECATED_BOOTSTRAP_PARAM, {
name: "data-sap-ui-on-init",
value,
details: `{@link topic:91f2d03b6f4d1014b6dd926db0e91070 Configuration Options and URL Parameters}`,
}, attr.value);
}
}

if (value.includes("sap/ui/core/plugin/declarativesupport")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
data-sap-ui-libs="sap.m"
data-sap-ui-async="true"
data-sap-ui-modules="sap.ui.core.plugin.DeclarativeSupport,sap.ui.core.plugin.LessSupport"
data-sap-ui-on-init="myΩGlobalInitFunction"
>
</script>
</head>
Expand Down

0 comments on commit 2495cc0

Please sign in to comment.