Skip to content

Commit a9788c3

Browse files
authored
Merge pull request #3360 from Tyriar/eslint_as
Add eslint type assertions rule
2 parents fe1d2f6 + f593d14 commit a9788c3

20 files changed

+65
-62
lines changed

.eslintrc.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"readonly": "generic"
4848
}
4949
],
50+
"@typescript-eslint/consistent-type-assertions": "warn",
5051
"@typescript-eslint/consistent-type-definitions": "warn",
5152
"@typescript-eslint/explicit-function-return-type": [
5253
"warn",

addons/xterm-addon-serialize/test/SerializeAddon.api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,9 @@ function newArray<T>(initial: T | ((index: number) => T), count: number): T[] {
487487
const array: T[] = new Array<T>(count);
488488
for (let i = 0; i < array.length; i++) {
489489
if (typeof initial === 'function') {
490-
array[i] = (<(index: number) => T>initial)(i);
490+
array[i] = (initial as (index: number) => T)(i);
491491
} else {
492-
array[i] = <T>initial;
492+
array[i] = initial as T;
493493
}
494494
}
495495
return array;

addons/xterm-addon-webgl/src/WebglAddon.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class WebglAddon implements ITerminalAddon {
2424
throw new Error('Cannot activate WebglAddon before Terminal.open');
2525
}
2626
this._terminal = terminal;
27-
const renderService: IRenderService = (<any>terminal)._core._renderService;
28-
const characterJoinerService: ICharacterJoinerService = (<any>terminal)._core._characterJoinerService;
29-
const colors: IColorSet = (<any>terminal)._core._colorManager.colors;
27+
const renderService: IRenderService = (terminal as any)._core._renderService;
28+
const characterJoinerService: ICharacterJoinerService = (terminal as any)._core._characterJoinerService;
29+
const colors: IColorSet = (terminal as any)._core._colorManager.colors;
3030
this._renderer = new WebglRenderer(terminal, colors, characterJoinerService, this._preserveDrawingBuffer);
3131
this._renderer.onContextLoss(() => this._onContextLoss.fire());
3232
renderService.setRenderer(this._renderer);

src/browser/AccessibilityManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export class AccessibilityManager extends Disposable {
112112
}
113113

114114
private _onBoundaryFocus(e: FocusEvent, position: BoundaryPosition): void {
115-
const boundaryElement = <HTMLElement>e.target;
115+
const boundaryElement = e.target as HTMLElement;
116116
const beforeBoundaryElement = this._rowElements[position === BoundaryPosition.TOP ? 1 : this._rowElements.length - 2];
117117

118118
// Don't scroll if the buffer top has reached the end in that direction

src/browser/ColorManager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('ColorManager', () => {
1717
dom = new jsdom.JSDOM('');
1818
window = dom.window;
1919
document = window.document;
20-
(<any>window).HTMLCanvasElement.prototype.getContext = () => ({
20+
(window as any).HTMLCanvasElement.prototype.getContext = () => ({
2121
createLinearGradient(): any {
2222
return null;
2323
},
@@ -36,7 +36,7 @@ describe('ColorManager', () => {
3636
for (const key of Object.keys(cm.colors)) {
3737
if (key !== 'ansi' && key !== 'contrastCache') {
3838
// A #rrggbb or rgba(...)
39-
assert.ok((<any>cm.colors)[key].css.length >= 7);
39+
assert.ok((cm.colors as any)[key].css.length >= 7);
4040
}
4141
}
4242
assert.equal(cm.colors.ansi.length, 256);

src/browser/Linkifier.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ describe('Linkifier', () => {
174174
assert.equal(mouseZoneManager.zones[0].y1, 1);
175175
assert.equal(mouseZoneManager.zones[0].y2, 1);
176176
// Fires done()
177-
mouseZoneManager.zones[0].clickCallback(<any>{});
177+
mouseZoneManager.zones[0].clickCallback({} as any);
178178
}
179179
});
180180
linkifier.linkifyRows();

src/browser/Linkifier.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export class Linkifier implements ILinkifier {
8989
if (this._rowsTimeoutId) {
9090
clearTimeout(this._rowsTimeoutId);
9191
}
92-
this._rowsTimeoutId = <number><any>setTimeout(() => this._linkifyRows(), Linkifier._timeBeforeLatency);
92+
93+
// Cannot use window.setTimeout since tests need to run in node
94+
this._rowsTimeoutId = setTimeout(() => this._linkifyRows(), Linkifier._timeBeforeLatency) as any as number;
9395
}
9496

9597
/**

src/browser/Terminal.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ describe('Terminal', () => {
2929
beforeEach(() => {
3030
term = new TestTerminal(termOptions);
3131
term.refresh = () => { };
32-
(<any>term).renderer = new MockRenderer();
32+
(term as any).renderer = new MockRenderer();
3333
term.viewport = new MockViewport();
34-
(<any>term)._compositionHelper = new MockCompositionHelper();
35-
(<any>term).element = {
34+
(term as any)._compositionHelper = new MockCompositionHelper();
35+
(term as any).element = {
3636
classList: {
3737
toggle: () => { },
3838
remove: () => { }
@@ -86,12 +86,12 @@ describe('Terminal', () => {
8686
assert.equal(e.domEvent instanceof Object, true);
8787
done();
8888
});
89-
const evKeyPress = <KeyboardEvent>{
89+
const evKeyPress = {
9090
preventDefault: () => { },
9191
stopPropagation: () => { },
9292
type: 'keypress',
9393
keyCode: 13
94-
};
94+
} as KeyboardEvent;
9595
term.keyPress(evKeyPress);
9696
});
9797
it('should fire a key event after a keydown DOM event', (done) => {
@@ -100,13 +100,13 @@ describe('Terminal', () => {
100100
assert.equal(e.domEvent instanceof Object, true);
101101
done();
102102
});
103-
(<any>term).textarea = { value: '' };
104-
const evKeyDown = <KeyboardEvent>{
103+
(term as any).textarea = { value: '' };
104+
const evKeyDown = {
105105
preventDefault: () => { },
106106
stopPropagation: () => { },
107107
type: 'keydown',
108108
keyCode: 13
109-
};
109+
} as KeyboardEvent;
110110
term.keyDown(evKeyDown);
111111
});
112112
it('should fire the onResize event', (done) => {
@@ -140,18 +140,18 @@ describe('Terminal', () => {
140140
});
141141

142142
describe('attachCustomKeyEventHandler', () => {
143-
const evKeyDown = <KeyboardEvent>{
143+
const evKeyDown = {
144144
preventDefault: () => { },
145145
stopPropagation: () => { },
146146
type: 'keydown',
147147
keyCode: 77
148-
};
149-
const evKeyPress = <KeyboardEvent>{
148+
} as KeyboardEvent;
149+
const evKeyPress = {
150150
preventDefault: () => { },
151151
stopPropagation: () => { },
152152
type: 'keypress',
153153
keyCode: 77
154-
};
154+
} as KeyboardEvent;
155155

156156
beforeEach(() => {
157157
term.clearSelection = () => { };
@@ -374,13 +374,13 @@ describe('Terminal', () => {
374374

375375
describe('keyPress', () => {
376376
it('should scroll down, when a key is pressed and terminal is scrolled up', () => {
377-
const event = <KeyboardEvent>{
377+
const event = {
378378
type: 'keydown',
379379
key: 'a',
380380
keyCode: 65,
381381
preventDefault: () => { },
382382
stopPropagation: () => { }
383-
};
383+
} as KeyboardEvent;
384384

385385
term.buffer.ydisp = 0;
386386
term.buffer.ybase = 40;
@@ -403,7 +403,7 @@ describe('Terminal', () => {
403403
assert.equal(term.buffer.ydisp, startYDisp);
404404
term.scrollLines(-1);
405405
assert.equal(term.buffer.ydisp, startYDisp - 1);
406-
term.keyPress(<KeyboardEvent>{ keyCode: 0 });
406+
term.keyPress({ keyCode: 0 });
407407
assert.equal(term.buffer.ydisp, startYDisp - 1);
408408
});
409409
});

src/browser/Terminal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
7272

7373
// private _visualBellTimer: number;
7474

75-
public browser: IBrowser = <any>Browser;
75+
public browser: IBrowser = Browser as any;
7676

7777
// TODO: We should remove options once components adopt optionsService
7878
public get options(): IInitializedTerminalOptions { return this.optionsService.options; }
@@ -601,7 +601,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
601601

602602
let but: CoreMouseButton;
603603
let action: CoreMouseAction | undefined;
604-
switch ((<any>ev).overrideType || ev.type) {
604+
switch ((ev as any).overrideType || ev.type) {
605605
case 'mousemove':
606606
action = CoreMouseAction.MOVE;
607607
if (ev.buttons === undefined) {

src/browser/TestUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export class MockTerminal implements ITerminal {
153153
public textarea!: HTMLTextAreaElement;
154154
public rows!: number;
155155
public cols!: number;
156-
public browser: IBrowser = <any>Browser;
156+
public browser: IBrowser = Browser as any;
157157
public writeBuffer!: string[];
158158
public children!: HTMLElement[];
159159
public cursorHidden!: boolean;

0 commit comments

Comments
 (0)