Skip to content

Commit 0f7f5f3

Browse files
marcoviethlfindlaysapigorsVoronins
authored
fix(eslint): check min UI5 version for rule sap-width-including-column-header (#4470)
* fix(eslint): check min UI5 version for rule sap-width-including-column-header * add changeset * docs: improved wording * update changeset to use patch * Delete .changeset/small-bags-chew.md * Apply suggestions from code review Co-authored-by: Louise Findlay <[email protected]> --------- Co-authored-by: Louise Findlay <[email protected]> Co-authored-by: igorsVoronins <[email protected]>
1 parent 40f5447 commit 0f7f5f3

4 files changed

Lines changed: 46 additions & 4 deletions

File tree

.changeset/public-pandas-guess.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@sap-ux/eslint-plugin-fiori-tools': patch
3+
---
4+
5+
Fix: Check minUI5 version for the sap-width-including-column-header rule

packages/eslint-plugin-fiori-tools/docs/rules/sap-width-including-column-header.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Require `widthIncludingColumnHeader` for Small Tables (`sap-width-including-column-header`)
22

3-
Ensures that small tables (less than six columns) include the `widthIncludingColumnHeader` property set to `true` for improved calculation of the column width.
3+
Ensures that small tables (less than six columns) include the `widthIncludingColumnHeader` property set to `true` for improved calculation of the column width. The rule is applicable to OData V4 applications with a minimum SAPUI5 version of 1.120.
44

55
## Rule Details
66

packages/eslint-plugin-fiori-tools/src/rules/sap-width-including-column-header.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getRecordType } from '../project-context/linker/annotations';
1010
import type { FeV4ObjectPage, FeV4ListReport, Table } from '../project-context/linker/fe-v4';
1111
import type { ParsedApp, ParsedService } from '../project-context/parser';
1212
import { createJsonFixer } from '../language/rule-fixer';
13+
import { isLowerThanMinimalUi5Version } from '../utils/version';
1314

1415
export type RequireWidthIncludingColumnHeaderOptions = {
1516
form: string;
@@ -110,8 +111,14 @@ const rule: FioriRuleDefinition = createFioriRule({
110111
if (app.type !== 'fe-v4') {
111112
continue;
112113
}
114+
const parsedApp = context.sourceCode.projectContext.index.apps[appKey];
115+
if (
116+
!parsedApp.manifest.minUI5Version ||
117+
isLowerThanMinimalUi5Version(parsedApp.manifest.minUI5Version, { major: 1, minor: 120 })
118+
) {
119+
continue;
120+
}
113121
for (const page of app.pages) {
114-
const parsedApp = context.sourceCode.projectContext.index.apps[appKey];
115122
const parsedService = context.sourceCode.projectContext.getIndexedServiceForMainService(parsedApp);
116123
if (!parsedService) {
117124
continue;

packages/eslint-plugin-fiori-tools/test/rules/sap-width-including-column-header.test.ts

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
116116
code: JSON.stringify(V4_MANIFEST)
117117
},
118118
[_6_COLUMNS_ANNOTATIONS]
119+
),
120+
createValidTest(
121+
{
122+
name: 'ui5 version lower than 1.120 - no warning for small table',
123+
filename: V4_MANIFEST_PATH,
124+
code: getManifestAsCode(V4_MANIFEST, [])
125+
},
126+
[ORIGINAL_ANNOTATIONS]
119127
)
120128
],
121129

@@ -124,7 +132,12 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
124132
{
125133
name: 'widthIncludingColumnHeader missing for small table',
126134
filename: V4_MANIFEST_PATH,
127-
code: getManifestAsCode(V4_MANIFEST, []),
135+
code: getManifestAsCode(V4_MANIFEST, [
136+
{
137+
path: ['sap.ui5', 'dependencies', 'minUI5Version'],
138+
value: '1.120.0'
139+
}
140+
]),
128141
errors: [
129142
{
130143
messageId: 'width-including-column-header-manifest',
@@ -133,6 +146,10 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
133146
}
134147
],
135148
output: getManifestAsCode(V4_MANIFEST, [
149+
{
150+
path: ['sap.ui5', 'dependencies', 'minUI5Version'],
151+
value: '1.120.0'
152+
},
136153
{
137154
path: [
138155
'sap.ui5',
@@ -170,7 +187,12 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
170187
[
171188
{
172189
filename: V4_MANIFEST_PATH,
173-
code: JSON.stringify(V4_MANIFEST, undefined, 2)
190+
code: getManifestAsCode(V4_MANIFEST, [
191+
{
192+
path: ['sap.ui5', 'dependencies', 'minUI5Version'],
193+
value: '1.120.0'
194+
}
195+
])
174196
}
175197
]
176198
),
@@ -179,6 +201,10 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
179201
name: 'small object page table',
180202
filename: V4_MANIFEST_PATH,
181203
code: getManifestAsCode(V4_MANIFEST, [
204+
{
205+
path: ['sap.ui5', 'dependencies', 'minUI5Version'],
206+
value: '1.120.0'
207+
},
182208
{
183209
path: [
184210
'sap.ui5',
@@ -203,6 +229,10 @@ ruleTester.run(TEST_NAME, flexEnabledRule, {
203229
}
204230
],
205231
output: getManifestAsCode(V4_MANIFEST, [
232+
{
233+
path: ['sap.ui5', 'dependencies', 'minUI5Version'],
234+
value: '1.120.0'
235+
},
206236
{
207237
path: [
208238
'sap.ui5',

0 commit comments

Comments
 (0)