chore: Enable "curly" rule to avoid single-statement if confusion/errors.

This commit is contained in:
cpojer
2026-01-31 16:19:20 +09:00
parent 009b16fab8
commit 5ceff756e1
1266 changed files with 27871 additions and 9393 deletions

View File

@@ -133,17 +133,23 @@ export function encodeKeySequence(request: KeyEncodingRequest): KeyEncodingResul
}
export function encodePaste(text: string, bracketed = true): string {
if (!bracketed) return text;
if (!bracketed) {
return text;
}
return `${BRACKETED_PASTE_START}${text}${BRACKETED_PASTE_END}`;
}
function encodeKeyToken(raw: string, warnings: string[]): string {
const token = raw.trim();
if (!token) return "";
if (!token) {
return "";
}
if (token.length === 2 && token.startsWith("^")) {
const ctrl = toCtrlChar(token[1]);
if (ctrl) return ctrl;
if (ctrl) {
return ctrl;
}
}
const parsed = parseModifiers(token);
@@ -190,10 +196,15 @@ function parseModifiers(token: string) {
while (rest.length > 2 && rest[1] === "-") {
const mod = rest[0].toLowerCase();
if (mod === "c") mods.ctrl = true;
else if (mod === "m") mods.alt = true;
else if (mod === "s") mods.shift = true;
else break;
if (mod === "c") {
mods.ctrl = true;
} else if (mod === "m") {
mods.alt = true;
} else if (mod === "s") {
mods.shift = true;
} else {
break;
}
sawModifiers = true;
rest = rest.slice(2);
}
@@ -208,7 +219,9 @@ function applyCharModifiers(char: string, mods: Modifiers): string {
}
if (mods.ctrl) {
const ctrl = toCtrlChar(value);
if (ctrl) value = ctrl;
if (ctrl) {
value = ctrl;
}
}
if (mods.alt) {
value = `${ESC}${value}`;
@@ -217,8 +230,12 @@ function applyCharModifiers(char: string, mods: Modifiers): string {
}
function toCtrlChar(char: string): string | null {
if (char.length !== 1) return null;
if (char === "?") return "\x7f";
if (char.length !== 1) {
return null;
}
if (char === "?") {
return "\x7f";
}
const code = char.toUpperCase().charCodeAt(0);
if (code >= 64 && code <= 95) {
return String.fromCharCode(code & 0x1f);
@@ -228,9 +245,15 @@ function toCtrlChar(char: string): string | null {
function xtermModifier(mods: Modifiers): number {
let mod = 1;
if (mods.shift) mod += 1;
if (mods.alt) mod += 2;
if (mods.ctrl) mod += 4;
if (mods.shift) {
mod += 1;
}
if (mods.alt) {
mod += 2;
}
if (mods.ctrl) {
mod += 4;
}
return mod;
}
@@ -259,8 +282,12 @@ function hasAnyModifier(mods: Modifiers): boolean {
function parseHexByte(raw: string): number | null {
const trimmed = raw.trim().toLowerCase();
const normalized = trimmed.startsWith("0x") ? trimmed.slice(2) : trimmed;
if (!/^[0-9a-f]{1,2}$/.test(normalized)) return null;
if (!/^[0-9a-f]{1,2}$/.test(normalized)) {
return null;
}
const value = Number.parseInt(normalized, 16);
if (Number.isNaN(value) || value < 0 || value > 0xff) return null;
if (Number.isNaN(value) || value < 0 || value > 0xff) {
return null;
}
return value;
}