Skip to content

Commit bad7e32

Browse files
committed
Add @typescript-eslint/prefer-nullish-coalescing eslint rule
1 parent 01450f0 commit bad7e32

32 files changed

Lines changed: 113 additions & 147 deletions

addons/addon-image/src/ImageAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class ImageAddon implements ITerminalAddon , IImageApi {
9090
// windowOptions.getCellSizePixels = true;
9191
// windowOptions.getWinSizeChars = true;
9292
// terminal.setOption('windowOptions', windowOptions);
93-
const windowOps = terminal.options.windowOptions || {};
93+
const windowOps = terminal.options.windowOptions ?? {};
9494
windowOps.getWinSizePixels = true;
9595
windowOps.getCellSizePixels = true;
9696
windowOps.getWinSizeChars = true;

addons/addon-image/src/ImageRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
3838
* Only the DOM output canvas should be on the terminal's document,
3939
* which gets explicitly checked in `insertLayerToDom`.
4040
*/
41-
const canvas = (localDocument || document).createElement('canvas');
41+
const canvas = (localDocument ?? document).createElement('canvas');
4242
canvas.width = width | 0;
4343
canvas.height = height | 0;
4444
return canvas;
@@ -242,7 +242,7 @@ export class ImageRenderer extends Disposable implements IDisposable {
242242
}
243243
if (!this._placeholder) return;
244244
this._ctx.drawImage(
245-
this._placeholderBitmap || this._placeholder!,
245+
this._placeholderBitmap ?? this._placeholder!,
246246
col * width,
247247
(row * height) % 2 ? 0 : 1, // needs %2 offset correction
248248
width * count,

addons/addon-image/src/ImageStorage.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export class ImageStorage implements IDisposable {
381381
if (!line) return;
382382
for (let col = 0; col < cols; ++col) {
383383
if (line.getBg(col) & BgFlags.HAS_EXTENDED) {
384-
let e: IExtendedAttrsImage = line._extendedAttrs[col] || EMPTY_ATTRS;
384+
let e: IExtendedAttrsImage = line._extendedAttrs[col] ?? EMPTY_ATTRS;
385385
const imageId = e.imageId;
386386
if (imageId === undefined || imageId === -1) {
387387
continue;
@@ -400,7 +400,7 @@ export class ImageStorage implements IDisposable {
400400
while (
401401
++col < cols
402402
&& (line.getBg(col) & BgFlags.HAS_EXTENDED)
403-
&& (e = line._extendedAttrs[col] || EMPTY_ATTRS)
403+
&& (e = line._extendedAttrs[col] ?? EMPTY_ATTRS)
404404
&& (e.imageId === imageId)
405405
&& (e.tileId === startTile + count)
406406
) {
@@ -442,7 +442,7 @@ export class ImageStorage implements IDisposable {
442442
for (let row = 0; row < rows; ++row) {
443443
const line = buffer.lines.get(row) as IBufferLineExt;
444444
if (line.getBg(oldCol) & BgFlags.HAS_EXTENDED) {
445-
const e: IExtendedAttrsImage = line._extendedAttrs[oldCol] || EMPTY_ATTRS;
445+
const e: IExtendedAttrsImage = line._extendedAttrs[oldCol] ?? EMPTY_ATTRS;
446446
const imageId = e.imageId;
447447
if (imageId === undefined || imageId === -1) {
448448
continue;
@@ -487,7 +487,7 @@ export class ImageStorage implements IDisposable {
487487
const buffer = this._terminal._core.buffer;
488488
const line = buffer.lines.get(y) as IBufferLineExt;
489489
if (line && line.getBg(x) & BgFlags.HAS_EXTENDED) {
490-
const e: IExtendedAttrsImage = line._extendedAttrs[x] || EMPTY_ATTRS;
490+
const e: IExtendedAttrsImage = line._extendedAttrs[x] ?? EMPTY_ATTRS;
491491
if (e.imageId && e.imageId !== -1) {
492492
const orig = this._images.get(e.imageId)?.orig;
493493
if (window.ImageBitmap && orig instanceof ImageBitmap) {
@@ -507,7 +507,7 @@ export class ImageStorage implements IDisposable {
507507
const buffer = this._terminal._core.buffer;
508508
const line = buffer.lines.get(y) as IBufferLineExt;
509509
if (line && line.getBg(x) & BgFlags.HAS_EXTENDED) {
510-
const e: IExtendedAttrsImage = line._extendedAttrs[x] || EMPTY_ATTRS;
510+
const e: IExtendedAttrsImage = line._extendedAttrs[x] ?? EMPTY_ATTRS;
511511
if (e.imageId && e.imageId !== -1 && e.tileId !== -1) {
512512
const spec = this._images.get(e.imageId);
513513
if (spec) {

addons/addon-ligatures/src/LigaturesAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class LigaturesAddon implements ITerminalAddon , ILigaturesApi {
2222

2323
constructor(options?: Partial<ILigatureOptions>) {
2424
// Source: calt set from https://github.com/be5invis/Iosevka?tab=readme-ov-file#ligations
25-
this._fallbackLigatures = (options?.fallbackLigatures || [
25+
this._fallbackLigatures = (options?.fallbackLigatures ?? [
2626
'<--', '<---', '<<-', '<-', '->', '->>', '-->', '--->',
2727
'<==', '<===', '<<=', '<=', '=>', '=>>', '==>', '===>', '>=', '>>=',
2828
'<->', '<-->', '<--->', '<---->', '<=>', '<==>', '<===>', '<====>', '::', ':::',

addons/addon-ligatures/src/font.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,7 @@ export default async function load(fontFamily: string, cacheSize: number): Promi
8080
console.error(err.name, err.message);
8181
}
8282
}
83-
if (!fontsPromise) {
84-
fontsPromise = Promise.resolve({});
85-
}
83+
fontsPromise ??= Promise.resolve({});
8684
}
8785

8886
const fonts = await fontsPromise;

addons/addon-ligatures/src/fontLigatures/processors/helper.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,10 @@ export function processLookaheadPosition(
5252
}
5353
processedEntries.add(currentEntry.entry);
5454

55-
if (!currentEntry.entry.forward) {
56-
currentEntry.entry.forward = {
57-
individual: {},
58-
range: []
59-
};
60-
}
55+
currentEntry.entry.forward ??= {
56+
individual: {},
57+
range: []
58+
};
6159

6260
// All glyphs at this position share ONE entry - lookahead just needs to match,
6361
// all paths lead to the same result
@@ -97,12 +95,10 @@ export function processBacktrackPosition(
9795
}
9896
processedEntries.add(currentEntry.entry);
9997

100-
if (!currentEntry.entry.reverse) {
101-
currentEntry.entry.reverse = {
102-
individual: {},
103-
range: []
104-
};
105-
}
98+
currentEntry.entry.reverse ??= {
99+
individual: {},
100+
range: []
101+
};
106102

107103
// All glyphs at this position share ONE entry - backtrack just needs to match,
108104
// all paths lead to the same result

addons/addon-ligatures/src/fontLigatures/processors/substitution.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ export function getIndividualSubstitutionGlyph(table: SubstitutionTable, glyphId
5454
return (glyphId + table.deltaGlyphId) % (2 ** 16);
5555
// https://docs.microsoft.com/en-us/typography/opentype/spec/gsub#12-single-substitution-format-2
5656
case 2:
57-
// eslint-disable-next-line eqeqeq
58-
return table.substitute[coverageIndex] != null
59-
? table.substitute[coverageIndex]
60-
: null;
57+
return table.substitute[coverageIndex] ?? null;
6158
}
6259
}

addons/addon-search/src/SearchEngine.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ export class SearchEngine {
198198
}
199199
}
200200

201-
if (!result) {
202-
result = this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
203-
}
201+
result ??= this._findInLine(term, searchPosition, searchOptions, isReverseSearch);
204202

205203
// Search from startRow - 1 to top
206204
if (!result) {

addons/addon-serialize/src/SerializeAddon.test.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe('SerializeAddon', () => {
228228
it('empty terminal with selection turned off', () => {
229229
const output = serializeAddon.serializeAsHTML();
230230
assert.notEqual(output, '');
231-
assert.equal((output.match(/<div><span> {10}<\/span><\/div>/g) || []).length, 2);
231+
assert.equal((output.match(/<div><span> {10}<\/span><\/div>/g) ?? []).length, 2);
232232
});
233233

234234
it('empty terminal with no selection', () => {
@@ -245,7 +245,7 @@ describe('SerializeAddon', () => {
245245
const output = serializeAddon.serializeAsHTML({
246246
onlySelection: true
247247
});
248-
assert.equal((output.match(/<div><span>terminal<\/span><\/div>/g) || []).length, 1, output);
248+
assert.equal((output.match(/<div><span>terminal<\/span><\/div>/g) ?? []).length, 1, output);
249249
});
250250

251251
it('basic terminal with html unsafe chars', async () => {
@@ -255,7 +255,7 @@ describe('SerializeAddon', () => {
255255
const output = serializeAddon.serializeAsHTML({
256256
onlySelection: true
257257
});
258-
assert.equal((output.match(/<div><span>&lt;a>&amp;pi;<\/span><\/div>/g) || []).length, 1, output);
258+
assert.equal((output.match(/<div><span>&lt;a>&amp;pi;<\/span><\/div>/g) ?? []).length, 1, output);
259259
});
260260

261261
it('serializes rows within a provided range', async () => {
@@ -267,7 +267,7 @@ describe('SerializeAddon', () => {
267267
startCol: 4
268268
}
269269
});
270-
const rowMatches = output.match(/<div><span>.*?<\/span><\/div>/g) || [];
270+
const rowMatches = output.match(/<div><span>.*?<\/span><\/div>/g) ?? [];
271271
assert.equal(rowMatches.length, 1, output);
272272
assert.ok(rowMatches[0]?.includes('hello'));
273273
assert.ok(!output.includes('bye'));
@@ -278,56 +278,56 @@ describe('SerializeAddon', () => {
278278
await writeP(terminal, ' ' + sgr('1') + 'terminal' + sgr('22') + ' ');
279279

280280
const output = serializeAddon.serializeAsHTML();
281-
assert.equal((output.match(/<span style='font-weight: bold;'>terminal<\/span>/g) || []).length, 1, output);
281+
assert.equal((output.match(/<span style='font-weight: bold;'>terminal<\/span>/g) ?? []).length, 1, output);
282282
});
283283

284284
it('cells with italic styling', async () => {
285285
await writeP(terminal, ' ' + sgr('3') + 'terminal' + sgr('23') + ' ');
286286

287287
const output = serializeAddon.serializeAsHTML();
288-
assert.equal((output.match(/<span style='font-style: italic;'>terminal<\/span>/g) || []).length, 1, output);
288+
assert.equal((output.match(/<span style='font-style: italic;'>terminal<\/span>/g) ?? []).length, 1, output);
289289
});
290290

291291
it('cells with inverse styling', async () => {
292292
await writeP(terminal, ' ' + sgr('7') + 'terminal' + sgr('27') + ' ');
293293

294294
const output = serializeAddon.serializeAsHTML();
295-
assert.equal((output.match(/<span style='color: #000000; background-color: #BFBFBF;'>terminal<\/span>/g) || []).length, 1, output);
295+
assert.equal((output.match(/<span style='color: #000000; background-color: #BFBFBF;'>terminal<\/span>/g) ?? []).length, 1, output);
296296
});
297297

298298
it('cells with underline styling', async () => {
299299
await writeP(terminal, ' ' + sgr('4') + 'terminal' + sgr('24') + ' ');
300300

301301
const output = serializeAddon.serializeAsHTML();
302-
assert.equal((output.match(/<span style='text-decoration: underline;'>terminal<\/span>/g) || []).length, 1, output);
302+
assert.equal((output.match(/<span style='text-decoration: underline;'>terminal<\/span>/g) ?? []).length, 1, output);
303303
});
304304

305305
it('cells with double underline styling', async () => {
306306
await writeP(terminal, ' ' + sgr('4:2') + 'terminal' + sgr('24') + ' ');
307307

308308
const output = serializeAddon.serializeAsHTML();
309-
assert.equal((output.match(/<span style='text-decoration: underline double;'>terminal<\/span>/g) || []).length, 1, output);
309+
assert.equal((output.match(/<span style='text-decoration: underline double;'>terminal<\/span>/g) ?? []).length, 1, output);
310310
});
311311

312312
it('cells with curly underline styling', async () => {
313313
await writeP(terminal, ' ' + sgr('4:3') + 'terminal' + sgr('24') + ' ');
314314

315315
const output = serializeAddon.serializeAsHTML();
316-
assert.equal((output.match(/<span style='text-decoration: underline wavy;'>terminal<\/span>/g) || []).length, 1, output);
316+
assert.equal((output.match(/<span style='text-decoration: underline wavy;'>terminal<\/span>/g) ?? []).length, 1, output);
317317
});
318318

319319
it('cells with dotted underline styling', async () => {
320320
await writeP(terminal, ' ' + sgr('4:4') + 'terminal' + sgr('24') + ' ');
321321

322322
const output = serializeAddon.serializeAsHTML();
323-
assert.equal((output.match(/<span style='text-decoration: underline dotted;'>terminal<\/span>/g) || []).length, 1, output);
323+
assert.equal((output.match(/<span style='text-decoration: underline dotted;'>terminal<\/span>/g) ?? []).length, 1, output);
324324
});
325325

326326
it('cells with dashed underline styling', async () => {
327327
await writeP(terminal, ' ' + sgr('4:5') + 'terminal' + sgr('24') + ' ');
328328

329329
const output = serializeAddon.serializeAsHTML();
330-
assert.equal((output.match(/<span style='text-decoration: underline dashed;'>terminal<\/span>/g) || []).length, 1, output);
330+
assert.equal((output.match(/<span style='text-decoration: underline dashed;'>terminal<\/span>/g) ?? []).length, 1, output);
331331
});
332332

333333
it('cells with underline color (palette)', async () => {
@@ -350,49 +350,49 @@ describe('SerializeAddon', () => {
350350
await writeP(terminal, ' ' + sgr('8') + 'terminal' + sgr('28') + ' ');
351351

352352
const output = serializeAddon.serializeAsHTML();
353-
assert.equal((output.match(/<span style='visibility: hidden;'>terminal<\/span>/g) || []).length, 1, output);
353+
assert.equal((output.match(/<span style='visibility: hidden;'>terminal<\/span>/g) ?? []).length, 1, output);
354354
});
355355

356356
it('cells with dim styling', async () => {
357357
await writeP(terminal, ' ' + sgr('2') + 'terminal' + sgr('22') + ' ');
358358

359359
const output = serializeAddon.serializeAsHTML();
360-
assert.equal((output.match(/<span style='opacity: 0.5;'>terminal<\/span>/g) || []).length, 1, output);
360+
assert.equal((output.match(/<span style='opacity: 0.5;'>terminal<\/span>/g) ?? []).length, 1, output);
361361
});
362362

363363
it('cells with strikethrough styling', async () => {
364364
await writeP(terminal, ' ' + sgr('9') + 'terminal' + sgr('29') + ' ');
365365

366366
const output = serializeAddon.serializeAsHTML();
367-
assert.equal((output.match(/<span style='text-decoration: line-through;'>terminal<\/span>/g) || []).length, 1, output);
367+
assert.equal((output.match(/<span style='text-decoration: line-through;'>terminal<\/span>/g) ?? []).length, 1, output);
368368
});
369369

370370
it('cells with combined styling', async () => {
371371
await writeP(terminal, sgr('1') + ' ' + sgr('9') + 'termi' + sgr('22') + 'nal' + sgr('29') + ' ');
372372

373373
const output = serializeAddon.serializeAsHTML();
374-
assert.equal((output.match(/<span style='font-weight: bold;'> <\/span>/g) || []).length, 1, output);
375-
assert.equal((output.match(/<span style='font-weight: bold; text-decoration: line-through;'>termi<\/span>/g) || []).length, 1, output);
376-
assert.equal((output.match(/<span style='text-decoration: line-through;'>nal<\/span>/g) || []).length, 1, output);
374+
assert.equal((output.match(/<span style='font-weight: bold;'> <\/span>/g) ?? []).length, 1, output);
375+
assert.equal((output.match(/<span style='font-weight: bold; text-decoration: line-through;'>termi<\/span>/g) ?? []).length, 1, output);
376+
assert.equal((output.match(/<span style='text-decoration: line-through;'>nal<\/span>/g) ?? []).length, 1, output);
377377
});
378378

379379
it('cells with color styling', async () => {
380380
await writeP(terminal, ' ' + sgr('38;5;46') + 'terminal' + sgr('39') + ' ');
381381

382382
const output = serializeAddon.serializeAsHTML();
383-
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) || []).length, 1, output);
383+
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) ?? []).length, 1, output);
384384
});
385385

386386
it('cells with background styling', async () => {
387387
await writeP(terminal, ' ' + sgr('48;5;46') + 'terminal' + sgr('49') + ' ');
388388

389389
const output = serializeAddon.serializeAsHTML();
390-
assert.equal((output.match(/<span style='background-color: #00ff00;'>terminal<\/span>/g) || []).length, 1, output);
390+
assert.equal((output.match(/<span style='background-color: #00ff00;'>terminal<\/span>/g) ?? []).length, 1, output);
391391
});
392392

393393
it('empty terminal with default options', async () => {
394394
const output = serializeAddon.serializeAsHTML();
395-
assert.equal((output.match(/color: #000000; background-color: #ffffff; font-family: monospace; font-size: 15px;/g) || []).length, 1, output);
395+
assert.equal((output.match(/color: #000000; background-color: #ffffff; font-family: monospace; font-size: 15px;/g) ?? []).length, 1, output);
396396
});
397397

398398
it('empty terminal with custom options', async () => {
@@ -405,14 +405,14 @@ describe('SerializeAddon', () => {
405405
const output = serializeAddon.serializeAsHTML({
406406
includeGlobalBackground: true
407407
});
408-
assert.equal((output.match(/color: #ff00ff; background-color: #00ff00; font-family: verdana; font-size: 20px;/g) || []).length, 1, output);
408+
assert.equal((output.match(/color: #ff00ff; background-color: #00ff00; font-family: verdana; font-size: 20px;/g) ?? []).length, 1, output);
409409
});
410410

411411
it('empty terminal with background included', async () => {
412412
const output = serializeAddon.serializeAsHTML({
413413
includeGlobalBackground: true
414414
});
415-
assert.equal((output.match(/color: #ffffff; background-color: #000000; font-family: monospace; font-size: 15px;/g) || []).length, 1, output);
415+
assert.equal((output.match(/color: #ffffff; background-color: #000000; font-family: monospace; font-size: 15px;/g) ?? []).length, 1, output);
416416
});
417417

418418
it('cells with custom color styling', async () => {
@@ -422,7 +422,7 @@ describe('SerializeAddon', () => {
422422
await writeP(terminal, ' ' + sgr('38;5;0') + 'terminal' + sgr('39') + ' ');
423423

424424
const output = serializeAddon.serializeAsHTML();
425-
assert.equal((output.match(/<span style='color: #ffa500;'>terminal<\/span>/g) || []).length, 1, output);
425+
assert.equal((output.match(/<span style='color: #ffa500;'>terminal<\/span>/g) ?? []).length, 1, output);
426426
});
427427

428428
it('cells with color styling - xterm headless', async () => {
@@ -432,7 +432,7 @@ describe('SerializeAddon', () => {
432432
await writeP(terminal, ' ' + sgr('38;5;46') + 'terminal' + sgr('39') + ' ');
433433

434434
const output = serializeAddon.serializeAsHTML();
435-
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) || []).length, 1, output);
435+
assert.equal((output.match(/<span style='color: #00ff00;'>terminal<\/span>/g) ?? []).length, 1, output);
436436
});
437437
});
438438
});

addons/addon-serialize/src/SerializeAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ export class SerializeAddon implements ITerminalAddon , ISerializeApi {
601601
throw new Error('Cannot use addon until it has been loaded');
602602
}
603603

604-
return this._serializeBufferAsHTML(this._terminal, options || {});
604+
return this._serializeBufferAsHTML(this._terminal, options ?? {});
605605
}
606606

607607
public dispose(): void { }

0 commit comments

Comments
 (0)