From 1c42ae9af468e9f83b0b4f61dad85c381ef350f4 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 26 May 2026 16:42:48 +0000 Subject: [PATCH] Add brace-style lint rule and fix violations Enforce 1tbs brace style with allowSingleLine per #5900. Auto-fix else/catch brace placement across the codebase and move a comment in font.ts that blocked else-if formatting. Co-authored-by: Daniel Imms --- addons/addon-ligatures/src/font.ts | 5 ++--- addons/addon-serialize/src/SerializeAddon.ts | 21 +++++++------------- demo/client/client.ts | 3 +-- eslint.config.mjs | 1 + src/browser/CoreBrowserTerminal.ts | 3 +-- src/common/Color.ts | 3 +-- src/common/InputHandler.ts | 3 +-- src/common/buffer/CellData.ts | 12 ++++------- src/common/input/Keyboard.ts | 9 +++------ src/common/input/TextDecoder.ts | 3 +-- 10 files changed, 22 insertions(+), 41 deletions(-) diff --git a/addons/addon-ligatures/src/font.ts b/addons/addon-ligatures/src/font.ts index 60ab3d746..663313b12 100644 --- a/addons/addon-ligatures/src/font.ts +++ b/addons/addon-ligatures/src/font.ts @@ -65,9 +65,8 @@ export default async function load(fontFamily: string, cacheSize: number): Promi console.error(err.name, err.message); } } - } - // Latest proposal https://bugs.chromium.org/p/chromium/issues/detail?id=1312603 - else if (typeof window !== 'undefined' && 'queryLocalFonts' in window) { + } else if (typeof window !== 'undefined' && 'queryLocalFonts' in window) { + // Latest proposal https://bugs.chromium.org/p/chromium/issues/detail?id=1312603 const fonts: Record = {}; try { const fontsIterator = await (window as any).queryLocalFonts(); diff --git a/addons/addon-serialize/src/SerializeAddon.ts b/addons/addon-serialize/src/SerializeAddon.ts index 4980c8eda..d7130040a 100644 --- a/addons/addon-serialize/src/SerializeAddon.ts +++ b/addons/addon-serialize/src/SerializeAddon.ts @@ -291,21 +291,15 @@ class StringSerializeHandler extends BaseSerializeHandler { } else { if (fgChanged) { const color = cell.getFgColor(); - if (cell.isFgRGB()) { sgrSeq.push(38, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } - else if (cell.isFgPalette()) { - if (color >= 16) { sgrSeq.push(38, 5, color); } - else { sgrSeq.push(color & 8 ? 90 + (color & 7) : 30 + (color & 7)); } - } - else { sgrSeq.push(39); } + if (cell.isFgRGB()) { sgrSeq.push(38, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } else if (cell.isFgPalette()) { + if (color >= 16) { sgrSeq.push(38, 5, color); } else { sgrSeq.push(color & 8 ? 90 + (color & 7) : 30 + (color & 7)); } + } else { sgrSeq.push(39); } } if (bgChanged) { const color = cell.getBgColor(); - if (cell.isBgRGB()) { sgrSeq.push(48, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } - else if (cell.isBgPalette()) { - if (color >= 16) { sgrSeq.push(48, 5, color); } - else { sgrSeq.push(color & 8 ? 100 + (color & 7) : 40 + (color & 7)); } - } - else { sgrSeq.push(49); } + if (cell.isBgRGB()) { sgrSeq.push(48, 2, (color >>> 16) & 0xFF, (color >>> 8) & 0xFF, color & 0xFF); } else if (cell.isBgPalette()) { + if (color >= 16) { sgrSeq.push(48, 5, color); } else { sgrSeq.push(color & 8 ? 100 + (color & 7) : 40 + (color & 7)); } + } else { sgrSeq.push(49); } } if (flagsChanged) { if (cell.isInverse() !== oldCell.isInverse()) { sgrSeq.push(cell.isInverse() ? 7 : 27); } @@ -646,8 +640,7 @@ export class HTMLSerializeHandler extends BaseSerializeHandler { // For xterm headless: fallback to ansi colors if ((_terminal as any)._core._themeService) { this._ansiColors = (_terminal as any)._core._themeService.colors.ansi; - } - else { + } else { this._ansiColors = DEFAULT_ANSI_COLORS; } } diff --git a/demo/client/client.ts b/demo/client/client.ts index aab723b7e..890d21781 100644 --- a/demo/client/client.ts +++ b/demo/client/client.ts @@ -521,8 +521,7 @@ function initAddons(term: Terminal): void { } else if (name === 'webLinks') { controlBar.setTabVisible('addon-web-links', true); } - } - catch { + } catch { addon.instance = undefined; checkbox.checked = false; checkbox.disabled = true; diff --git a/eslint.config.mjs b/eslint.config.mjs index b73eece7a..b92202ba7 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -128,6 +128,7 @@ export default tseslint.config( 'no-fallthrough': 'off', 'prefer-spread': 'off', 'object-curly-spacing': ['warn', 'always'], + 'brace-style': ['warn', '1tbs', { allowSingleLine: true }], 'prefer-const': 'warn', 'spaced-comment': ['warn', 'always', { markers: ['/'], exceptions: ['-'] }] } diff --git a/src/browser/CoreBrowserTerminal.ts b/src/browser/CoreBrowserTerminal.ts index 52eb00025..953f30180 100644 --- a/src/browser/CoreBrowserTerminal.ts +++ b/src/browser/CoreBrowserTerminal.ts @@ -563,8 +563,7 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal { try { this._onWillOpen.fire(this.element); - } - catch { /* fails to load addon for some reason */ } + } catch { /* fails to load addon for some reason */ } if (!this._renderService.hasRenderer()) { this._renderService.setRenderer(this._createRenderer()); } diff --git a/src/common/Color.ts b/src/common/Color.ts index b3d13fc99..cbe5044ae 100644 --- a/src/common/Color.ts +++ b/src/common/Color.ts @@ -132,8 +132,7 @@ export namespace css { $ctx.globalCompositeOperation = 'copy'; $litmusColor = $ctx.createLinearGradient(0, 0, 1, 1); } - } - catch { + } catch { // noop } diff --git a/src/common/InputHandler.ts b/src/common/InputHandler.ts index 2b7142dd0..53d0ef280 100644 --- a/src/common/InputHandler.ts +++ b/src/common/InputHandler.ts @@ -1268,8 +1268,7 @@ export class InputHandler extends Disposable implements IInputHandler { for (; j >= 0; j--) { this._bufferService.scroll(this._eraseAttrData()); } - } - else { + } else { j = this._bufferService.rows; this._dirtyRowTracker.markDirty(j - 1); while (j--) { diff --git a/src/common/buffer/CellData.ts b/src/common/buffer/CellData.ts index 43c4c594b..4910d3044 100644 --- a/src/common/buffer/CellData.ts +++ b/src/common/buffer/CellData.ts @@ -62,8 +62,7 @@ export class CellData extends AttributeData implements ICellData { // surrogates and combined strings need special treatment if (value[CHAR_DATA_CHAR_INDEX].length > 2) { combined = true; - } - else if (value[CHAR_DATA_CHAR_INDEX].length === 2) { + } else if (value[CHAR_DATA_CHAR_INDEX].length === 2) { const code = value[CHAR_DATA_CHAR_INDEX].charCodeAt(0); // if the 2-char string is a surrogate create single codepoint // everything else is combined @@ -71,16 +70,13 @@ export class CellData extends AttributeData implements ICellData { const second = value[CHAR_DATA_CHAR_INDEX].charCodeAt(1); if (0xDC00 <= second && second <= 0xDFFF) { this.content = ((code - 0xD800) * 0x400 + second - 0xDC00 + 0x10000) | (value[CHAR_DATA_WIDTH_INDEX] << Content.WIDTH_SHIFT); - } - else { + } else { combined = true; } - } - else { + } else { combined = true; } - } - else { + } else { this.content = value[CHAR_DATA_CHAR_INDEX].charCodeAt(0) | (value[CHAR_DATA_WIDTH_INDEX] << Content.WIDTH_SHIFT); } if (combined) { diff --git a/src/common/input/Keyboard.ts b/src/common/input/Keyboard.ts index 545b436c8..5abdb95ff 100644 --- a/src/common/input/Keyboard.ts +++ b/src/common/input/Keyboard.ts @@ -58,22 +58,19 @@ export function evaluateKeyboardEvent( } else { result.key = C0.ESC + '[A'; } - } - else if (ev.key === 'UIKeyInputLeftArrow') { + } else if (ev.key === 'UIKeyInputLeftArrow') { if (applicationCursorMode) { result.key = C0.ESC + 'OD'; } else { result.key = C0.ESC + '[D'; } - } - else if (ev.key === 'UIKeyInputRightArrow') { + } else if (ev.key === 'UIKeyInputRightArrow') { if (applicationCursorMode) { result.key = C0.ESC + 'OC'; } else { result.key = C0.ESC + '[C'; } - } - else if (ev.key === 'UIKeyInputDownArrow') { + } else if (ev.key === 'UIKeyInputDownArrow') { if (applicationCursorMode) { result.key = C0.ESC + 'OB'; } else { diff --git a/src/common/input/TextDecoder.ts b/src/common/input/TextDecoder.ts index 7ec9c7cd2..601e3e759 100644 --- a/src/common/input/TextDecoder.ts +++ b/src/common/input/TextDecoder.ts @@ -230,8 +230,7 @@ export class Utf8ToUtf32 { && !((byte1 = input[i]) & 0x80) && !((byte2 = input[i + 1]) & 0x80) && !((byte3 = input[i + 2]) & 0x80) - && !((byte4 = input[i + 3]) & 0x80)) - { + && !((byte4 = input[i + 3]) & 0x80)) { target[size++] = byte1; target[size++] = byte2; target[size++] = byte3;