Skip to content

Commit

Permalink
chore: fix eslint in blocksuite (#9232)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Dec 20, 2024
1 parent bfcc53d commit 3a82da0
Show file tree
Hide file tree
Showing 269 changed files with 941 additions and 848 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class EmbedHtmlFullscreenToolbar extends LitElement {
}
`;

private _popSettings = () => {
private readonly _popSettings = () => {
this._popperVisible = true;
popMenu(popupTargetFromElement(this._fullScreenToolbarContainer), {
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import { getEmbedLinkedDocIcons } from './utils.js';
export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinkedDocModel> {
static override styles = styles;

private _load = async () => {
private readonly _load = async () => {
const {
loading = true,
isError = false,
Expand Down Expand Up @@ -103,15 +103,15 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
}
};

private _selectBlock = () => {
private readonly _selectBlock = () => {
const selectionManager = this.host.selection;
const blockSelection = selectionManager.create('block', {
blockId: this.blockId,
});
selectionManager.setGroup('note', [blockSelection]);
};

private _setDocUpdatedAt = () => {
private readonly _setDocUpdatedAt = () => {
const meta = this.doc.collection.meta.getDocMeta(this.model.pageId);
if (meta) {
const date = meta.updatedDate || meta.createDate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
// Caches total bounds, includes all blocks and elements.
private _cachedBounds: Bound | null = null;

private _initEdgelessFitEffect = () => {
private readonly _initEdgelessFitEffect = () => {
const fitToContent = () => {
if (this.isPageMode) return;

Expand Down Expand Up @@ -99,7 +99,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
.catch(() => {});
};

private _pageFilter: Query = {
private readonly _pageFilter: Query = {
mode: 'loose',
match: [
{
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/block-list/src/list-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<

private _inlineRangeProvider: InlineRangeProvider | null = null;

private _onClickIcon = (e: MouseEvent) => {
private readonly _onClickIcon = (e: MouseEvent) => {
e.stopPropagation();

if (this.model.type === 'toggle') {
Expand Down
6 changes: 3 additions & 3 deletions blocksuite/affine/block-paragraph/src/paragraph-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<
> {
static override styles = paragraphBlockStyles;

private _composing = signal(false);
private readonly _composing = signal(false);

private _displayPlaceholder = signal(false);
private readonly _displayPlaceholder = signal(false);

private _inlineRangeProvider: InlineRangeProvider | null = null;

private _isInDatabase = () => {
private readonly _isInDatabase = () => {
let parent = this.parentElement;
while (parent && parent !== document.body) {
if (parent.tagName.toLowerCase() === 'affine-database') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ export class PathGenerator {

export class ConnectorPathGenerator extends PathGenerator {
constructor(
private options: {
private readonly options: {
getElementById: (id: string) => GfxModel | null;
}
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type RendererOptions = {
export class CanvasRenderer {
private _container!: HTMLElement;

private _disposables = new DisposableGroup();
private readonly _disposables = new DisposableGroup();

private _overlays = new Set<Overlay>();
private readonly _overlays = new Set<Overlay>();

private _refreshRafId: number | null = null;

Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/block-surface/src/surface-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class SurfaceBlockComponent extends BlockComponent<

private _cachedViewport = new Bound();

private _initThemeObserver = () => {
private readonly _initThemeObserver = () => {
const theme = this.std.get(ThemeProvider);
this.disposables.add(theme.theme$.subscribe(() => this.requestUpdate()));
};
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/block-surface/src/surface-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const SurfaceBlockSchema = defineBlockSchema({
export type SurfaceMiddleware = (surface: SurfaceBlockModel) => () => void;

export class SurfaceBlockModel extends BaseSurfaceModel {
private _disposables: DisposableGroup = new DisposableGroup();
private readonly _disposables: DisposableGroup = new DisposableGroup();

override _init() {
this._extendElement(elementsCtorMap);
Expand Down
19 changes: 11 additions & 8 deletions blocksuite/affine/block-surface/src/utils/a-star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,27 @@ function pointAlmostEqual(a: IVec3, b: IVec3): boolean {
}

export class AStarRunner {
private _cameFrom = new Map<IVec3, { from: IVec3[]; indexs: number[] }>();
private readonly _cameFrom = new Map<
IVec3,
{ from: IVec3[]; indexs: number[] }
>();

private _complete = false;

private _costSoFar = new Map<IVec3, number[]>();
private readonly _costSoFar = new Map<IVec3, number[]>();

private _current: IVec3 | null = null;

private _diagonalCount = new Map<IVec3, number[]>();
private readonly _diagonalCount = new Map<IVec3, number[]>();

private _frontier!: PriorityQueue<
IVec3,
[diagonalCount: number, pointPriority: number, distCost: number]
>;

private _graph: Graph<IVec3>;
private readonly _graph: Graph<IVec3>;

private _pointPriority = new Map<IVec3, number[]>();
private readonly _pointPriority = new Map<IVec3, number[]>();

get path() {
const result: IVec3[] = [];
Expand All @@ -72,9 +75,9 @@ export class AStarRunner {

constructor(
points: IVec3[],
private _sp: IVec3,
private _ep: IVec3,
private _originalSp: IVec3,
private readonly _sp: IVec3,
private readonly _ep: IVec3,
private readonly _originalSp: IVec3,
private _originalEp: IVec3,
blocks: Bound[] = [],
expandBlocks: Bound[] = []
Expand Down
12 changes: 6 additions & 6 deletions blocksuite/affine/block-surface/src/utils/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ function arrayAlmostEqual(point: IVec | IVec3, point2: IVec | IVec3) {
}

export class Graph<V extends IVec | IVec3 = IVec> {
private _xMap = new Map<number, V[]>();
private readonly _xMap = new Map<number, V[]>();

private _yMap = new Map<number, V[]>();
private readonly _yMap = new Map<number, V[]>();

constructor(
private points: V[],
private blocks: Bound[] = [],
private expandedBlocks: Bound[] = [],
private excludedPoints: V[] = []
private readonly points: V[],
private readonly blocks: Bound[] = [],
private readonly expandedBlocks: Bound[] = [],
private readonly excludedPoints: V[] = []
) {
const xMap = this._xMap;
const yMap = this._yMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type PriorityQueueNode<T, K> = {
export class PriorityQueue<T, K> {
heap: PriorityQueueNode<T, K>[] = [];

constructor(private _compare: (a: K, b: K) => number) {}
constructor(private readonly _compare: (a: K, b: K) => number) {}

bubbleDown(): void {
let index = 0;
Expand Down
6 changes: 3 additions & 3 deletions blocksuite/affine/block-surface/src/utils/rough/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { RoughGenerator } from './generator.js';
import type { Point } from './geometry.js';

export class RoughCanvas {
private canvas: HTMLCanvasElement;
private readonly canvas: HTMLCanvasElement;

private ctx: CanvasRenderingContext2D;
private readonly ctx: CanvasRenderingContext2D;

private gen: RoughGenerator;
private readonly gen: RoughGenerator;

get generator(): RoughGenerator {
return this.gen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js';
import { polygonHachureLines } from './scan-line-hachure.js';

export class DashedFiller implements PatternFiller {
private helper: RenderHelper;
private readonly helper: RenderHelper;

constructor(helper: RenderHelper) {
this.helper = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js';
import { polygonHachureLines } from './scan-line-hachure.js';

export class DotFiller implements PatternFiller {
private helper: RenderHelper;
private readonly helper: RenderHelper;

constructor(helper: RenderHelper) {
this.helper = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js';
import { polygonHachureLines } from './scan-line-hachure.js';

export class HachureFiller implements PatternFiller {
private helper: RenderHelper;
private readonly helper: RenderHelper;

constructor(helper: RenderHelper) {
this.helper = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { PatternFiller, RenderHelper } from './filler-interface.js';
import { polygonHachureLines } from './scan-line-hachure.js';

export class ZigZagLineFiller implements PatternFiller {
private helper: RenderHelper;
private readonly helper: RenderHelper;

constructor(helper: RenderHelper) {
this.helper = helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
const NOS = 'none';

export class RoughGenerator {
private config: Config;
private readonly config: Config;

defaultOptions: ResolvedOptions = {
maxRandomnessOffset: 2,
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-surface/src/utils/rough/svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import { RoughGenerator } from './generator.js';
import type { Point } from './geometry.js';

export class RoughSVG {
private gen: RoughGenerator;
private readonly gen: RoughGenerator;

private svg: SVGSVGElement;
private readonly svg: SVGSVGElement;

get generator(): RoughGenerator {
return this.gen;
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/block-surface/src/view/mindmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { handleLayout } from '../utils/mindmap/utils.js';
export class MindMapView extends GfxElementModelView<MindmapElementModel> {
static override type = 'mindmap';

private _collapseButtons = new Map<string, LocalShapeElementModel>();
private readonly _collapseButtons = new Map<string, LocalShapeElementModel>();

private _hoveredState = new Map<
string,
Expand Down
14 changes: 7 additions & 7 deletions blocksuite/affine/components/src/context-menu/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ export class MenuInput extends MenuFocusable {
}
`;

private onCompositionEnd = () => {
private readonly onCompositionEnd = () => {
this.data.onChange?.(this.inputRef.value);
};

private onInput = (e: InputEvent) => {
private readonly onInput = (e: InputEvent) => {
e.stopPropagation();
if (e.isComposing) return;
this.data.onChange?.(this.inputRef.value);
};

private onKeydown = (e: KeyboardEvent) => {
private readonly onKeydown = (e: KeyboardEvent) => {
e.stopPropagation();
if (e.isComposing) return;
if (e.key === 'Escape') {
Expand All @@ -71,7 +71,7 @@ export class MenuInput extends MenuFocusable {
}
};

private stopPropagation = (e: Event) => {
private readonly stopPropagation = (e: Event) => {
e.stopPropagation();
};

Expand Down Expand Up @@ -140,17 +140,17 @@ export class MobileMenuInput extends MenuFocusable {
}
`;

private onCompositionEnd = () => {
private readonly onCompositionEnd = () => {
this.data.onChange?.(this.inputRef.value);
};

private onInput = (e: InputEvent) => {
private readonly onInput = (e: InputEvent) => {
e.stopPropagation();
if (e.isComposing) return;
this.data.onChange?.(this.inputRef.value);
};

private stopPropagation = (e: Event) => {
private readonly stopPropagation = (e: Event) => {
e.stopPropagation();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export class MenuComponent
}
`;

private _clickContainer = (e: MouseEvent) => {
private readonly _clickContainer = (e: MouseEvent) => {
e.stopPropagation();
this.focusInput();
this.menu.closeSubMenu();
};

private searchRef = createRef<HTMLInputElement>();
private readonly searchRef = createRef<HTMLInputElement>();

override firstUpdated() {
const input = this.searchRef.value;
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/components/src/context-menu/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export function onMenuOpen(listener: MenuOpenListener) {
export class Menu {
private _cleanupFns: Array<() => void> = [];

private _currentFocused$ = signal<MenuFocusable>();
private readonly _currentFocused$ = signal<MenuFocusable>();

private _subMenu$ = signal<Menu>();
private readonly _subMenu$ = signal<Menu>();

closed = false;

Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/components/src/date-picker/date-picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export class DatePicker extends WithDisposable(LitElement) {
/** current active month */
private _cursor = new Date();

private _maxYear = 2099;
private readonly _maxYear = 2099;

private _minYear = 1970;
private readonly _minYear = 1970;

get _cardStyle() {
return {
Expand Down
2 changes: 1 addition & 1 deletion blocksuite/affine/components/src/date-picker/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,6 @@ export function getMonthMatrix(maybeDate: MaybeDate) {
}

export function clamp(num1: number, num2: number, value: number) {
const [min, max] = [num1, num2].sort();
const [min, max] = [num1, num2].sort((a, b) => a - b);
return Math.min(Math.max(value, min), max);
}
6 changes: 3 additions & 3 deletions blocksuite/affine/components/src/peek/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PeekViewProvider } from './service.js';
import type { PeekableClass, PeekViewService } from './type.js';

export class PeekableController<T extends PeekableClass> {
private _getPeekViewService = (): PeekViewService | null => {
private readonly _getPeekViewService = (): PeekViewService | null => {
return this.target.std.getOptional(PeekViewProvider);
};

Expand All @@ -25,7 +25,7 @@ export class PeekableController<T extends PeekableClass> {
}

constructor(
private target: T,
private enable?: (e: T) => boolean
private readonly target: T,
private readonly enable?: (e: T) => boolean
) {}
}
Loading

0 comments on commit 3a82da0

Please sign in to comment.