Require switch blocks when declaring variables

pull/3188/head
Anton 2024-02-10 16:51:46 +01:00
parent 49fbc6a252
commit f1d3438d1c
10 changed files with 26 additions and 15 deletions

View File

@ -142,7 +142,6 @@
"SwitchCase": 1 "SwitchCase": 1
} }
], ],
"no-case-declarations": "off",
"no-constant-condition": "off", "no-constant-condition": "off",
"no-delete-var": "off", "no-delete-var": "off",
"no-empty": "off", "no-empty": "off",

View File

@ -369,7 +369,7 @@ function buttonPress(val) {
} }
hasPressedNumber = false; hasPressedNumber = false;
break; break;
default: default: {
specials.R.val = 'C'; specials.R.val = 'C';
if (!swipeEnabled) drawKey('R', specials.R); if (!swipeEnabled) drawKey('R', specials.R);
const is0Negative = (currNumber === 0 && 1/currNumber === -Infinity); const is0Negative = (currNumber === 0 && 1/currNumber === -Infinity);
@ -385,6 +385,7 @@ function buttonPress(val) {
hasPressedNumber = currNumber; hasPressedNumber = currNumber;
displayOutput(currNumber); displayOutput(currNumber);
break; break;
}
} }
} }

View File

@ -99,7 +99,7 @@ const sameDay = function(d1, d2) {
const drawEvent = function(ev, curDay, x1, y1, x2, y2) { const drawEvent = function(ev, curDay, x1, y1, x2, y2) {
"ram"; "ram";
switch(ev.type) { switch(ev.type) {
case "e": // alarm/event case "e": { // alarm/event
const hour = 0|ev.date.getHours() + 0|ev.date.getMinutes()/60.0; const hour = 0|ev.date.getHours() + 0|ev.date.getMinutes()/60.0;
const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59 const slice = hour/24*(eventsPerDay-1); // slice 0 for 0:00 up to eventsPerDay for 23:59
const height = (y2-2) - (y1+2); // height of a cell const height = (y2-2) - (y1+2); // height of a cell
@ -107,6 +107,7 @@ const drawEvent = function(ev, curDay, x1, y1, x2, y2) {
const ystart = (y1+2) + slice*sliceHeight; const ystart = (y1+2) + slice*sliceHeight;
g.setColor(bgEvent).fillRect(x1+1, ystart, x2-2, ystart+sliceHeight); g.setColor(bgEvent).fillRect(x1+1, ystart, x2-2, ystart+sliceHeight);
break; break;
}
case "h": // holiday case "h": // holiday
g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1); g.setColor(bgColorWeekend).fillRect(x1+1, y1+1, x2-1, y2-1);
break; break;

View File

@ -64,13 +64,14 @@
switch (true) { switch (true) {
case (Radius > outerRadius): Color = '#000000'; break; case (Radius > outerRadius): Color = '#000000'; break;
case (Radius < innerRadius): Color = '#FFFFFF'; break; case (Radius < innerRadius): Color = '#FFFFFF'; break;
default: default: {
let Phi = Math.atan2(dy,dx) + halfPi; let Phi = Math.atan2(dy,dx) + halfPi;
if (Phi < 0) { Phi += twoPi; } if (Phi < 0) { Phi += twoPi; }
if (Phi > twoPi) { Phi -= twoPi; } if (Phi > twoPi) { Phi -= twoPi; }
let Index = Math.floor(12*Phi/twoPi); let Index = Math.floor(12*Phi/twoPi);
Color = ColorList[Index]; Color = ColorList[Index];
}
} }
g.setColor(1,1,1); g.setColor(1,1,1);
g.fillCircle(CenterX,CenterY, innerRadius); g.fillCircle(CenterX,CenterY, innerRadius);

View File

@ -894,7 +894,7 @@
g.setFontAlign(-1,0); g.setFontAlign(-1,0);
g.drawString('9', CenterX-outerRadius,CenterY); g.drawString('9', CenterX-outerRadius,CenterY);
break; break;
case '1-12': case '1-12': {
let innerRadius = outerRadius * 0.9 - 10; let innerRadius = outerRadius * 0.9 - 10;
let dark = g.theme.dark; let dark = g.theme.dark;
@ -942,6 +942,7 @@
g.drawString(i == 0 ? '12' : '' + i, x,y); g.drawString(i == 0 ? '12' : '' + i, x,y);
} }
}
} }
let now = new Date(); let now = new Date();

View File

