Merge pull request #5639 from Tyriar/nullish

Add @typescript-eslint/prefer-nullish-coalescing eslint rule
This commit is contained in:
Daniel Imms
2026-01-31 09:03:35 -08:00
committed by GitHub
33 changed files with 119 additions and 157 deletions
+4 -4
View File
@@ -793,15 +793,15 @@ export class CoreBrowserTerminal extends CoreTerminal implements ITerminal {
if (!(events & CoreMouseEventType.UP)) {
this._document!.removeEventListener('mouseup', requestedEvents.mouseup!);
requestedEvents.mouseup = null;
} else if (!requestedEvents.mouseup) {
requestedEvents.mouseup = eventListeners.mouseup;
} else {
requestedEvents.mouseup ??= eventListeners.mouseup;
}
if (!(events & CoreMouseEventType.DRAG)) {
this._document!.removeEventListener('mousemove', requestedEvents.mousedrag!);
requestedEvents.mousedrag = null;
} else if (!requestedEvents.mousedrag) {
requestedEvents.mousedrag = eventListeners.mousedrag;
} else {
requestedEvents.mousedrag ??= eventListeners.mousedrag;
}
}));
// force initial onProtocolChange so we dont miss early mouse requests
+2 -2
View File
@@ -40,8 +40,8 @@ export class RenderDebouncer implements IRenderDebouncerWithCallback {
public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
this._rowCount = rowCount;
// Get the min/max row start/end for the arg values
rowStart = rowStart !== undefined ? rowStart : 0;
rowEnd = rowEnd !== undefined ? rowEnd : this._rowCount - 1;
rowStart = rowStart ?? 0;
rowEnd = rowEnd ?? this._rowCount - 1;
// Set the properties to the updated values
this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
+2 -2
View File
@@ -37,8 +37,8 @@ export class TimeBasedDebouncer implements IRenderDebouncer {
public refresh(rowStart: number | undefined, rowEnd: number | undefined, rowCount: number): void {
this._rowCount = rowCount;
// Get the min/max row start/end for the arg values
rowStart = rowStart !== undefined ? rowStart : 0;
rowEnd = rowEnd !== undefined ? rowEnd : this._rowCount - 1;
rowStart = rowStart ?? 0;
rowEnd = rowEnd ?? this._rowCount - 1;
// Set the properties to the updated values
this._rowStart = this._rowStart !== undefined ? Math.min(this._rowStart, rowStart) : rowStart;
this._rowEnd = this._rowEnd !== undefined ? Math.max(this._rowEnd, rowEnd) : rowEnd;
+2 -8
View File
@@ -84,10 +84,7 @@ export class Terminal extends Disposable implements ITerminalApi {
public get element(): HTMLElement | undefined { return this._core.element; }
public get parser(): IParser {
if (!this._parser) {
this._parser = new ParserApi(this._core);
}
return this._parser;
return this._parser ??= new ParserApi(this._core);
}
public get unicode(): IUnicodeHandling {
this._checkProposedApi();
@@ -97,10 +94,7 @@ export class Terminal extends Disposable implements ITerminalApi {
public get rows(): number { return this._core.rows; }
public get cols(): number { return this._core.cols; }
public get buffer(): IBufferNamespaceApi {
if (!this._buffer) {
this._buffer = this._register(new BufferNamespaceApi(this._core));
}
return this._buffer;
return this._buffer ??= this._register(new BufferNamespaceApi(this._core));
}
public get markers(): ReadonlyArray<IMarker> {
return this._core.markers;
@@ -494,8 +494,8 @@ export class DomRendererRowFactory {
// Dim cells only require half the contrast, otherwise they wouldn't be distinguishable from
// non-dim cells
const ratio = this._optionsService.rawOptions.minimumContrastRatio / (cell.isDim() ? 2 : 1);
adjustedColor = color.ensureContrastRatio(bgOverride || bg, fgOverride || fg, ratio);
cache.setColor((bgOverride || bg).rgba, (fgOverride || fg).rgba, adjustedColor ?? null);
adjustedColor = color.ensureContrastRatio(bgOverride ?? bg, fgOverride ?? fg, ratio);
cache.setColor((bgOverride ?? bg).rgba, (fgOverride ?? fg).rgba, adjustedColor ?? null);
}
if (adjustedColor) {
+2 -6
View File
@@ -24,16 +24,12 @@ export class KeyboardService implements IKeyboardService {
}
private _getWin32InputMode(): Win32InputMode {
if (!this._win32InputMode) {
this._win32InputMode = new Win32InputMode();
}
this._win32InputMode ??= new Win32InputMode();
return this._win32InputMode;
}
private _getKittyKeyboard(): KittyKeyboard {
if (!this._kittyKeyboard) {
this._kittyKeyboard = new KittyKeyboard();
}
this._kittyKeyboard ??= new KittyKeyboard();
return this._kittyKeyboard;
}
+5 -7
View File
@@ -347,13 +347,11 @@ class SynchronizedOutputHandler {
this._end = Math.max(this._end, end);
}
if (this._timeout === undefined) {
this._timeout = this._coreBrowserService.window.setTimeout(() => {
this._timeout = undefined;
this._coreService.decPrivateModes.synchronizedOutput = false;
this._onTimeout();
}, Constants.SYNCHRONIZED_OUTPUT_TIMEOUT_MS);
}
this._timeout ??= this._coreBrowserService.window.setTimeout(() => {
this._timeout = undefined;
this._coreService.decPrivateModes.synchronizedOutput = false;
this._onTimeout();
}, Constants.SYNCHRONIZED_OUTPUT_TIMEOUT_MS);
}
public flush(): { start: number, end: number } | undefined {
+27 -26
View File
@@ -18,33 +18,34 @@ export class Emitter<T> {
private _event: IEvent<T> | undefined;
public get event(): IEvent<T> {
if (!this._event) {
this._event = (listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore) => {
if (this._disposed) {
return toDisposable(() => {});
}
const entry = { fn: listener, thisArgs };
this._listeners.push(entry);
const result = toDisposable(() => {
const idx = this._listeners.indexOf(entry);
if (idx !== -1) {
this._listeners.splice(idx, 1);
}
});
if (disposables) {
if (Array.isArray(disposables)) {
disposables.push(result);
} else {
disposables.add(result);
}
}
return result;
};
if (this._event) {
return this._event;
}
this._event = (listener: (e: T) => any, thisArgs?: any, disposables?: IDisposable[] | DisposableStore) => {
if (this._disposed) {
return toDisposable(() => {});
}
const entry = { fn: listener, thisArgs };
this._listeners.push(entry);
const result = toDisposable(() => {
const idx = this._listeners.indexOf(entry);
if (idx !== -1) {
this._listeners.splice(idx, 1);
}
});
if (disposables) {
if (Array.isArray(disposables)) {
disposables.push(result);
} else {
disposables.add(result);
}
}
return result;
};
return this._event;
}
+1 -1
View File
@@ -3343,7 +3343,7 @@ export class InputHandler extends Disposable implements IInputHandler {
if (collectAndFlag[0] === '/') {
return true; // TODO: Is this supported?
}
this._charsetService.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] || DEFAULT_CHARSET);
this._charsetService.setgCharset(GLEVEL[collectAndFlag[0]], CHARSETS[collectAndFlag[1]] ?? DEFAULT_CHARSET);
return true;
}
+3 -9
View File
@@ -122,9 +122,7 @@ export class Buffer implements IBuffer {
*/
public fillViewportRows(fillAttr?: IAttributeData): void {
if (this.lines.length === 0) {
if (fillAttr === undefined) {
fillAttr = DEFAULT_ATTR_DATA;
}
fillAttr ??= DEFAULT_ATTR_DATA;
let i = this._rows;
while (i--) {
this.lines.push(this.getBlankLine(fillAttr));
@@ -589,9 +587,7 @@ export class Buffer implements IBuffer {
* @param x The position to move the cursor to the previous tab stop.
*/
public prevStop(x?: number): number {
if (x === null || x === undefined) {
x = this.x;
}
x ??= this.x;
while (!this.tabs[--x] && x > 0);
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
}
@@ -601,9 +597,7 @@ export class Buffer implements IBuffer {
* @param x The position to move the cursor one tab stop forward.
*/
public nextStop(x?: number): number {
if (x === null || x === undefined) {
x = this.x;
}
x ??= this.x;
while (!this.tabs[++x] && x < this._cols);
return x >= this._cols ? this._cols - 1 : x < 0 ? 0 : x;
}
+1 -1
View File
@@ -66,7 +66,7 @@ export class BufferLine implements IBufferLine {
constructor(cols: number, fillCellData?: ICellData, public isWrapped: boolean = false) {
this._data = new Uint32Array(cols * CELL_SIZE);
const cell = fillCellData || CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
const cell = fillCellData ?? CellData.fromCharData([0, NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE]);
for (let i = 0; i < cols; ++i) {
this.setCell(i, cell);
}
+1 -1
View File
@@ -26,7 +26,7 @@ function testEvaluateKeyboardEvent(partialEvent: {
ctrlKey: partialEvent.ctrlKey || false,
shiftKey: partialEvent.shiftKey || false,
metaKey: partialEvent.metaKey || false,
keyCode: partialEvent.keyCode !== undefined ? partialEvent.keyCode : 0,
keyCode: partialEvent.keyCode ?? 0,
code: partialEvent.code || '',
key: partialEvent.key || '',
type: partialEvent.type || ''
+1 -1
View File
@@ -9,7 +9,7 @@ function createEvent(partialEvent: Partial<IKeyboardEvent> = {}): IKeyboardEvent
ctrlKey: partialEvent.ctrlKey || false,
shiftKey: partialEvent.shiftKey || false,
metaKey: partialEvent.metaKey || false,
keyCode: partialEvent.keyCode !== undefined ? partialEvent.keyCode : 0,
keyCode: partialEvent.keyCode ?? 0,
code: partialEvent.code || '',
key: partialEvent.key || '',
type: partialEvent.type || 'keydown'
+1 -1
View File
@@ -169,7 +169,7 @@ it('wcwidth should match all values from the old implementation', function(): vo
if (num < 127) {
return 1;
}
const t = table || initTable();
const t = table ?? initTable();
if (num < 65536) {
return t[num >> 4] >> ((num & 15) << 1) & 3;
}
+1 -3
View File
@@ -36,9 +36,7 @@ export class ApcParser implements IApcParser {
* @param handler The handler to register
*/
public registerHandler(ident: number, handler: IApcHandler): IDisposable {
if (this._handlers[ident] === undefined) {
this._handlers[ident] = [];
}
this._handlers[ident] ??= [];
const handlerList = this._handlers[ident];
handlerList.push(handler);
return {
+1 -3
View File
@@ -29,9 +29,7 @@ export class DcsParser implements IDcsParser {
}
public registerHandler(ident: number, handler: IDcsHandler): IDisposable {
if (this._handlers[ident] === undefined) {
this._handlers[ident] = [];
}
this._handlers[ident] ??= [];
const handlerList = this._handlers[ident];
handlerList.push(handler);
return {
+2 -6
View File
@@ -362,9 +362,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
public registerEscHandler(id: IFunctionIdentifier, handler: EscHandlerType): IDisposable {
const ident = this._identifier(id, [0x30, 0x7e]);
if (this._escHandlers[ident] === undefined) {
this._escHandlers[ident] = [];
}
this._escHandlers[ident] ??= [];
const handlerList = this._escHandlers[ident];
handlerList.push(handler);
return {
@@ -395,9 +393,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
public registerCsiHandler(id: IFunctionIdentifier, handler: CsiHandlerType): IDisposable {
const ident = this._identifier(id);
if (this._csiHandlers[ident] === undefined) {
this._csiHandlers[ident] = [];
}
this._csiHandlers[ident] ??= [];
const handlerList = this._csiHandlers[ident];
handlerList.push(handler);
return {
+1 -3
View File
@@ -23,9 +23,7 @@ export class OscParser implements IOscParser {
};
public registerHandler(ident: number, handler: IOscHandler): IDisposable {
if (this._handlers[ident] === undefined) {
this._handlers[ident] = [];
}
this._handlers[ident] ??= [];
const handlerList = this._handlers[ident];
handlerList.push(handler);
return {
+2 -6
View File
@@ -84,9 +84,7 @@ export class Terminal extends Disposable implements ITerminalApi {
public get onWriteParsed(): IEvent<void> { return this._core.onWriteParsed; }
public get parser(): IParser {
if (!this._parser) {
this._parser = new ParserApi(this._core);
}
this._parser ??= new ParserApi(this._core);
return this._parser;
}
public get unicode(): IUnicodeHandling {
@@ -96,9 +94,7 @@ export class Terminal extends Disposable implements ITerminalApi {
public get rows(): number { return this._core.rows; }
public get cols(): number { return this._core.cols; }
public get buffer(): IBufferNamespaceApi {
if (!this._buffer) {
this._buffer = this._register(new BufferNamespaceApi(this._core));
}
this._buffer ??= this._register(new BufferNamespaceApi(this._core));
return this._buffer;
}
public get markers(): ReadonlyArray<IMarker> {