Skip to content

Commit ef03dd2

Browse files
refactor(sonar): fix javascript:S5906
1 parent 5d456ae commit ef03dd2

6 files changed

Lines changed: 32 additions & 31 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<a href="https://github.com/LizardByte/GameDB/actions/workflows/ci-tests.yml?query=branch%3Amaster"><img src="https://img.shields.io/github/actions/workflow/status/lizardbyte/gamedb/ci-tests.yml.svg?branch=master&label=CI&logo=github&style=for-the-badge" alt="CI"></a>
88
<a href="https://github.com/LizardByte/GameDB/actions/workflows/update-db.yml?query=branch%3Amaster"><img src="https://img.shields.io/github/actions/workflow/status/lizardbyte/gamedb/update-db.yml.svg?branch=master&label=update%20db&logo=github&style=for-the-badge" alt="Update DB"></a>
99
<a href="https://app.codecov.io/gh/LizardByte/GameDB"><img src="https://img.shields.io/codecov/c/gh/LizardByte/GameDB.svg?token=AG91ICECDX&style=for-the-badge&logo=codecov&label=codecov" alt="Codecov"></a>
10+
<a href="https://sonarcloud.io/project/overview?id=LizardByte_GameDB"><img src="https://img.shields.io/sonar/quality_gate/LizardByte_GameDB?server=https%3A%2F%2Fsonarcloud.io&style=for-the-badge&logo=sonarqubecloud&label=sonarcloud" alt="SonarCloud"></a>
1011
</div>
1112

1213
---

tests/character_detail.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('character_detail.js', () => {
9393

9494
test('skips badges when gender and species absent', () => {
9595
renderCharacter({ name: 'Robot' });
96-
expect(document.getElementById('character-badges').children.length).toBe(0);
96+
expect(document.getElementById('character-badges').children).toHaveLength(0);
9797
});
9898

9999
test('shows games section when games present', () => {

tests/game_detail.test.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ describe('game_detail.js', () => {
107107
game_modes: [{ name: 'Single player' }],
108108
player_perspectives: [{ name: 'First person' }],
109109
});
110-
expect(document.getElementById('game-badges').children.length).toBe(4);
110+
expect(document.getElementById('game-badges').children).toHaveLength(4);
111111
});
112112

113113
test('handles missing badge arrays gracefully', () => {
114114
renderGameBadges({});
115-
expect(document.getElementById('game-badges').children.length).toBe(0);
115+
expect(document.getElementById('game-badges').children).toHaveLength(0);
116116
});
117117
});
118118

@@ -136,15 +136,15 @@ describe('game_detail.js', () => {
136136
test('skips when no ratings', () => {
137137
const dl = document.getElementById('game-meta');
138138
renderGameRatings({}, dl);
139-
expect(dl.children.length).toBe(0);
139+
expect(dl.children).toHaveLength(0);
140140
});
141141

142142
test('skips age ratings row when all entries are incomplete', () => {
143143
const dl = document.getElementById('game-meta');
144144
renderGameRatings({
145145
age_ratings: [{ rating_category: null, organization: null }],
146146
}, dl);
147-
expect(dl.children.length).toBe(0);
147+
expect(dl.children).toHaveLength(0);
148148
});
149149
});
150150

@@ -174,7 +174,7 @@ describe('game_detail.js', () => {
174174
test('skips when no platforms', () => {
175175
const dl = document.getElementById('game-meta');
176176
renderGamePlatforms({}, dl);
177-
expect(dl.children.length).toBe(0);
177+
expect(dl.children).toHaveLength(0);
178178
});
179179
});
180180

