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

refactor: migrate TSLint rules to ESLint equivalents #4158

Merged
merged 17 commits into from
May 29, 2020
Merged
Prev Previous commit
Next Next commit
manual lint fixes
  • Loading branch information
adidahiya committed May 27, 2020
commit 9a2dc21d741ecaff06060b60a068da247ee3a71c
27 changes: 27 additions & 0 deletions packages/core/src/common/context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2020 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// simplified typings copied from @types/prop-types, to avoid that explicit dependency

export type Validator = (
props: { [key: string]: any },
propName: string,
componentName: string,
location: string,
propFullName: string,
) => Error | null;

export type ValidationMap<T> = { [K in keyof T]?: Validator };
2 changes: 1 addition & 1 deletion packages/core/src/components/context-menu/context-menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ the context menu is closed.
import { ContextMenuTarget, Menu, MenuItem } from "@blueprintjs/core";

@ContextMenuTarget
class RightClickMe extends React.Component<{}> {
class RightClickMe extends React.Component {
public render() {
// root element must support `onContextMenu`
return <div>{...}</div>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/forms/numeric-input.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ provided to the callback both as a number and as a string.
```tsx
import { NumericInput } from "@blueprintjs/core";

export class NumericInputExample extends React.Component<{}> {
export class NumericInputExample extends React.Component {
public render() {
return <NumericInput onValueChange={this.handleValueChange} />;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/hotkeys/hotkeys.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { Hotkey, Hotkeys, HotkeysTarget } from "@blueprintjs/core";
import * as React from "react";

@HotkeysTarget
export class MyComponent extends React.Component<{}> {
export class MyComponent extends React.Component {
public render() {
return <div>Custom content</div>;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/hotkeys/hotkeys.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { Hotkey, IHotkeyProps } from "./hotkey";
import { IHotkeysProps } from "./hotkeysTypes";

@polyfill
export class Hotkeys extends AbstractPureComponent2<IHotkeysProps, {}> {
export class Hotkeys extends AbstractPureComponent2<IHotkeysProps> {
public static displayName = `${DISPLAYNAME_PREFIX}.Hotkeys`;

public static defaultProps = {
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ export interface IIconProps extends IIntentProps, IProps {
* required because it determines the content of the component, but it can
* be explicitly set to falsy values to render nothing.
*
* - If `null` or `undefined` or `false`, this component will render
* nothing.
* - If `null` or `undefined` or `false`, this component will render nothing.
* - If given an `IconName` (a string literal union of all icon names), that
* icon will be rendered as an `<svg>` with `<path>` tags. Unknown strings
* will render a blank icon to occupy space.
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/panel-stack/panelStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class PanelStack extends AbstractPureComponent2<IPanelStackProps, IPanelS
stack: this.props.stack != null ? this.props.stack.slice().reverse() : [this.props.initialPanel],
};

public componentDidUpdate(prevProps: IPanelStackProps, _prevState: IPanelStackState, _snapshot: {}) {
super.componentDidUpdate(prevProps, _prevState, _snapshot);
public componentDidUpdate(prevProps: IPanelStackProps, prevState: IPanelStackState) {
super.componentDidUpdate(prevProps, prevState);

// Always update local stack if stack prop changes
if (this.props.stack !== prevProps.stack && prevProps.stack != null) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/popover/popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export class Popover extends AbstractPureComponent2<IPopoverProps, IPopoverState
this.updateDarkParent();
}

public componentDidUpdate(_: IPopoverProps, __: IPopoverState, snapshot: {}) {
super.componentDidUpdate(_, __, snapshot);
public componentDidUpdate(props: IPopoverProps, state: IPopoverState) {
super.componentDidUpdate(props, state);
this.updateDarkParent();

const nextIsOpen = this.getIsOpen(this.props);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/portal/portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

import { ValidationMap } from "prop-types";
import * as React from "react";
import * as ReactDOM from "react-dom";

import * as Classes from "../../common/classes";
import { ValidationMap } from "../../common/context";
import * as Errors from "../../common/errors";
import { DISPLAYNAME_PREFIX, IProps } from "../../common/props";
import { isFunction } from "../../common/utils";
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/components/slider/multiSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ export class MultiSlider extends AbstractPureComponent2<IMultiSliderProps, ISlid
this.updateTickSize();
}

public componentDidUpdate(prevProps: IMultiSliderProps, prevState: ISliderState, ss: {}) {
super.componentDidUpdate(prevProps, prevState, ss);
public componentDidUpdate(prevProps: IMultiSliderProps, prevState: ISliderState) {
super.componentDidUpdate(prevProps, prevState);
this.updateTickSize();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as Utils from "../../common/utils";
import { ITabProps, Tab, TabId } from "./tab";
import { generateTabPanelId, generateTabTitleId, TabTitle } from "./tabTitle";

export const Expander: React.SFC<{}> = () => <div className={Classes.FLEX_EXPANDER} />;
export const Expander: React.SFC = () => <div className={Classes.FLEX_EXPANDER} />;

type TabElement = React.ReactElement<ITabProps & { children: React.ReactNode }>;

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/components/tag-input/tagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ const NONE = -1;
export class TagInput extends AbstractPureComponent2<ITagInputProps, ITagInputState> {
public static displayName = `${DISPLAYNAME_PREFIX}.TagInput`;

public static defaultProps: Partial<ITagInputProps> & object = {
public static defaultProps: Partial<ITagInputProps> & Record<string, unknown> = {
addOnBlur: false,
addOnPaste: true,
inputProps: {},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/context-menu/contextMenuTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe("ContextMenu", () => {
afterEach(() => ContextMenu.hide());

it("Decorator does not mutate the original class", () => {
class TestComponent extends React.Component<{}> {
class TestComponent extends React.Component {
public render() {
return <div />;
}
Expand Down Expand Up @@ -101,7 +101,7 @@ describe("ContextMenu", () => {
/* -- uncomment this test to confirm compilation failure -- */
// it("TypeScript compilation fails if decorated class does not implement renderContextMenu", () => {
// @ContextMenuTarget
// return class TypeScriptFail extends React.Component<{}> {
// return class TypeScriptFail extends React.Component {
// public render() { return <article />; }
// }
// });
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/controls/numericInputTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,8 @@ describe("<NumericInput>", () => {
function runInteractionSuite(
incrementDescription: string,
decrementDescription: string,
simulateIncrement: (component: ReactWrapper<any>, mockEvent?: object) => void,
simulateDecrement: (component: ReactWrapper<any>, mockEvent?: object) => void,
simulateIncrement: (component: ReactWrapper<any>, mockEvent?: Record<string, unknown>) => void,
simulateDecrement: (component: ReactWrapper<any>, mockEvent?: Record<string, unknown>) => void,
) {
it(`increments by stepSize on ${incrementDescription}`, () => {
const component = createNumericInputForInteractionSuite();
Expand Down
4 changes: 2 additions & 2 deletions packages/core/test/hotkeys/hotkeysTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe("Hotkeys", () => {
});

it("Decorator does not mutate the original class", () => {
class TestComponent extends React.Component<{}> {
class TestComponent extends React.Component {
public render() {
return <div />;
}
Expand Down Expand Up @@ -213,7 +213,7 @@ describe("Hotkeys", () => {
const handleKeyDown = spy();

@HotkeysTarget
class ComboComponent extends React.Component<{}> {
class ComboComponent extends React.Component {
public renderHotkeys() {
return (
<Hotkeys>
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/tabs/tabsTests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ describe("<Tabs>", () => {
function findTabById(wrapper: ReactWrapper<ITabsProps>, id: string) {
// Need this to get the right overload signature
// eslint-disable-line @typescript-eslint/consistent-type-assertions
return wrapper.find(TAB).filter({ "data-tab-id": id } as React.HTMLAttributes<{}>);
return wrapper.find(TAB).filter({ "data-tab-id": id } as React.HTMLAttributes<HTMLElement>);
}

function assertIndicatorPosition(wrapper: ReactWrapper<ITabsProps, ITabsState>, selectedTabId: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-app/src/components/colorPalettes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const ColorBar: React.SFC<{ colors: string[] }> = ({ colors }) => {
};

// a group of ColorPalettes, arranged by default in two columns
function createPaletteBook(palettes: string[][], className?: string): React.SFC<{}> {
function createPaletteBook(palettes: string[][], className?: string): React.SFC {
return () => (
<section className={classNames("docs-color-book", className)}>
{palettes.map((palette, index) => (
Expand Down
6 changes: 3 additions & 3 deletions packages/docs-app/src/components/colorSchemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,17 @@ export class ColorScheme extends React.PureComponent<IColorSchemeProps, IColorSc
}
}

export const QualitativeSchemePalette: React.SFC<{}> = () => <ColorBar colors={QUALITATIVE} />;
export const QualitativeSchemePalette: React.SFC = () => <ColorBar colors={QUALITATIVE} />;

export const SequentialSchemePalette: React.SFC<{}> = () => {
export const SequentialSchemePalette: React.SFC = () => {
const schemes = [
{ label: "Single hue", palettes: SINGLE_HUE },
{ label: "Multi-hue", palettes: SEQUENTIAL },
];
return <ColorScheme schemes={schemes} />;
};

export const DivergingSchemePalette: React.SFC<{}> = () => {
export const DivergingSchemePalette: React.SFC = () => {
const schemes = [{ diverging: true, label: "Diverging", palettes: DIVERGING }];
return <ColorScheme schemes={schemes} />;
};
8 changes: 4 additions & 4 deletions packages/docs-app/src/examples/core-examples/tabsExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class TabsExample extends React.PureComponent<IExampleProps, ITabsExample
private handleNavbarTabChange = (navbarTabId: TabId) => this.setState({ navbarTabId });
}

const ReactPanel: React.SFC<{}> = () => (
const ReactPanel: React.SFC = () => (
<div>
<H3>Example panel: React</H3>
<p className={Classes.RUNNING_TEXT}>
Expand All @@ -107,7 +107,7 @@ const ReactPanel: React.SFC<{}> = () => (
</div>
);

const AngularPanel: React.SFC<{}> = () => (
const AngularPanel: React.SFC = () => (
<div>
<H3>Example panel: Angular</H3>
<p className={Classes.RUNNING_TEXT}>
Expand All @@ -118,7 +118,7 @@ const AngularPanel: React.SFC<{}> = () => (
</div>
);

const EmberPanel: React.SFC<{}> = () => (
const EmberPanel: React.SFC = () => (
<div>
<H3>Example panel: Ember</H3>
<p className={Classes.RUNNING_TEXT}>
Expand All @@ -130,7 +130,7 @@ const EmberPanel: React.SFC<{}> = () => (
</div>
);

const BackbonePanel: React.SFC<{}> = () => (
const BackbonePanel: React.SFC = () => (
<div>
<H3>Backbone</H3>
</div>
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-theme/src/tags/reactDocs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { ITag } from "@documentalist/client";
import * as React from "react";

export interface IDocsMap {
[name: string]: React.ComponentClass<{}>;
[name: string]: React.ComponentClass;
}

export class ReactDocsTagRenderer {
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-config/eslint-plugin-rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
],
"import/order": "off",
"jsdoc/check-alignment": "error",
"jsdoc/check-indentation": "error",
"jsdoc/check-indentation": "off",
"jsdoc/newline-after-description": "off"
}