Skip to content

Commit

Permalink
chore: enable ESLint rule "unbound-method" (#4449)
Browse files Browse the repository at this point in the history
  • Loading branch information
adidahiya committed Dec 9, 2020
1 parent 0808dd5 commit 379ee55
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import * as ContextMenu from "./contextMenu";

export interface IContextMenuTargetComponent extends React.Component {
render(): React.ReactElement<any> | null | undefined;
renderContextMenu(e: React.MouseEvent<HTMLElement>): JSX.Element | undefined;
onContextMenuClose?(): void;
renderContextMenu: (e: React.MouseEvent<HTMLElement>) => JSX.Element | undefined;
onContextMenuClose?: () => void;
}

export function ContextMenuTarget<T extends IConstructor<IContextMenuTargetComponent>>(WrappedComponent: T) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/hotkeys/hotkeysTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface IHotkeysTargetComponent extends React.Component {
* Components decorated with the `@HotkeysTarget` decorator must implement
* this method, and it must return a `Hotkeys` React element.
*/
renderHotkeys(): React.ReactElement<IHotkeysProps>;
renderHotkeys: () => React.ReactElement<IHotkeysProps>;
}

export function HotkeysTarget<T extends IConstructor<IHotkeysTargetComponent>>(WrappedComponent: T) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/toast/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ export class Toaster extends AbstractPureComponent2<IToasterProps, IToasterState
}
}

private renderToast(toast: IToastOptions) {
private renderToast = (toast: IToastOptions) => {
return <Toast {...toast} onDismiss={this.getDismissHandler(toast)} />;
}
};

private createToastOptions(props: IToastProps, key = `toast-${this.toastId++}`) {
// clone the object before adding the key prop to avoid leaking the mutation
Expand Down
7 changes: 6 additions & 1 deletion packages/core/test/popover/popoverTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,12 @@ describe("<Popover>", () => {
wrapper.popoverElement = (wrapper.instance() as Popover).popoverElement!;
wrapper.targetElement = (wrapper.instance() as Popover).targetElement!;
wrapper.assertFindClass = (className: string, expected = true, msg = className) => {
(expected ? assert.isTrue : assert.isFalse)(wrapper!.findClass(className).exists(), msg);
const actual = wrapper!.findClass(className);
if (expected) {
assert.isTrue(actual.exists(), msg);
} else {
assert.isFalse(actual.exists(), msg);
}
return wrapper!;
};
wrapper.assertIsOpen = (isOpen = true, index = 0) => {
Expand Down
8 changes: 4 additions & 4 deletions packages/docs-app/src/components/blueprintDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class BlueprintDocs extends React.Component<IBlueprintDocsProps, { themeN
return <NavMenuItem {...props} />;
};

private renderPageActions(page: IPageData) {
private renderPageActions = (page: IPageData) => {
return (
<AnchorButton
href={`${GITHUB_SOURCE_URL}/${page.sourcePath}`}
Expand All @@ -125,7 +125,7 @@ export class BlueprintDocs extends React.Component<IBlueprintDocsProps, { themeN
text="Edit this page"
/>
);
}
};

private maybeRenderPageTag(reference: string) {
const tag = this.props.docs.pages[reference].metadata.tag;
Expand All @@ -139,9 +139,9 @@ export class BlueprintDocs extends React.Component<IBlueprintDocsProps, { themeN
);
}

private renderViewSourceLinkText(entry: ITsDocBase) {
private renderViewSourceLinkText = (entry: ITsDocBase) => {
return `@blueprintjs/${entry.fileName.split("/", 2)[1]}`;
}
};

private maybeRenderPackageLink(packageName: string) {
const pkg = this.getNpmPackage(packageName);
Expand Down
4 changes: 2 additions & 2 deletions packages/docs-app/src/components/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class Icons extends React.PureComponent<IIconsProps, IIconsState> {
);
}

private maybeRenderIconGroup(groupName: string, index: number) {
private maybeRenderIconGroup = (groupName: string, index: number) => {
const { iconRenderer } = this.props;
const iconElements = this.getFilteredIcons(groupName).map(iconRenderer);
if (iconElements.length === 0) {
Expand All @@ -84,7 +84,7 @@ export class Icons extends React.PureComponent<IIconsProps, IIconsState> {
{iconElements}
</div>
);
}
};

private renderZeroState() {
return <NonIdealState className={Classes.TEXT_MUTED} icon="zoom-out" description="No icons found" />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ export class BreadcrumbsExample extends React.PureComponent<IExampleProps, IBrea
);
}

private renderLabel(value: number) {
private renderLabel = (value: number) => {
return `${value}%`;
}
};

private handleChangeWidth = (width: number) => this.setState({ width });
private handleChangeRenderCurrentAsInput = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ export class CollapsibleListExample extends React.PureComponent<IExampleProps, I
/* eslint-enable deprecation/deprecation */
}

private renderBreadcrumb(props: IMenuItemProps) {
private renderBreadcrumb = (props: IMenuItemProps) => {
if (props.href != null) {
return <a className={Classes.BREADCRUMB}>{props.text}</a>;
} else {
return <span className={classNames(Classes.BREADCRUMB, Classes.BREADCRUMB_CURRENT)}>{props.text}</span>;
}
}
};

private handleChangeCount = (visibleItemCount: number) => this.setState({ visibleItemCount });
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ export class SliderExample extends React.PureComponent<IExampleProps, ISliderExa
return (value: number) => this.setState({ [key]: value });
}

private renderLabel2(val: number) {
private renderLabel2 = (val: number) => {
return `${Math.round(val * 100)}%`;
}
};

private renderLabel3(val: number) {
private renderLabel3 = (val: number) => {
return val === 0 ? ${val}` : ${val},000`;
}
};
}
4 changes: 2 additions & 2 deletions packages/docs-app/src/examples/core-examples/toastExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ export class ToastExample extends React.PureComponent<IExampleProps<IBlueprintEx
);
}

