Skip to content

Commit

Permalink
fix(html): Improve detection of deprecated themes
Browse files Browse the repository at this point in the history
The detection now includes all theme variants and all deprecated or
already removed themes, based on the list of deprecated themes in the
UI5 SDK.
  • Loading branch information
matz3 committed Oct 7, 2024
1 parent 6d51ec5 commit 0a30673
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/linter/html/transpiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import LinterContext, {ResourcePath, TranspileResult} from "../LinterContext.js"
import {taskStart} from "../../utils/perf.js";
import {MESSAGE} from "../messages.js";
import {Tag, Attribute} from "sax-wasm";
import {deprecatedLibraries, deprecatedThemeLibraries} from "../../utils/deprecations.js";
import {deprecatedLibraries, deprecatedThemes} from "../../utils/deprecations.js";

export default async function transpileHtml(
resourcePath: ResourcePath, contentStream: ReadStream, context: LinterContext
Expand Down Expand Up @@ -151,8 +151,8 @@ function lintBootstrapAttributes(tag: Tag, report: HtmlReporter) {

function checkThemeAttr(attr: Attribute, report: HtmlReporter) {
const themeName = attr.value.value.toLowerCase();
if (deprecatedThemeLibraries.includes(`themelib_${themeName}`)) {
report.addMessage(MESSAGE.DEPRECATED_THEME_LIBRARY, {
if (deprecatedThemes.includes(themeName)) {
report.addMessage(MESSAGE.DEPRECATED_THEME, {
themeName,
}, attr.value);
}
Expand Down
9 changes: 5 additions & 4 deletions src/linter/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const RULES = {
"no-deprecated-api": "no-deprecated-api",
"no-deprecated-component": "no-deprecated-component",
"no-deprecated-library": "no-deprecated-library",
"no-deprecated-theme": "no-deprecated-theme",
"no-globals": "no-globals",
"no-pseudo-modules": "no-pseudo-modules",
"parsing-error": "parsing-error",
Expand Down Expand Up @@ -36,7 +37,7 @@ export enum MESSAGE {
DEPRECATED_ODATA_MODEL_V4_SYNCHRONIZATION_MODE,
DEPRECATED_PROPERTY,
DEPRECATED_PROPERTY_OF_CLASS,
DEPRECATED_THEME_LIBRARY,
DEPRECATED_THEME,
DEPRECATED_VIEW_CONFIG,
DEPRECATED_VIEW_TYPE,
DUPLICATE_BOOTSTRAP_PARAM,
Expand Down Expand Up @@ -236,13 +237,13 @@ export const MESSAGE_INFO = {
details: ({details}: {details: string}) => details,
},

[MESSAGE.DEPRECATED_THEME_LIBRARY]: {
[MESSAGE.DEPRECATED_THEME]: {
severity: LintMessageSeverity.Error,
ruleId: RULES["no-deprecated-library"],
ruleId: RULES["no-deprecated-theme"],

message: ({themeName}: {themeName: string}) =>
`Use of deprecated theme '${themeName}'`,
details: () => undefined,
details: () => `{@link topic:a87ca843bcee469f82a9072927a7dcdb Deprecated Themes and Libraries}`,
},

[MESSAGE.DEPRECATED_VIEW_CONFIG]: {
Expand Down
25 changes: 23 additions & 2 deletions src/utils/deprecations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,29 @@ export const deprecatedLibraries: string[] = [
];

export const deprecatedThemeLibraries: string[] = [
"themelib_sap_belize",
"themelib_sap_bluecrystal",
"themelib_sap_belize", // deprecated as of 1.120
"themelib_sap_bluecrystal", // deprecated as of 1.40
];

// Based on https://ui5.sap.com/#/topic/a87ca843bcee469f82a9072927a7dcdb
export const deprecatedThemes: string[] = [

// Part of themelib_sap_belize, deprecated as of 1.120
"sap_belize",
"sap_belize_plus",
"sap_belize_hcb",
"sap_belize_hcw",

// Part of themelib_sap_bluecrystal, deprecated as of 1.40
"sap_bluecrystal",

// Legacy HCB theme, part of every library, deprecated as of 1.46
"sap_hcb",

// Legacy themes, removed with 1.48
"sap_goldreflection",
"sap_platinum",
"sap_ux",
];

export const deprecatedComponents: string[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!Doctype HTML>
<html>
<head>
<title>Declarative Programming for SAPUI5</title>
<script id="sap-ui-bootstrap"
type="text/javascript"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_belize_hcw"
data-sap-ui-async="true"
data-sap-ui-compat-version="edge"
>
</script>
</head>
<body class="sapUiBody">
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!Doctype HTML>
<html>
<head>
<title>Declarative Programming for SAPUI5</title>
<script id="sap-ui-bootstrap"
type="text/javascript"
src="resources/sap-ui-core.js"
data-sap-ui-theme="sap_platinum"
data-sap-ui-async="true"
data-sap-ui-compat-version="edge"
>
</script>
</head>
<body class="sapUiBody">
</body>
</html>
51 changes: 50 additions & 1 deletion test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Generated by [AVA](https://avajs.dev).
column: 22,
line: 13,
message: 'Use of deprecated theme \'sap_bluecrystal\'',
ruleId: 'no-deprecated-library',
messageDetails: 'Deprecated Themes and Libraries (https://ui5.sap.com/#/topic/a87ca843bcee469f82a9072927a7dcdb)',
ruleId: 'no-deprecated-theme',
severity: 2,
},
{
Expand Down Expand Up @@ -137,6 +138,54 @@ Generated by [AVA](https://avajs.dev).
},
]

## General: BootstrapParameters_Deprecations4.html

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 1,
fatalErrorCount: 0,
filePath: 'BootstrapParameters_Deprecations4.html',
messages: [
{
column: 22,
line: 8,
message: 'Use of deprecated theme \'sap_belize_hcw\'',
messageDetails: 'Deprecated Themes and Libraries (https://ui5.sap.com/#/topic/a87ca843bcee469f82a9072927a7dcdb)',
ruleId: 'no-deprecated-theme',
severity: 2,
},
],
warningCount: 0,
},
]

## General: BootstrapParameters_Deprecations5.html

> Snapshot 1
[
{
coverageInfo: [],
errorCount: 1,
fatalErrorCount: 0,
filePath: 'BootstrapParameters_Deprecations5.html',
messages: [
{
column: 22,
line: 8,
message: 'Use of deprecated theme \'sap_platinum\'',
messageDetails: 'Deprecated Themes and Libraries (https://ui5.sap.com/#/topic/a87ca843bcee469f82a9072927a7dcdb)',
ruleId: 'no-deprecated-theme',
severity: 2,
},
],
warningCount: 0,
},
]

## General: BootstrapParameters_MultipleScripts.html

> Snapshot 1
Expand Down
Binary file modified test/lib/linter/rules/snapshots/NoDeprecatedApi.ts.snap
Binary file not shown.

0 comments on commit 0a30673

Please sign in to comment.