Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint rule for on=event emitter and rename all methods with on prefix to handle #4187

Merged
merged 2 commits into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,19 @@
{ "selector": "enumMember", "format": ["UPPER_CASE"] },
// memberLike - Allow enum-like objects to use UPPER_CASE
{ "selector": "property", "modifiers": ["public"], "format": ["camelCase", "UPPER_CASE"] },
{ "selector": "method", "modifiers": ["public"], "format": ["camelCase", "UPPER_CASE"] },
// restrict on* naming for events only
{ "selector": "method", "modifiers": ["public"], "format": ["camelCase", "UPPER_CASE"], "custom": {
"regex": "^on[A-Z].+",
"match": false
} },
{ "selector": "method", "modifiers": ["private"], "format": ["camelCase"], "leadingUnderscore": "require", "custom": {
"regex": "^on[A-Z].+",
"match": false
} },
{ "selector": "method", "modifiers": ["protected"], "format": ["camelCase"], "leadingUnderscore": "require", "custom": {
"regex": "^on[A-Z].+",
"match": false
} },
// typeLike
{ "selector": "typeLike", "format": ["PascalCase"] },
{ "selector": "interface", "format": ["PascalCase"], "prefix": ["I"] }
Expand Down
14 changes: 7 additions & 7 deletions addons/xterm-addon-canvas/src/BaseRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer
}
}

public onOptionsChanged(): void {}
public onBlur(): void {}
public onFocus(): void {}
public onCursorMove(): void {}
public onGridChanged(startRow: number, endRow: number): void {}
public handleOptionsChanged(): void {}
public handleBlur(): void {}
public handleFocus(): void {}
public handleCursorMove(): void {}
public handleGridChanged(startRow: number, endRow: number): void {}

public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
public handleSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
this._selectionModel.update(this._terminal, start, end, columnSelectMode);
}

Expand All @@ -105,7 +105,7 @@ export abstract class BaseRenderLayer extends Disposable implements IRenderLayer

