Skip to content

Commit 44d7fee

Browse files
fix: sonar fixes (#223)
1 parent 3849a3a commit 44d7fee

File tree

11 files changed

+22
-26
lines changed

11 files changed

+22
-26
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.initCrowdIn('LizardByte-docs', null);
1+
globalThis.initCrowdIn('LizardByte-docs', null);

examples/jekyll/assets/js/discord-init.js

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
window.initCrowdIn('LizardByte-docs', 'sphinx')
1+
globalThis.initCrowdIn('LizardByte-docs', 'sphinx')

src/js/format-number.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ function formatNumber(num, decimalPlaces = 1) {
1515
}
1616

1717
// Expose to the global scope
18-
if (typeof window !== 'undefined') {
19-
window.formatNumber = formatNumber;
18+
if (globalThis.window !== undefined) {
19+
globalThis.formatNumber = formatNumber;
2020
}
2121

2222
module.exports = formatNumber;

src/js/levenshtein-distance.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ function levenshteinDistance(a, b) {
4040
}
4141

4242
// Expose to the global scope
43-
if (typeof window !== 'undefined') {
44-
window.levenshteinDistance = levenshteinDistance;
43+
if (globalThis.window !== undefined) {
44+
globalThis.levenshteinDistance = levenshteinDistance;
4545
}
4646

4747
module.exports = levenshteinDistance;

src/js/load-script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ function loadScript(url, callback) {
2020
}
2121

2222
// Expose to the global scope
23-
if (typeof window !== 'undefined') {
24-
window.loadScript = loadScript;
23+
if (globalThis.window !== undefined) {
24+
globalThis.loadScript = loadScript;
2525
}
2626

2727
module.exports = loadScript;

src/js/ranking-sorter.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@ function rankingSorter(firstKey, secondKey) {
1010
return -1;
1111
} else if (a[firstKey] < b[firstKey]) {
1212
return 1;
13-
}
14-
else {
15-
if (a[secondKey] > b[secondKey]) {
16-
return 1;
17-
} else if (a[secondKey] < b[secondKey]) {
18-
return -1;
19-
} else {
20-
return 0;
21-
}
13+
} else if (a[secondKey] > b[secondKey]) {
14+
return 1;
15+
} else if (a[secondKey] < b[secondKey]) {
16+
return -1;
17+
} else {
18+
return 0;
2219
}
2320
}
2421
}
2522

2623
// Expose to the global scope
27-
if (typeof window !== 'undefined') {
28-
window.rankingSorter = rankingSorter;
24+
if (globalThis.window !== undefined) {
25+
globalThis.rankingSorter = rankingSorter;
2926
}
3027

3128
module.exports = rankingSorter;

src/js/sleep.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ function sleep(ms) {
88
}
99

1010
// Expose to the global scope
11-
if (typeof window !== 'undefined') {
12-
window.sleep = sleep;
11+
if (globalThis.window !== undefined) {
12+
globalThis.sleep = sleep;
1313
}
1414

1515
module.exports = sleep;

tests/crowdin.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('initCrowdIn', () => {
4949
afterEach(() => {
5050
jest.clearAllMocks();
5151
jest.useRealTimers();
52-
delete global.window.proxyTranslator;
52+
delete globalThis.window.proxyTranslator;
5353
delete globalThis._crowdinMirrorInstalled;
5454
});
5555

@@ -84,7 +84,7 @@ describe('initCrowdIn', () => {
8484
// Simulate script loading
8585
jest.runAllTimers();
8686

87-
expect(window.proxyTranslator.init).toHaveBeenCalledWith(
87+
expect(globalThis.proxyTranslator.init).toHaveBeenCalledWith(
8888
expect.objectContaining({
8989
baseUrl: "http://localhost",
9090
distribution: "d6c830ba4b41106fefe5d391bw4",

tests/sleep.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('sleep function', () => {
1616
})
1717

1818
beforeEach(() => {
19-
jest.spyOn(global, 'setTimeout');
19+
jest.spyOn(globalThis, 'setTimeout');
2020
});
2121

2222
test.each([

0 commit comments

Comments
 (0)