Skip to content

Commit e1f1ade

Browse files
authored
Update plugin.ts
security fixes
1 parent b537228 commit e1f1ade

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/plugins/starfieldScreensaver/plugin.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ interface Star {
1414
}
1515

1616
function randomBetween(min: number, max: number): number {
17-
// NOSONAR: Math.random() is used purely for cosmetic star placement/timing,
18-
// not for any security-sensitive purpose.
19-
return min + Math.random() * (max - min);
17+
// Cosmetic randomness only (star position/timing) - not security-sensitive.
18+
return min + Math.random() * (max - min); // NOSONAR
2019
}
2120

2221
function easeInOut(t: number): number {
@@ -57,7 +56,7 @@ class StarfieldScreensaver {
5756
private lastFrameTime = 0;
5857
private prefersReducedMotion = false;
5958

60-
private spawnStar = (): void => {
59+
private readonly spawnStar = (): void => {
6160
if (!this.width || !this.height) return;
6261

6362
const fadeIn = randomBetween(600, 1600);
@@ -78,7 +77,7 @@ class StarfieldScreensaver {
7877
});
7978
};
8079

81-
private scheduleNextSpawn = (delayOverride?: number): void => {
80+
private readonly scheduleNextSpawn = (delayOverride?: number): void => {
8281
const delay = delayOverride ?? randomBetween(80, 260);
8382

8483
this.spawnTimeoutId = setTimeout(() => {
@@ -93,7 +92,7 @@ class StarfieldScreensaver {
9392
}, delay);
9493
};
9594

96-
private draw = (dt: number): void => {
95+
private readonly draw = (dt: number): void => {
9796
const { ctx } = this;
9897
if (!ctx) return;
9998

@@ -125,7 +124,7 @@ class StarfieldScreensaver {
125124
}
126125
};
127126

128-
private tick = (now: number): void => {
127+
private readonly tick = (now: number): void => {
129128
const dt = now - (this.lastFrameTime || now);
130129
this.lastFrameTime = now;
131130

@@ -134,7 +133,7 @@ class StarfieldScreensaver {
134133
this.rafId = requestAnimationFrame(this.tick);
135134
};
136135

137-
private resizeCanvas = (): void => {
136+
private readonly resizeCanvas = (): void => {
138137
const { canvas, ctx } = this;
139138
if (!canvas || !ctx) return;
140139

@@ -186,7 +185,7 @@ class StarfieldScreensaver {
186185
}
187186
}
188187

189-
show = (): void => {
188+
readonly show = (): void => {
190189
this.prefersReducedMotion = !!window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
191190

192191
this.buildDom();
@@ -201,7 +200,7 @@ class StarfieldScreensaver {
201200
this.rafId = requestAnimationFrame(this.tick);
202201
};
203202

204-
hide = (): Promise<void> => {
203+
readonly hide = (): Promise<void> => {
205204
this.stopTimers();
206205

207206
this.container?.remove();

0 commit comments

Comments
 (0)