Skip to content

Commit

Permalink
fix: lint errors (#420)
Browse files Browse the repository at this point in the history
* fix: lint errors

* fix: lint

* fix: more lints

* fix: broken test

* fix: singleton type
  • Loading branch information
kristw authored and zhaoyongjie committed Nov 26, 2021
1 parent 6190450 commit 62b2a50
Show file tree
Hide file tree
Showing 36 changed files with 70 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import { isDefined } from '@superset-ui/core';

function checkNumber(input: any): input is number {
function checkNumber(input: unknown): input is number {
return isDefined(input) && typeof input === 'number';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('WithLegend', () => {
<WithLegend debounceTime={1} width={500} height={500} renderChart={renderChart} />,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -49,6 +50,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -64,6 +66,7 @@ describe('WithLegend', () => {
<WithLegend debounceTime={1} renderChart={renderChart} renderLegend={renderLegend} />,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -84,6 +87,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -104,6 +108,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -124,6 +129,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -144,6 +150,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand All @@ -165,6 +172,7 @@ describe('WithLegend', () => {
/>,
);

// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();
// Have to delay more than debounceTime (1ms)
return promiseTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class ChartClient {
...options,
} as RequestConfig)
.then(response => response.json as Json)
.then(json => json.form_data);
.then(json => json.form_data as QueryFormData);

/*
* If formData is also specified, override API result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ChartDataProvider extends React.PureComponent<Props, State> {
.then(this.handleReceiveData)
.catch(this.handleError);
} catch (error) {
this.handleError(error);
this.handleError(error as Error);
}
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export default class SuperChart extends React.PureComponent<Props, {}> {
if (
queryData == null ||
queryData.data === null ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(Array.isArray(queryData.data) && queryData.data.length === 0)
) {
chart = <NoResultsComponent id={id} className={className} height={height} width={width} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { ChartType } from '../models/ChartPlugin';
import { PreTransformProps, TransformProps, PostTransformProps } from '../types/TransformFunction';
import { HandlerFunction } from '../types/Base';

const IDENTITY = (x: any) => x;
function IDENTITY<T>(x: T) {
return x;
}

const EMPTY = () => null;

Expand All @@ -24,7 +26,7 @@ const defaultProps = {
};

interface LoadingProps {
error: any;
error: { toString(): string };
}

interface LoadedModules {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export default function createLoadableRenderer<Props, Exports>(
const { onRenderFailure, onRenderSuccess } = this.props;
if (!loading) {
if (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
(onRenderFailure as Function)(error);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
} else if (loaded && Object.keys(loaded).length > 0) {
(onRenderSuccess as Function)();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type ChartControlPanel = { [key: string]: any };
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,29 @@ export default class ChartPlugin<T extends QueryFormData = QueryFormData> extend

register() {
const { key = isRequired('config.key') } = this.config;
getChartMetadataRegistry().registerValue(key, this.metadata);
getChartComponentRegistry().registerLoader(key, this.loadChart);
getChartControlPanelRegistry().registerValue(key, this.controlPanel);
getChartTransformPropsRegistry().registerLoader(key, this.loadTransformProps);
getChartMetadataRegistry().registerValue(key as string, this.metadata);
getChartComponentRegistry().registerLoader(key as string, this.loadChart);
getChartControlPanelRegistry().registerValue(key as string, this.controlPanel);
getChartTransformPropsRegistry().registerLoader(key as string, this.loadTransformProps);
if (this.loadBuildQuery) {
getChartBuildQueryRegistry().registerLoader(key, this.loadBuildQuery);
getChartBuildQueryRegistry().registerLoader(key as string, this.loadBuildQuery);
}

return this;
}

unregister() {
const { key = isRequired('config.key') } = this.config;
getChartMetadataRegistry().remove(key);
getChartComponentRegistry().remove(key);
getChartControlPanelRegistry().remove(key);
getChartTransformPropsRegistry().remove(key);
getChartBuildQueryRegistry().remove(key);
getChartMetadataRegistry().remove(key as string);
getChartComponentRegistry().remove(key as string);
getChartControlPanelRegistry().remove(key as string);
getChartTransformPropsRegistry().remove(key as string);
getChartBuildQueryRegistry().remove(key as string);

return this;
}

configure(config: { [key: string]: any }, replace?: boolean) {
configure(config: { [key: string]: unknown }, replace?: boolean) {
super.configure(config, replace);

return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class ChartProps {
this.width = width;
this.height = height;
this.annotationData = annotationData;
this.datasource = convertKeysToCamelCase(datasource);
this.datasource = convertKeysToCamelCase(datasource) as Datasource;
this.rawDatasource = datasource;
this.formData = convertKeysToCamelCase(formData);
this.rawFormData = formData;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type HandlerFunction = (...args: any[]) => void;
export type HandlerFunction = (...args: unknown[]) => void;

export interface PlainObject {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QueryFormData, QueryContext } from '@superset-ui/query';
import ChartProps from '../models/ChartProps';

export interface PlainProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ describe('SuperChart', () => {
height="100%"
/>,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();

return promiseTimeout(() => {
Expand All @@ -243,6 +244,7 @@ describe('SuperChart', () => {
height="125"
/>,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver([{ contentRect: { height: 125, width: 150 } }]);

return promiseTimeout(() => {
Expand All @@ -264,6 +266,7 @@ describe('SuperChart', () => {
height="25%"
/>,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver([{ contentRect: { height: 75, width: 50 } }]);

return promiseTimeout(() => {
Expand All @@ -283,6 +286,7 @@ describe('SuperChart', () => {
debounceTime={1}
/>,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();

return promiseTimeout(() => {
Expand Down Expand Up @@ -336,6 +340,7 @@ describe('SuperChart', () => {
Wrapper={MyWrapper}
/>,
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
triggerResizeObserver();

return promiseTimeout(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('reactify(renderFn)', () => {
const TheChart = reactify(renderFn);
const TheChartWithWillUnmountHook = reactify(renderFn, { componentWillUnmount: willUnmountCb });

class TestComponent extends React.PureComponent<{}, { content: string }, any> {
class TestComponent extends React.PureComponent<{}, { content: string }> {
constructor(props = {}) {
super(props);
this.state = { content: 'abc' };
Expand All @@ -46,7 +46,7 @@ describe('reactify(renderFn)', () => {
}
}

class AnotherTestComponent extends React.PureComponent<{}, {}, any> {
class AnotherTestComponent extends React.PureComponent<{}, {}> {
render() {
return <TheChartWithWillUnmountHook id="another_test" />;
}
Expand Down Expand Up @@ -99,7 +99,9 @@ describe('reactify(renderFn)', () => {
});
it('does not try to render if not mounted', () => {
const anotherRenderFn = jest.fn();
const AnotherChart = reactify(anotherRenderFn) as any; // enables valid new AnotherChart() call
const AnotherChart = reactify(anotherRenderFn); // enables valid new AnotherChart() call
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
new AnotherChart({ id: 'test' }).execute();
expect(anotherRenderFn).not.toHaveBeenCalled();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe('ChartProps', () => {
formData: RAW_FORM_DATA,
queryData: QUERY_DATA,
});
expect(props.formData.someField).toEqual(1);
expect(props.formData.someField as number).toEqual(1);
expect(props.datasource.columnFormats).toEqual(RAW_DATASOURCE.column_formats);
expect(props.rawFormData).toEqual(RAW_FORM_DATA);
expect(props.rawDatasource).toEqual(RAW_DATASOURCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('rejectAfterTimeout()', () => {

rejectAfterTimeout(10)
.then(throwIfCalled)
.catch(error => {
.catch((error: Error) => {
expect(error).toBeDefined();

return done();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function throwIfCalled(args: any) {
export default function throwIfCalled(args: unknown) {
throw new Error(`Unexpected call to throwIfCalled(): ${JSON.stringify(args)}`);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface PlainObject {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import camelCase from 'lodash/camelCase';
import isPlainObject from 'lodash/isPlainObject';
import mapKeys from 'lodash/mapKeys';

export default function convertKeysToCamelCase(object: any) {
export default function convertKeysToCamelCase<T>(object: T) {
if (object === null || object === undefined) {
return object;
}
if (isPlainObject(object)) {
return mapKeys(object, (_, k) => camelCase(k));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return mapKeys(object as { [key: string]: any }, (_, k) => camelCase(k)) as T;
}
throw new Error(`Cannot convert input that is not a plain object: ${object}`);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export default function isDefined(x: any) {
export default function isDefined(x: unknown) {
return x !== null && x !== undefined;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
interface ClassInterface<T> {
new (...args: any[]): T;
interface ClassInterface<T, Args extends unknown[]> {
new (...args: Args): T;
}

export default function makeSingleton<T>(BaseClass: ClassInterface<T>, ...args: any[]): () => T {
export default function makeSingleton<T, Args extends unknown[]>(
BaseClass: ClassInterface<T, Args>,
...args: Args
): () => T {
let singleton: T;

return function getInstance() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/** setTimeout that returns a promise */
export default function promiseTimeout(
export default function promiseTimeout<T>(
/** A function to be executed after the timer expires. */
func: Function,
func: (...args: unknown[]) => T,
/** The time, in milliseconds (thousandths of a second), the timer should wait before the specified function or code is executed. If this parameter is omitted, a value of 0 is used, meaning execute "immediately", or more accurately, as soon as possible. */
delay?: number,
) {
return new Promise(resolve => {
return new Promise<T>(resolve => {
setTimeout(() => {
resolve(func());
}, delay);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Preset', () => {
class Plugin4 extends Plugin {
register() {
const { key } = this.config;
values.push(key);
values.push(key as number);

return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ describe('Registry', () => {
it('returns a rejected promise if the item with specified key does not exist', () => {
const registry = new Registry();

return registry.getAsPromise('a').then(null, err => {
return registry.getAsPromise('a').then(null, (err: Error) => {
expect(err.toString()).toEqual('Error: Item with key "a" is not registered.');
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ describe('makeSingleton()', () => {

isSitting?: boolean;

constructor(name: string) {
this.name = name;
constructor(name?: string) {
this.name = name || 'Pluto';
}

sit() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable func-names, no-plusplus, react/sort-prop-types */
/* eslint-disable func-names, react/sort-prop-types */
import d3 from 'd3';
import PropTypes from 'prop-types';
import 'd3-svg-legend';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
/* eslint-disable no-continue, no-plusplus, no-bitwise */
/* eslint-disable no-continue, no-bitwise */
/* eslint-disable react/jsx-sort-default-props */
/* eslint-disable react/sort-prop-types */
import React from 'react';
Expand Down

0 comments on commit 62b2a50

Please sign in to comment.