diff --git a/.betterer.results b/.betterer.results index 2f0796eb0a0..0f974928fec 100644 --- a/.betterer.results +++ b/.betterer.results @@ -2567,11 +2567,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/core/utils/errors.test.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] - ], - "public/app/core/utils/errors.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/core/utils/explore.test.ts:5381": [ @@ -7737,9 +7732,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "14"], [0, 0, 0, "Do not use any type assertions.", "15"] ], - "public/app/plugins/panel/xychart/types.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/polyfills/old-mediaquerylist.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -7767,8 +7759,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "6"] ], "public/app/types/dashboard.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/types/events.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -7785,9 +7776,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "11"], [0, 0, 0, "Unexpected any. Specify a different type.", "12"] ], - "public/app/types/explore.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], "public/app/types/jquery/jquery.d.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -7799,11 +7787,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "7"], [0, 0, 0, "Unexpected any. Specify a different type.", "8"] ], - "public/app/types/plugins.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] - ], "public/app/types/store.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -7820,16 +7803,11 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/test/core/redux/mocks.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/test/core/redux/reducerTester.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"] + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/test/core/redux/reduxTester.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -7881,17 +7859,6 @@ exports[`better eslint`] = { "public/test/matchers/index.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/test/matchers/toEmitValues.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"] - ], "public/test/matchers/toEmitValuesWith.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -7902,23 +7869,6 @@ exports[`better eslint`] = { "public/test/matchers/utils.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/test/mocks/angular.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] - ], - "public/test/mocks/backend_srv.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"] - ], - "public/test/mocks/common.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] - ], - "public/test/mocks/datasource_srv.ts:5381": [ - [0, 0, 0, "Unexpected any. Specify a different type.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"] - ], "public/test/mocks/workers.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] diff --git a/public/app/core/utils/errors.test.ts b/public/app/core/utils/errors.test.ts index 65f05d639d3..fcddaaa1470 100644 --- a/public/app/core/utils/errors.test.ts +++ b/public/app/core/utils/errors.test.ts @@ -1,3 +1,4 @@ +import { FetchError } from '@grafana/runtime'; import { getMessageFromError } from 'app/core/utils/errors'; describe('errors functions', () => { @@ -15,7 +16,7 @@ describe('errors functions', () => { describe('when getMessageFromError gets an error object with message field', () => { beforeEach(() => { - message = getMessageFromError({ message: 'error string' } as Error); + message = getMessageFromError(new Error('error string')); }); it('should return the message text', () => { @@ -25,7 +26,7 @@ describe('errors functions', () => { describe('when getMessageFromError gets an error object with data.message field', () => { beforeEach(() => { - message = getMessageFromError({ data: { message: 'error string' } } as any); + message = getMessageFromError({ data: { message: 'error string' }, status: 500 } as FetchError); }); it('should return the message text', () => { @@ -35,7 +36,7 @@ describe('errors functions', () => { describe('when getMessageFromError gets an error object with statusText field', () => { beforeEach(() => { - message = getMessageFromError({ statusText: 'error string' } as any); + message = getMessageFromError({ data: 'foo', statusText: 'error string', status: 500 } as FetchError); }); it('should return the statusText text', () => { diff --git a/public/app/core/utils/errors.ts b/public/app/core/utils/errors.ts index ff68f598021..59f8468d6b4 100644 --- a/public/app/core/utils/errors.ts +++ b/public/app/core/utils/errors.ts @@ -1,17 +1,18 @@ -import { isString } from 'lodash'; +import { isFetchError } from '@grafana/runtime'; -export function getMessageFromError(err: string | (Error & { data?: any; statusText?: string })): string { - if (err && !isString(err)) { - if (err.message) { +export function getMessageFromError(err: unknown): string { + if (err) { + if (typeof err === 'string') { + return err; + } else if (err instanceof Error) { return err.message; - } else if (err.data && err.data.message) { - return err.data.message; - } else if (err.statusText) { - return err.statusText; - } else { - return JSON.stringify(err); + } else if (isFetchError(err)) { + if (err.data && err.data.message) { + return err.data.message; + } else if (err.statusText) { + return err.statusText; + } } } - - return err; + return JSON.stringify(err); } diff --git a/public/app/plugins/datasource/mixed/MixedDataSource.test.ts b/public/app/plugins/datasource/mixed/MixedDataSource.test.ts index d94588780aa..7fa133926c5 100644 --- a/public/app/plugins/datasource/mixed/MixedDataSource.test.ts +++ b/public/app/plugins/datasource/mixed/MixedDataSource.test.ts @@ -13,8 +13,8 @@ const datasourceSrv = new DatasourceSrvMock(defaultDS, { A: new MockObservableDataSourceApi('DSA', [{ data: ['AAAA'] }]), B: new MockObservableDataSourceApi('DSB', [{ data: ['BBBB'] }]), C: new MockObservableDataSourceApi('DSC', [{ data: ['CCCC'] }]), - D: new MockObservableDataSourceApi('DSD', [{ data: [] }], {}, 'syntax error near FROM'), - E: new MockObservableDataSourceApi('DSE', [{ data: [] }], {}, 'syntax error near WHERE'), + D: new MockObservableDataSourceApi('DSD', [{ data: [] }], undefined, 'syntax error near FROM'), + E: new MockObservableDataSourceApi('DSE', [{ data: [] }], undefined, 'syntax error near WHERE'), Loki: new MockObservableDataSourceApi('Loki', [ { data: ['A'], key: 'A' }, { data: ['B'], key: 'B' }, diff --git a/public/app/plugins/panel/xychart/types.ts b/public/app/plugins/panel/xychart/types.ts index 34f102410ee..d60a60b9d79 100644 --- a/public/app/plugins/panel/xychart/types.ts +++ b/public/app/plugins/panel/xychart/types.ts @@ -24,13 +24,6 @@ export interface ScatterHoverEvent { export type ScatterHoverCallback = (evt?: ScatterHoverEvent) => void; -export interface LegendInfo { - color: CanvasRenderingContext2D['strokeStyle']; - text: string; - symbol: string; - openEditor?: (evt: any) => void; -} - export interface ScatterFieldConfig extends GeneratedScatterFieldConfig { pointSymbol?: DimensionSupplier; } diff --git a/public/app/types/dashboard.ts b/public/app/types/dashboard.ts index 0f15ecc67b8..c897d8ddf04 100644 --- a/public/app/types/dashboard.ts +++ b/public/app/types/dashboard.ts @@ -84,7 +84,7 @@ export enum DashboardInitPhase { export interface DashboardInitError { message: string; - error: any; + error: unknown; } export enum KioskMode { diff --git a/public/app/types/explore.ts b/public/app/types/explore.ts index d9a630fa5c5..38678696ce4 100644 --- a/public/app/types/explore.ts +++ b/public/app/types/explore.ts @@ -9,7 +9,6 @@ import { HistoryItem, LogsModel, PanelData, - QueryHint, RawTimeRange, TimeRange, EventBusExtended, @@ -231,11 +230,8 @@ export interface QueryOptions { export interface QueryTransaction { id: string; done: boolean; - error?: string | JSX.Element; - hints?: QueryHint[]; request: DataQueryRequest; queries: DataQuery[]; - result?: any; // Table model / Timeseries[] / Logs scanning?: boolean; } diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts index 12bb6984e62..a6d6f68ab47 100644 --- a/public/app/types/plugins.ts +++ b/public/app/types/plugins.ts @@ -1,5 +1,4 @@ import { PanelPlugin, PluginError, PluginMeta } from '@grafana/data'; -import { TemplateSrv } from '@grafana/runtime'; export interface PluginDashboard { dashboardId: number; @@ -31,13 +30,3 @@ export interface PluginsState { isLoadingPluginDashboards: boolean; panels: PanelPluginsIndex; } - -/** - * @deprecated use VariableQueryEditorProps instead - */ -export interface VariableQueryProps { - query: any; - onChange: (query: any, definition: string) => void; - datasource: any; - templateSrv: TemplateSrv; -} diff --git a/public/test/core/redux/mocks.ts b/public/test/core/redux/mocks.ts index c25f96728e1..a65bf971c7f 100644 --- a/public/test/core/redux/mocks.ts +++ b/public/test/core/redux/mocks.ts @@ -5,8 +5,8 @@ export const mockToolkitActionCreator = (creator: PayloadActio }; export type ToolkitActionCreatorWithoutPayloadMockType = typeof mockToolkitActionCreatorWithoutPayload & - ActionCreatorWithoutPayload; + ActionCreatorWithoutPayload; -export const mockToolkitActionCreatorWithoutPayload = (creator: ActionCreatorWithoutPayload) => { +export const mockToolkitActionCreatorWithoutPayload = (creator: ActionCreatorWithoutPayload) => { return Object.assign(jest.fn(), creator); }; diff --git a/public/test/core/redux/reducerTester.ts b/public/test/core/redux/reducerTester.ts index 49c7dad1854..145dadb0e9a 100644 --- a/public/test/core/redux/reducerTester.ts +++ b/public/test/core/redux/reducerTester.ts @@ -30,7 +30,7 @@ interface ObjectType extends Object { export const deepFreeze = (obj: T): T => { Object.freeze(obj); - const isNotException = (object: any, propertyName: any) => + const isNotException = (object: unknown, propertyName: string) => typeof object === 'function' ? propertyName !== 'caller' && propertyName !== 'callee' && propertyName !== 'arguments' : true; @@ -39,7 +39,7 @@ export const deepFreeze = (obj: T): T => { if (obj && obj instanceof Object) { const object: ObjectType = obj; Object.getOwnPropertyNames(object).forEach((propertyName) => { - const objectProperty: any = object[propertyName]; + const objectProperty = object[propertyName]; if ( hasOwnProp.call(object, propertyName) && isNotException(object, propertyName) && diff --git a/public/test/matchers/toEmitValues.ts b/public/test/matchers/toEmitValues.ts index 80e96d7e32c..d2987471a38 100644 --- a/public/test/matchers/toEmitValues.ts +++ b/public/test/matchers/toEmitValues.ts @@ -4,7 +4,7 @@ import { Observable, Subscription } from 'rxjs'; import { expectObservable, forceObservableCompletion } from './utils'; -function passMessage(received: any[], expected: any[]) { +function passMessage(received: unknown[], expected: unknown[]) { return `${matcherHint('.not.toEmitValues')} Expected observable to emit values: @@ -14,7 +14,7 @@ function passMessage(received: any[], expected: any[]) { `; } -function failMessage(received: any[], expected: any[]) { +function failMessage(received: unknown[], expected: unknown[]) { return `${matcherHint('.toEmitValues')} Expected observable to emit values: @@ -24,7 +24,7 @@ function failMessage(received: any[], expected: any[]) { `; } -function tryExpectations(received: any[], expected: any[]): jest.CustomMatcherResult { +function tryExpectations(received: unknown[], expected: unknown[]): jest.CustomMatcherResult { try { if (received.length !== expected.length) { return { @@ -58,14 +58,14 @@ function tryExpectations(received: any[], expected: any[]): jest.CustomMatcherRe } } -export function toEmitValues(received: Observable, expected: any[]): Promise { +export function toEmitValues(received: Observable, expected: unknown[]): Promise { const failsChecks = expectObservable(received); if (failsChecks) { return Promise.resolve(failsChecks); } return new Promise((resolve) => { - const receivedValues: any[] = []; + const receivedValues: unknown[] = []; const subscription = new Subscription(); subscription.add( diff --git a/public/test/mocks/angular.ts b/public/test/mocks/angular.ts deleted file mode 100644 index 185d64214fd..00000000000 --- a/public/test/mocks/angular.ts +++ /dev/null @@ -1,17 +0,0 @@ -export default class AngularJSMock { - service: any; - controller: any; - directive: any; - - constructor() { - this.service = jest.fn(); - this.controller = jest.fn(); - this.directive = jest.fn(); - } - - module() { - return this; - } -} - -module.exports = AngularJSMock; diff --git a/public/test/mocks/backend_srv.ts b/public/test/mocks/backend_srv.ts deleted file mode 100644 index 32c04866395..00000000000 --- a/public/test/mocks/backend_srv.ts +++ /dev/null @@ -1,5 +0,0 @@ -export class BackendSrvMock { - search: any; - - constructor() {} -} diff --git a/public/test/mocks/common.ts b/public/test/mocks/common.ts deleted file mode 100644 index 5736eae061b..00000000000 --- a/public/test/mocks/common.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { NavModel, NavModelItem } from '@grafana/data'; - -export const backendSrv = { - get: jest.fn(), - getDashboard: jest.fn(), - getDashboardByUid: jest.fn(), - getFolderByUid: jest.fn(), - post: jest.fn(), -}; - -export function createNavTree(...args: any[]) { - const root: any[] = []; - let node = root; - for (const arg of args) { - const child: any = { id: arg, url: `/url/${arg}`, text: `${arg}-Text`, children: [] }; - node.push(child); - node = child.children; - } - - return root; -} - -export function createNavModel(title: string, ...tabs: string[]): NavModel { - const node: NavModelItem = { - id: title, - text: title, - icon: 'exclamation-triangle', - subTitle: 'subTitle', - url: title, - children: [], - breadcrumbs: [], - }; - - const children: NavModelItem[] = []; - - for (const tab of tabs) { - children.push({ - id: tab, - subTitle: 'subTitle', - url: title, - text: title, - active: false, - }); - } - - children[0].active = true; - - node.children = children; - - return { - node: node, - main: node, - }; -} diff --git a/public/test/mocks/datasource_srv.ts b/public/test/mocks/datasource_srv.ts index d7c9844158f..90c182b657c 100644 --- a/public/test/mocks/datasource_srv.ts +++ b/public/test/mocks/datasource_srv.ts @@ -31,7 +31,12 @@ export class DatasourceSrvMock { export class MockDataSourceApi extends DataSourceApi { result: DataQueryResponse = { data: [] }; - constructor(name?: string, result?: DataQueryResponse, meta?: any, public error: string | null = null) { + constructor( + name?: string, + result?: DataQueryResponse, + meta?: DataSourcePluginMeta, + public error: string | null = null + ) { super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings); if (result) { this.result = result; @@ -60,7 +65,12 @@ export class MockDataSourceApi extends DataSourceApi { export class MockObservableDataSourceApi extends DataSourceApi { results: DataQueryResponse[] = [{ data: [] }]; - constructor(name?: string, results?: DataQueryResponse[], meta?: any, private error: string | null = null) { + constructor( + name?: string, + results?: DataQueryResponse[], + meta?: DataSourcePluginMeta, + private error: string | null = null + ) { super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings); if (results) {