Skip to content

Commit

Permalink
feat: Add further deprecated configuration option detection (#357)
Browse files Browse the repository at this point in the history
JIRA: CPOUI5FOUNDATION-925

Documentation:
https://ui5.sap.com/#/topic/b474a712ca364d40a1b0a804baf2d734

---------

Co-authored-by: Yavor Ivanov <[email protected]>
Co-authored-by: Yavor Ivanov <[email protected]>
Co-authored-by: Matthias Oßwald <[email protected]>
  • Loading branch information
4 people authored Dec 19, 2024
1 parent 2adeea4 commit 28e60a0
Show file tree
Hide file tree
Showing 9 changed files with 327 additions and 34 deletions.
84 changes: 82 additions & 2 deletions src/linter/html/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ const oldToNewAttr = new Map([
["data-sap-ui-evt-oninit", "data-sap-ui-on-init"],
["data-sap-ui-oninit", "data-sap-ui-on-init"],
["data-sap-ui-resourceroots", "data-sap-ui-resource-roots"],
["data-sap-ui-legacy-date-format", "data-sap-ui-a-b-a-p-date-format"],
["data-sap-ui-legacy-time-format", "data-sap-ui-a-b-a-p-time-format"],
["data-sap-ui-legacy-number-format", "data-sap-ui-a-b-a-p-number-format"],
]);

const aliasToAttr = new Map([
Expand All @@ -110,7 +113,7 @@ function lintBootstrapAttributes(tag: Tag, report: HtmlReporter) {
if (attributes.has(attributeName)) {
report.addMessage(MESSAGE.DUPLICATE_BOOTSTRAP_PARAM, {
name: attributeName,
value: attr.name.value,
value: attr.value.value,
}, attr.name);
}
attributes.add(attributeName);
Expand All @@ -134,16 +137,54 @@ function lintBootstrapAttributes(tag: Tag, report: HtmlReporter) {
checkOnInitAttr(attr, report);
break;
case "data-sap-ui-binding-syntax":
checkBindingSyntaxAttr(attr, report);
break;
case "data-sap-ui-origin-info":
checkOriginInfoAttr(attr, report);
break;
case "data-sap-ui-preload":
report.addMessage(MESSAGE.REDUNDANT_BOOTSTRAP_PARAM, {
checkPreloadAttr(attr, report);
break;
case "data-sap-ui-no-duplicate-ids":
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
messageDetails: "Duplicate ID checks are enforced with UI5 2.x",
}, attr.name);
break;
case "data-sap-ui-auto-aria-body-role":
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
messageDetails: "Avoid assigning a role=\"application\" to the body element, as doing so " +
"would make screen readers interpret the entire application as a single custom control",
}, attr.name);
break;
case "data-sap-ui-xx-no-less":
case "data-sap-ui-trace":
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM, {
name: attr.name.value,
}, attr.name);
break;
case "data-sap-ui-areas":
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM, {
name: attr.name.value,
messageDetails: "No longer supported. UI areas are created on request by calling Control.placeAt",
}, attr.name);
break;
case "data-sap-ui-animation":
report.addMessage(MESSAGE.REPLACED_BOOTSTRAP_PARAM, {
name: attr.name.value,
replacement: "data-sap-ui-animation-mode",
messageDetails: "Migrate to 'data-sap-ui-animation-mode' attribute " +
"{@link module:sap/ui/core/AnimationMode AnimationMode}",
}, attr.name);
break;
case "data-sap-ui-manifest-first":
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
messageDetails: "Set the manifest parameter in component factory call" +
" {@link sap.ui.core.Component#sap.ui.core.Component.create}",
}, attr.name);
break;
}
}

Expand All @@ -161,6 +202,45 @@ function lintBootstrapAttributes(tag: Tag, report: HtmlReporter) {
}
}

function checkPreloadAttr(attr: Attribute, report: HtmlReporter) {
const value = attr.value.value.toLowerCase();
if (value && !["auto", "async", "sync"].includes(value)) {
report.addMessage(MESSAGE.REDUNDANT_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
messageDetails: "Use sap-ui-debug=true to suppress library preload requests",
}, attr.name);
}
}

function checkOriginInfoAttr(attr: Attribute, report: HtmlReporter) {
if (attr.value.value.toLowerCase() === "true") {
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
}, attr.name);
} else {
report.addMessage(MESSAGE.ABANDONED_BOOTSTRAP_PARAM, {
name: attr.name.value,
}, attr.name);
}
}