// Regenerate char atlas and force a full redraw
this._refreshCharAtlas(this._colors);
this.onGridChanged(0, this._bufferService.rows - 1);
this.handleGridChanged(0, this._bufferService.rows - 1);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions addons/xterm-addon-canvas/src/CanvasAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ export class CanvasAddon extends Disposable implements ITerminalAddon {
this._renderer = new CanvasRenderer(terminal, colors, screenElement, linkifier, bufferService, charSizeService, optionsService, characterJoinerService, coreService, coreBrowserService, decorationService);
this.register(forwardEvent(this._renderer.onChangeTextureAtlas, this._onChangeTextureAtlas));
renderService.setRenderer(this._renderer);
renderService.onResize(bufferService.cols, bufferService.rows);
renderService.handleResize(bufferService.cols, bufferService.rows);

this.register(toDisposable(() => {
renderService.setRenderer((this._terminal as any)._core._createRenderer());
renderService.onResize(terminal.cols, terminal.rows);
renderService.handleResize(terminal.cols, terminal.rows);
this._renderer?.dispose();
this._renderer = undefined;
}));
Expand Down
34 changes: 17 additions & 17 deletions addons/xterm-addon-canvas/src/CanvasRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {

this.register(observeDevicePixelDimensions(this._renderLayers[0].canvas, this._coreBrowserService.window, (w, h) => this._setCanvasDevicePixelDimensions(w, h)));

this.onOptionsChanged();
this.handleOptionsChanged();

this.register(toDisposable(() => {
for (const l of this._renderLayers) {
Expand All @@ -83,12 +83,12 @@ export class CanvasRenderer extends Disposable implements IRenderer {
return this._renderLayers[0].cacheCanvas;
}

public onDevicePixelRatioChange(): void {
public handleDevicePixelRatioChange(): void {
// If the device pixel ratio changed, the char atlas needs to be regenerated
// and the terminal needs to refreshed
if (this._devicePixelRatio !== this._coreBrowserService.dpr) {
this._devicePixelRatio = this._coreBrowserService.dpr;
this.onResize(this._bufferService.cols, this._bufferService.rows);
this.handleResize(this._bufferService.cols, this._bufferService.rows);
}
}

Expand All @@ -101,7 +101,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
}
}

public onResize(cols: number, rows: number): void {
public handleResize(cols: number, rows: number): void {
// Update character and canvas dimensions
this._updateDimensions();

Expand All @@ -115,32 +115,32 @@ export class CanvasRenderer extends Disposable implements IRenderer {
this._screenElement.style.height = `${this.dimensions.canvasHeight}px`;
}

public onCharSizeChanged(): void {
this.onResize(this._bufferService.cols, this._bufferService.rows);
public handleCharSizeChanged(): void {
this.handleResize(this._bufferService.cols, this._bufferService.rows);
}

public onBlur(): void {
this._runOperation(l => l.onBlur());
public handleBlur(): void {
this._runOperation(l => l.handleBlur());
}

public onFocus(): void {
this._runOperation(l => l.onFocus());
public handleFocus(): void {
this._runOperation(l => l.handleFocus());
}

public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
this._runOperation(l => l.onSelectionChanged(start, end, columnSelectMode));
public handleSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean = false): void {
this._runOperation(l => l.handleSelectionChanged(start, end, columnSelectMode));
// Selection foreground requires a full re-render
if (this._colors.selectionForeground) {
this._onRequestRedraw.fire({ start: 0, end: this._bufferService.rows - 1 });
}
}

public onCursorMove(): void {
this._runOperation(l => l.onCursorMove());
public handleCursorMove(): void {
this._runOperation(l => l.handleCursorMove());
}

public onOptionsChanged(): void {
this._runOperation(l => l.onOptionsChanged());
public handleOptionsChanged(): void {
this._runOperation(l => l.handleOptionsChanged());
}

public clear(): void {
Expand All @@ -159,7 +159,7 @@ export class CanvasRenderer extends Disposable implements IRenderer {
*/
public renderRows(start: number, end: number): void {
for (const l of this._renderLayers) {
l.onGridChanged(start, end);
l.handleGridChanged(start, end);
}
}

Expand Down
12 changes: 6 additions & 6 deletions addons/xterm-addon-canvas/src/CursorRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ export class CursorRenderLayer extends BaseRenderLayer {
public reset(): void {
this._clearCursor();
this._cursorBlinkStateManager?.restartBlinkAnimation();
this.onOptionsChanged();
this.handleOptionsChanged();
}

public onBlur(): void {
public handleBlur(): void {
this._cursorBlinkStateManager?.pause();
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
}

public onFocus(): void {
public handleFocus(): void {
this._cursorBlinkStateManager?.resume();
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
}

public onOptionsChanged(): void {
public handleOptionsChanged(): void {
if (this._optionsService.rawOptions.cursorBlink) {
if (!this._cursorBlinkStateManager) {
this._cursorBlinkStateManager = new CursorBlinkStateManager(this._coreBrowserService.isFocused, () => {
Expand All @@ -108,11 +108,11 @@ export class CursorRenderLayer extends BaseRenderLayer {
this._onRequestRedraw.fire({ start: this._bufferService.buffer.y, end: this._bufferService.buffer.y });
}

public onCursorMove(): void {
public handleCursorMove(): void {
this._cursorBlinkStateManager?.restartBlinkAnimation();
}

public onGridChanged(startRow: number, endRow: number): void {
public handleGridChanged(startRow: number, endRow: number): void {
if (!this._cursorBlinkStateManager || this._cursorBlinkStateManager.isPaused) {
this._render(false);
} else {
Expand Down
8 changes: 4 additions & 4 deletions addons/xterm-addon-canvas/src/LinkRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export class LinkRenderLayer extends BaseRenderLayer {
) {
super(terminal, container, 'link', zIndex, true, colors, bufferService, optionsService, decorationService, coreBrowserService);

this.register(linkifier2.onShowLinkUnderline(e => this._onShowLinkUnderline(e)));
this.register(linkifier2.onHideLinkUnderline(e => this._onHideLinkUnderline(e)));
this.register(linkifier2.onShowLinkUnderline(e => this._handleShowLinkUnderline(e)));
this.register(linkifier2.onHideLinkUnderline(e => this._handleHideLinkUnderline(e)));
}

public resize(dim: IRenderDimensions): void {
Expand All @@ -54,7 +54,7 @@ export class LinkRenderLayer extends BaseRenderLayer {
}
}

private _onShowLinkUnderline(e: ILinkifierEvent): void {
private _handleShowLinkUnderline(e: ILinkifierEvent): void {
if (e.fg === INVERTED_DEFAULT_COLOR) {
this._ctx.fillStyle = this._colors.background.css;
} else if (e.fg && is256Color(e.fg)) {
Expand All @@ -78,7 +78,7 @@ export class LinkRenderLayer extends BaseRenderLayer {
this._state = e;
}

private _onHideLinkUnderline(e: ILinkifierEvent): void {
private _handleHideLinkUnderline(e: ILinkifierEvent): void {
this._clearCurrentLink();
}
}
8 changes: 4 additions & 4 deletions addons/xterm-addon-canvas/src/SelectionRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ export class SelectionRenderLayer extends BaseRenderLayer {
}
}

public onBlur(): void {
public handleBlur(): void {
this.reset();
this._redrawSelection(this._selectionModel.selectionStart, this._selectionModel.selectionEnd, this._selectionModel.columnSelectMode);
}

public onFocus(): void {
public handleFocus(): void {
this.reset();
this._redrawSelection(this._selectionModel.selectionStart, this._selectionModel.selectionEnd, this._selectionModel.columnSelectMode);
}

public onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void {
super.onSelectionChanged(start, end, columnSelectMode);
public handleSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void {
super.handleSelectionChanged(start, end, columnSelectMode);
this._redrawSelection(start, end, columnSelectMode);
}

Expand Down
4 changes: 2 additions & 2 deletions addons/xterm-addon-canvas/src/TextRenderLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export class TextRenderLayer extends BaseRenderLayer {
this._forEachCell(firstRow, lastRow, (cell, x, y) => this._drawChars(cell, x, y));
}

public onGridChanged(firstRow: number, lastRow: number): void {
public handleGridChanged(firstRow: number, lastRow: number): void {
// Resize has not been called yet
if (this._state.cache.length === 0) {
return;
Expand All @@ -251,7 +251,7 @@ export class TextRenderLayer extends BaseRenderLayer {
this._drawForeground(firstRow, lastRow);
}

public onOptionsChanged(): void {
public handleOptionsChanged(): void {
this._setTransparency(this._optionsService.rawOptions.allowTransparency);
}

Expand Down
28 changes: 14 additions & 14 deletions addons/xterm-addon-canvas/src/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export interface IRenderer extends IDisposable {
readonly onRequestRedraw: IEvent<IRequestRedrawEvent>;

setColors(colors: IColorSet): void;
onDevicePixelRatioChange(): void;
onResize(cols: number, rows: number): void;
onCharSizeChanged(): void;
onBlur(): void;
onFocus(): void;
onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void;
onCursorMove(): void;
onOptionsChanged(): void;
handleDevicePixelRatioChange(): void;
handleResize(cols: number, rows: number): void;
handleCharSizeChanged(): void;
handleBlur(): void;
handleFocus(): void;
handleSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void;
handleCursorMove(): void;
handleOptionsChanged(): void;
clear(): void;
renderRows(start: number, end: number): void;
clearTextureAtlas?(): void;
Expand All @@ -62,22 +62,22 @@ export interface IRenderLayer extends IDisposable {
/**
* Called when the terminal loses focus.
*/
onBlur(): void;
handleBlur(): void;

/**
* * Called when the terminal gets focus.
*/
onFocus(): void;
handleFocus(): void;

/**
* Called when the cursor is moved.
*/
onCursorMove(): void;
handleCursorMove(): void;

/**
* Called when options change.
*/
onOptionsChanged(): void;
handleOptionsChanged(): void;

/**
* Called when the theme changes.
Expand All @@ -88,12 +88,12 @@ export interface IRenderLayer extends IDisposable {
* Called when the data in the grid has changed (or needs to be rendered
* again).
*/
onGridChanged(startRow: number, endRow: number): void;
handleGridChanged(startRow: number, endRow: number): void;

/**
* Calls when the selection changes.
*/
onSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void;
handleSelectionChanged(start: [number, number] | undefined, end: [number, number] | undefined, columnSelectMode: boolean): void;

/**
* Resize the render layer.
Expand Down
4 changes: 2 additions & 2 deletions addons/xterm-addon-webgl/src/GlyphRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class GlyphRenderer extends Disposable {
gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);

// Set viewport
this.onResize();
this.handleResize();
}

public beginFrame(): boolean {
Expand Down Expand Up @@ -263,7 +263,7 @@ export class GlyphRenderer extends Disposable {
}
}

public onResize(): void {
public handleResize(): void {
const gl = this._gl;
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height);
this.clear();
Expand Down
2 changes: 1 addition & 1 deletion addons/xterm-addon-webgl/src/RectangleRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export class RectangleRenderer extends Disposable {
gl.drawElementsInstanced(this._gl.TRIANGLES, 6, gl.UNSIGNED_BYTE, 0, this._vertices.count);
}

public onResize(): void {
public handleResize(): void {
this._updateViewportRectangle();
}

Expand Down
2 changes: 1 addition & 1 deletion addons/xterm-addon-webgl/src/WebglAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class WebglAddon extends Disposable implements ITerminalAddon {
this.register(toDisposable(() => {
const renderService: IRenderService = (this._terminal as any)._core._renderService;
renderService.setRenderer((this._terminal as any)._core._createRenderer());
renderService.onResize(terminal.cols, terminal.rows);
renderService.handleResize(terminal.cols, terminal.rows);
}));
}

Expand Down
Loading