@ -136,19 +136,21 @@ function rIcon(l) {
const x2 = l.x+l.w-1, const x2 = l.x+l.w-1,
y2 = l.y+l.h-1; y2 = l.y+l.h-1;
switch(l.icon) { switch(l.icon) {
case "pause": case "pause": {
const w13 = l.w/3; const w13 = l.w/3;
g.drawRect(l.x, l.y, l.x+w13, y2); g.drawRect(l.x, l.y, l.x+w13, y2);
g.drawRect(l.x+l.w-w13, l.y, x2, y2); g.drawRect(l.x+l.w-w13, l.y, x2, y2);
break; break;
case "play": }
case "play": {
g.drawPoly([ g.drawPoly([
l.x, l.y, l.x, l.y,
x2, l.y+l.h/2, x2, l.y+l.h/2,
l.x, y2, l.x, y2,
], true); ], true);
break; break;
case "previous": }
case "previous": {
const w15 = l.w*1/5; const w15 = l.w*1/5;
g.drawPoly([ g.drawPoly([
x2, l.y, x2, l.y,
@ -157,7 +159,8 @@ function rIcon(l) {
], true); ], true);
g.drawRect(l.x, l.y, l.x+w15, y2); g.drawRect(l.x, l.y, l.x+w15, y2);
break; break;
case "next": }
case "next": {
const w45 = l.w*4/5; const w45 = l.w*4/5;
g.drawPoly([ g.drawPoly([
l.x, l.y, l.x, l.y,
@ -166,12 +169,14 @@ function rIcon(l) {
], true); ], true);
g.drawRect(l.x+w45, l.y, x2, y2); g.drawRect(l.x+w45, l.y, x2, y2);
break; break;
default: // red X }
default: { // red X
console.log(`Unknown icon: ${l.icon}`); console.log(`Unknown icon: ${l.icon}`);
g.setColor("#f00") g.setColor("#f00")
.drawRect(l.x, l.y, x2, y2) .drawRect(l.x, l.y, x2, y2)
.drawLine(l.x, l.y, x2, y2) .drawLine(l.x, l.y, x2, y2)
.drawLine(l.x, y2, x2, l.y); .drawLine(l.x, y2, x2, l.y);
}
} }
} }
let layout; let layout;

View File

@ -134,11 +134,12 @@ function truncStr(str, max) {
function phoneInbound(evt) { function phoneInbound(evt) {
switch (evt.t) { switch (evt.t) {
case 'notify': case 'notify': {
const sender = truncStr(evt.sender, 10); const sender = truncStr(evt.sender, 10);
const subject = truncStr(evt.subject, 15); const subject = truncStr(evt.subject, 15);
phoneNewMessage("notify", `${sender} - '${subject}'`); phoneNewMessage("notify", `${sender} - '${subject}'`);
break; break;
}
case 'call': case 'call':
if (evt.cmd === "accept") { if (evt.cmd === "accept") {
let nameOrNumber = "Unknown"; let nameOrNumber = "Unknown";

View File

@ -54,7 +54,7 @@ let manageEvent = function(ovr, event) {
showMessage(ovr, event); showMessage(ovr, event);
break; break;
case "modify": case "modify": {
let find = false; let find = false;
eventQueue.forEach(element => { eventQueue.forEach(element => {
if (element.id == event.id) { if (element.id == event.id) {
@ -68,7 +68,7 @@ let manageEvent = function(ovr, event) {
if (!callInProgress) if (!callInProgress)
showMessage(ovr, event); showMessage(ovr, event);
break; break;
}
case "remove": case "remove":
if (eventQueue.length == 0 && !callInProgress) if (eventQueue.length == 0 && !callInProgress)
next(ovr); next(ovr);

View File

@ -318,7 +318,7 @@ function handleInput(button) {
showSettingsMenu(); showSettingsMenu();
return; return;
case 3: case 3:
case 4: case 4: {
let hLimit = currentSet() - setsPerPage() + 1; let hLimit = currentSet() - setsPerPage() + 1;
let lLimit = 0; let lLimit = 0;
let val = (button * 2 - 7); let val = (button * 2 - 7);
@ -326,6 +326,7 @@ function handleInput(button) {
if (firstShownSet > hLimit) firstShownSet = hLimit; if (firstShownSet > hLimit) firstShownSet = hLimit;
if (firstShownSet < lLimit) firstShownSet = lLimit; if (firstShownSet < lLimit) firstShownSet = lLimit;
break; break;
}
} }
draw(); draw();

View File

@ -1391,13 +1391,14 @@ function initLevel(aRandomSeed, noLoading) {
boardWidth = 10; boardWidth = 10;
boardHeight = 8; boardHeight = 8;
break; break;
case DIFFRANDOM: case DIFFRANDOM: {
let rnd = random(255); let rnd = random(255);
boardWidth = 5 + (rnd % (MAXBOARDWIDTH - 5 + 1)); //5 is smallest level width from very easy boardWidth = 5 + (rnd % (MAXBOARDWIDTH - 5 + 1)); //5 is smallest level width from very easy
rnd = random(255); rnd = random(255);
boardHeight = 5 + (rnd % (MAXBOARDHEIGHT - 5 + 1)); //5 is smallest level height from very easy boardHeight = 5 + (rnd % (MAXBOARDHEIGHT - 5 + 1)); //5 is smallest level height from very easy
maxLevel = 0; //special value with random maxLevel = 0; //special value with random
break; break;
}
} }
//add space for arrows based on same posadd value (1 or 0 depending if sliding is allowed) //add space for arrows based on same posadd value (1 or 0 depending if sliding is allowed)
boardWidth -= posAdd + posAdd; boardWidth -= posAdd + posAdd;