@@ -195,13 +195,13 @@ describe('game_detail.js', () => {
195195
test('skips when no release dates', () => {
196196
const dl = document.getElementById('game-meta');
197197
renderReleaseDates({}, dl);
198-
expect(dl.children.length).toBe(0);
198+
expect(dl.children).toHaveLength(0);
199199
});
200200

201201
test('skips row when all entries lack date and y', () => {
202202
const dl = document.getElementById('game-meta');
203203
renderReleaseDates({ release_dates: [{ date: null, y: null }] }, dl);
204-
expect(dl.children.length).toBe(0);
204+
expect(dl.children).toHaveLength(0);
205205
});
206206

207207
test('renders release date with unknown release_region (empty flag)', () => {
@@ -239,13 +239,13 @@ describe('game_detail.js', () => {
239239
test('skips when no involved companies', () => {
240240
const dl = document.getElementById('game-meta');
241241
renderCompanies({}, dl);
242-
expect(dl.children.length).toBe(0);
242+
expect(dl.children).toHaveLength(0);
243243
});
244244

245245
test('skips rows when devs or pubs list is empty', () => {
246246
const dl = document.getElementById('game-meta');
247247
renderCompanies({ involved_companies: [] }, dl);
248-
expect(dl.children.length).toBe(0);
248+
expect(dl.children).toHaveLength(0);
249249
});
250250
});
251251

@@ -302,7 +302,7 @@ describe('game_detail.js', () => {
302302
test('skips franchise when neither franchises array nor franchise object', () => {
303303
const dl = document.getElementById('game-meta');
304304
renderCollectionsAndFranchises({}, dl);
305-
expect(dl.children.length).toBe(0);
305+
expect(dl.children).toHaveLength(0);
306306
});
307307
});
308308

@@ -318,13 +318,13 @@ describe('game_detail.js', () => {
318318
test('skips when no multiplayer modes', () => {
319319
const dl = document.getElementById('game-meta');
320320
renderMultiplayer({}, dl);
321-
expect(dl.children.length).toBe(0);
321+
expect(dl.children).toHaveLength(0);
322322
});
323323

324324
test('skips when parts are empty', () => {
325325
const dl = document.getElementById('game-meta');
326326
renderMultiplayer({ multiplayer_modes: [{}] }, dl);
327-
expect(dl.children.length).toBe(0);
327+
expect(dl.children).toHaveLength(0);
328328
});
329329
});
330330

@@ -339,7 +339,7 @@ describe('game_detail.js', () => {
339339
const section = document.getElementById('game-screenshots-section');
340340
expect(section.classList.contains('d-none')).toBe(false);
341341
const buttons = document.querySelectorAll('#game-screenshots button');
342-
expect(buttons.length).toBe(2);
342+
expect(buttons).toHaveLength(2);
343343
buttons[0].click();
344344
expect(globalThis.openImageModal).toHaveBeenCalled();
345345
});
@@ -365,7 +365,7 @@ describe('game_detail.js', () => {
365365

366366
test('skips video entries without video_id', () => {
367367
renderVideos({ videos: [{ name: 'No ID' }] });
368-
expect(document.querySelectorAll('#game-videos iframe').length).toBe(0);
368+
expect(document.querySelectorAll('#game-videos iframe')).toHaveLength(0);
369369
});
370370

371371
test('skips when no videos', () => {
@@ -406,7 +406,7 @@ describe('game_detail.js', () => {
406406

407407
test('skips entries with no url and no uid', () => {
408408
renderExternalLinks({ external_games: [{}] });
409-
expect(document.getElementById('game-external').children.length).toBe(0);
409+
expect(document.getElementById('game-external').children).toHaveLength(0);
410410
});
411411

412412
test('skips when no external_games', () => {
@@ -509,7 +509,7 @@ describe('game_detail.js', () => {
509509
introHeader.appendChild(existingDesc);
510510
// Should not add a second img-desc
511511
setupGameBanner({ artworks: [{ url: '//images.igdb.com/t_thumb/art.jpg' }] });
512-
expect(document.querySelectorAll('.intro-header .img-desc').length).toBe(1);
512+
expect(document.querySelectorAll('.intro-header .img-desc')).toHaveLength(1);
513513
});
514514

515515
test('does not throw when artworks present but no .page-heading anywhere', () => {

tests/item_detail.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ describe('item_detail.js', () => {
110110
test('appends dt and dd with string value', () => {
111111
const dl = document.createElement('dl');
112112
addDlRow(dl, 'Developer', 'Test Studio');
113-
expect(dl.children.length).toBe(2);
113+
expect(dl.children).toHaveLength(2);
114114
expect(dl.children[0].tagName).toBe('DT');
115115
expect(dl.children[1].tagName).toBe('DD');
116116
expect(dl.children[0].textContent).toBe('Developer');

tests/item_loader.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ describe('item_loader.js', () => {
6868
test('splits at word boundary when longer than 200 chars', () => {
6969
const long = 'word '.repeat(50); // 250 chars
7070
const result = splitString(long);
71-
expect(result.length).toBe(2);
71+
expect(result).toHaveLength(2);
7272
expect(result[0].length).toBeLessThanOrEqual(200);
7373
expect(result[1]).toBe(long);
7474
});
@@ -137,7 +137,7 @@ describe('item_loader.js', () => {
137137
}, allPlatforms);
138138
// Should show first 3 platforms + "+1 more"
139139
const badges = col.querySelectorAll('.badge');
140-
expect(badges.length).toBe(4); // 3 platforms + "+1 more"
140+
expect(badges).toHaveLength(4); // 3 platforms + "+1 more"
141141
expect(col.textContent).toContain('+1 more');
142142
});
143143

@@ -167,22 +167,22 @@ describe('item_loader.js', () => {
167167
row,
168168
null,
169169
);
170-
expect(row.children.length).toBe(2);
170+
expect(row.children).toHaveLength(2);
171171
});
172172
});
173173

174174
describe('addMoreResultsNote', () => {
175175
test('appends note when total exceeds shown', () => {
176176
const container = document.createElement('div');
177177
addMoreResultsNote(container, 100, 60);
178-
expect(container.children.length).toBe(1);
178+
expect(container.children).toHaveLength(1);
179179
expect(container.textContent).toContain('60');
180180
});
181181

182182
test('does nothing when total equals shown', () => {
183183
const container = document.createElement('div');
184184
addMoreResultsNote(container, 60, 60);
185-
expect(container.children.length).toBe(0);
185+
expect(container.children).toHaveLength(0);
186186
});
187187
});
188188

@@ -294,7 +294,7 @@ describe('item_loader.js', () => {
294294
const para = document.createElement('p');
295295
const footer = document.createElement('div');
296296
addVersionMetadataToFooter({}, para, footer, {}, regionMap, iconMap);
297-
expect(footer.children.length).toBe(0);
297+
expect(footer.children).toHaveLength(0);
298298
});
299299

300300
test('skips metadata key when it has null icon and is not a special key', () => {
@@ -304,7 +304,7 @@ describe('item_loader.js', () => {
304304
const customIconMap = { media: null, platform_version_release_dates: null, summary: null };
305305
addVersionMetadataToFooter({ media: 'Blu-ray' }, para, footer, {}, regionMap, customIconMap);
306306
// Should not add to footer since icon is null and not a special key
307-
expect(footer.children.length).toBe(0);
307+
expect(footer.children).toHaveLength(0);
308308
});
309309
});
310310

tests/platform_detail.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,22 @@ describe('platform_detail.js', () => {
9292
test('renders category and generation badges', () => {
9393
renderPlatformBadges({ category: 1, generation: 9 });
9494
const badges = document.getElementById('platform-badges');
95-
expect(badges.children.length).toBe(2);
95+
expect(badges.children).toHaveLength(2);
9696
});
9797

9898
test('renders only category when no generation', () => {
9999
renderPlatformBadges({ category: 2 });
100-
expect(document.getElementById('platform-badges').children.length).toBe(1);
100+
expect(document.getElementById('platform-badges').children).toHaveLength(1);
101101
});
102102

103103
test('renders only generation when no category', () => {
104104
renderPlatformBadges({ generation: 8 });
105-
expect(document.getElementById('platform-badges').children.length).toBe(1);
105+
expect(document.getElementById('platform-badges').children).toHaveLength(1);
106106
});
107107

108108
test('renders nothing when no category or generation', () => {
109109
renderPlatformBadges({});
110-
expect(document.getElementById('platform-badges').children.length).toBe(0);
110+
expect(document.getElementById('platform-badges').children).toHaveLength(0);
111111
});
112112

113113
test('renders fallback text for unknown category number', () => {
@@ -144,7 +144,7 @@ describe('platform_detail.js', () => {
144144

145145
test('renders nothing when no data', () => {
146146
renderPlatformMetadata({});
147-
expect(document.getElementById('platform-meta').children.length).toBe(0);
147+
expect(document.getElementById('platform-meta').children).toHaveLength(0);
148148
});
149149
});
150150

@@ -248,7 +248,7 @@ describe('platform_detail.js', () => {
248248
test('renders nothing extra when version is empty', () => {
249249
const body = document.createElement('div');
250250
populateVersionBody(body, {});
251-
expect(body.children.length).toBe(0);
251+
expect(body.children).toHaveLength(0);
252252
});
253253
});
254254

0 commit comments

Comments
 (0)