Skip to content

Commit

Permalink
feat: Detect legacy template:require (space-separated list)
Browse files Browse the repository at this point in the history
JIRA: CPOUI5FOUNDATION-917
  • Loading branch information
matz3 committed Feb 14, 2025
1 parent 81d4173 commit a840e1f
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum MESSAGE {
NO_EXPORTED_VALUES_BY_LIB,
NO_GLOBALS,
NO_ICON_POOL_RENDERER,
NO_LEGACY_TEMPLATE_REQUIRE_SYNTAX,
NO_ODATA_GLOBALS,
NOT_STATIC_CONTROL_RENDERER,
PARSING_ERROR,
Expand Down Expand Up @@ -368,6 +369,16 @@ export const MESSAGE_INFO = {
details: () => `{@link sap.ui.core.RenderManager#methods/icon RenderManager}`,
},

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

message: ({moduleNames}: {moduleNames: string}) =>
`Usage of space-separated list '${moduleNames}' in template:require`,
details: () => `Use the object notation of template:require instead ` +
`{@link topic:263f6e5a915f430894ee290040e7e220}`,
},

[MESSAGE.NOT_STATIC_CONTROL_RENDERER]: {
severity: LintMessageSeverity.Warning,
ruleId: RULES["ui5-class-declaration"],
Expand Down
7 changes: 7 additions & 0 deletions src/linter/xmlTemplate/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ export default class Parser {
variableName,
});
});
if (requireDeclarations.length) {
// Usage of space separated list is not recommended, as it only allows for global access
this.#context.addLintingMessage(this.#resourcePath,
MESSAGE.NO_LEGACY_TEMPLATE_REQUIRE_SYNTAX,
{moduleNames: attr.value}, attr.start
);
}
} else {
// Most common case: JSON-like representation
// e.g. core:require="{Helper: 'sap/ui/demo/todo/util/Helper'}"
Expand Down
10 changes: 9 additions & 1 deletion test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1896,7 +1896,7 @@ Generated by [AVA](https://avajs.dev).
[
{
coverageInfo: [],
errorCount: 4,
errorCount: 5,
fatalErrorCount: 0,
filePath: 'XMLTemplatingRequire.view.xml',
messages: [
Expand All @@ -1908,6 +1908,14 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 7,
line: 8,
message: 'Usage of space-separated list \'sap.ui.model.odata.ODataModel sap.ui.model.odata.ODataUtils\' in template:require',
messageDetails: 'Use the object notation of template:require instead topic:263f6e5a915f430894ee290040e7e220 (https://ui5.sap.com/#/topic/263f6e5a915f430894ee290040e7e220)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 8,
line: 9,
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.
8 changes: 8 additions & 0 deletions test/lib/linter/xmlTemplate/snapshots/transpiler.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,14 @@ Generated by [AVA](https://avajs.dev).
> messages
[
{
column: 7,
line: 8,
message: 'Usage of space-separated list \'sap.ui.model.odata.ODataModel sap.ui.model.odata.ODataUtils\' in template:require',
messageDetails: 'Use the object notation of template:require instead topic:263f6e5a915f430894ee290040e7e220 (https://ui5.sap.com/#/topic/263f6e5a915f430894ee290040e7e220)',
ruleId: 'no-deprecated-api',
severity: 2,
},
{
column: 37,
line: 10,
Expand Down
Binary file modified test/lib/linter/xmlTemplate/snapshots/transpiler.ts.snap
Binary file not shown.

0 comments on commit a840e1f

Please sign in to comment.