function checkBindingSyntaxAttr(attr: Attribute, report: HtmlReporter) {
if (attr.value.value.toLowerCase() === "complex") {
report.addMessage(MESSAGE.REDUNDANT_BOOTSTRAP_PARAM, {
name: attr.name.value,
messageDetails: "Only 'complex' is supported with UI5 2.x and automatically" +
" enforced by the UI5 runtime. Complex binding parser supports simple binding syntax per default.",
}, attr.name);
} else {
report.addMessage(MESSAGE.REDUNDANT_BOOTSTRAP_PARAM_ERROR, {
name: attr.name.value,
messageDetails: "Only 'complex' is supported with UI5 2.x and automatically" +
" enforced by the UI5 runtime. Check all bindings whether they will be " +
"misinterpreted in 2.x with binding syntax 'complex'.",
}, attr.name);
}
}

function checkThemeAttr(attr: Attribute, report: HtmlReporter) {
const themeName = attr.value.value.toLowerCase();
if (deprecatedThemes.includes(themeName)) {
Expand Down
34 changes: 32 additions & 2 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum LintMessageSeverity {
// Messages (sorted alphabetically)
export enum MESSAGE {
ABANDONED_BOOTSTRAP_PARAM,
ABANDONED_BOOTSTRAP_PARAM_ERROR,
COMPONENT_MISSING_ASYNC_INTERFACE,
COMPONENT_MISSING_MANIFEST_DECLARATION,
COMPONENT_REDUNDANT_ASYNC_FLAG,
Expand Down Expand Up @@ -63,7 +64,9 @@ export enum MESSAGE {
PARTIALLY_DEPRECATED_ODATA_MODEL_V2_CREATE_ENTRY_PROPERTIES_ARRAY,
PARTIALLY_DEPRECATED_PARAMETERS_GET,
REDUNDANT_BOOTSTRAP_PARAM,
REDUNDANT_BOOTSTRAP_PARAM_ERROR,
REDUNDANT_VIEW_CONFIG_PROPERTY,
REPLACED_BOOTSTRAP_PARAM,
SPELLING_BOOTSTRAP_PARAM,
SVG_IN_XML,
MISSING_CONTROL_RENDERER_DECLARATION,
Expand All @@ -77,7 +80,16 @@ export const MESSAGE_INFO = {

message: ({name}: {name: string}) =>
`Abandoned bootstrap parameter '${name}' should be removed`,
details: () => undefined,
details: ({messageDetails}: {messageDetails?: string}) => messageDetails,
},

[MESSAGE.ABANDONED_BOOTSTRAP_PARAM_ERROR]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["no-deprecated-api"],

message: ({name}: {name: string}) =>
`Abandoned bootstrap parameter '${name}' should be removed`,
details: ({messageDetails}: {messageDetails?: string}) => messageDetails,
},

[MESSAGE.COMPONENT_MISSING_ASYNC_INTERFACE]: {
Expand Down Expand Up @@ -474,7 +486,16 @@ export const MESSAGE_INFO = {

message: ({name}: {name: string}) =>
`Redundant bootstrap parameter '${name}' should be removed`,
details: () => undefined,
details: ({messageDetails}: {messageDetails?: string}) => messageDetails,
},

[MESSAGE.REDUNDANT_BOOTSTRAP_PARAM_ERROR]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["no-deprecated-api"],

message: ({name}: {name: string}) =>
`Redundant bootstrap parameter '${name}' should be removed`,
details: ({messageDetails}: {messageDetails?: string}) => messageDetails,
},

[MESSAGE.REDUNDANT_VIEW_CONFIG_PROPERTY]: {
Expand Down Expand Up @@ -529,4 +550,13 @@ export const MESSAGE_INFO = {
},
},

[MESSAGE.REPLACED_BOOTSTRAP_PARAM]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["no-deprecated-api"],

message: ({name, replacement}: {name: string; replacement: string}) =>
`Bootstrap parameter '${name}' should be replaced with '${replacement}'`,
details: ({messageDetails}: {messageDetails: string}) => messageDetails,
},

} as const;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,23 @@
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-compat-version="1.18"
data-sap-ui-async="false"
data-sap-ui-animation="false"
data-sap-ui-areas="uiArea1,uiArea2"
data-sap-ui-auto-aria-body-role="true"
data-sap-ui-binding-syntax="simple"
data-sap-ui-binding-syntax="complex"
data-sap-ui-format-settings='{"legacyDateFormat": "1"}'
data-sap-ui-manifest-first="true"
data-sap-ui-no-duplicate-ids="true"
data-sap-ui-origin-info="true"
data-sap-ui-origin-info="false"
data-sap-ui-preload="false"
data-sap-ui-trace="true"
data-sap-ui-on-init="my.global.function"

data-sap-ui-legacy-date-format=""
data-sap-ui-legacy-time-format=""
data-sap-ui-legacy-number-format=""

data-sap-ui-xx-waitForTheme="true">
</script>
Expand Down
Loading

0 comments on commit 28e60a0

Please sign in to comment.