private renderToastDemo(toast: IToastDemo, index: number) {
private renderToastDemo = (toast: IToastDemo, index: number) => {
// tslint:disable-next-line:jsx-no-lambda
return <Button intent={toast.intent} key={index} text={toast.button} onClick={() => this.addToast(toast)} />;
}
};

private renderProgress(amount: number): IToastProps {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,20 @@ class RecordSortableColumn extends AbstractSortableColumn {
}
}

private toWins(a: any) {
private toWins = (a: any) => {
const match = RecordSortableColumn.WIN_LOSS_PATTERN.exec(a);
return match == null ? -1 : parseInt(match[1], 10);
}
};

private toTies(a: any) {
private toTies = (a: any) => {
const match = RecordSortableColumn.WIN_LOSS_PATTERN.exec(a);
return match == null || match[3] == null ? -1 : parseInt(match[3], 10);
}
};

private toLosses(a: any) {
private toLosses = (a: any) => {
const match = RecordSortableColumn.WIN_LOSS_PATTERN.exec(a);
return match == null ? -1 : parseInt(match[5], 10);
}
};
}

export class TableSortableExample extends React.PureComponent<IExampleProps> {
Expand Down
10 changes: 5 additions & 5 deletions packages/docs-theme/src/common/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ export interface IDocumentationContext {
* Get the Documentalist data.
* Use the `hasTypescriptData` and `hasKssData` typeguards before accessing those plugins' data.
*/
getDocsData(): IDocsData;
getDocsData: () => IDocsData;

/** Render a block of Documentalist documentation to a React node. */
renderBlock(block: IBlock): React.ReactNode;
renderBlock: (block: IBlock) => React.ReactNode;

/** Render a Documentalist Typescript type string to a React node. */
renderType(type: string): React.ReactNode;
renderType: (type: string) => React.ReactNode;

/** Render the text of a "View source" link. */
renderViewSourceLinkText(entry: ITsDocBase): React.ReactNode;
renderViewSourceLinkText: (entry: ITsDocBase) => React.ReactNode;

/** Open the API browser to the given member name. */
showApiDocs(name: string): void;
showApiDocs: (name: string) => void;
}

/**
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint-config/typescript-eslint-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@
"lib": "always"
}
],
"@typescript-eslint/unbound-method": [
"error",
{
"ignoreStatic": true
}
],
"@typescript-eslint/unified-signatures": "error"
}
Loading

1 comment on commit 379ee55

@blueprint-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chore: enable ESLint rule "unbound-method" (#4449)

Previews: documentation | landing | table

Please sign in to comment.