Chore: some low-hanging type assertion fruit (#51618)

* some low-hanging type assertion fruit

* results
This commit is contained in:
Ashley Harrison 2022-06-30 10:40:00 +01:00 committed by GitHub
parent c8fa4a9397
commit 2a6b32598d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 85 additions and 128 deletions

View File

@ -4176,29 +4176,17 @@ exports[`better eslint`] = {
"public/app/features/alerting/unified/AmRoutes.tsx:746213791": [
[54, 20, 124, "Do not use any type assertions.", "1859971542"]
],
"public/app/features/alerting/unified/PanelAlertTabContent.test.tsx:2885585711": [
"public/app/features/alerting/unified/PanelAlertTabContent.test.tsx:2750168837": [
[148, 18, 168, "Do not use any type assertions.", "3635996173"],
[161, 14, 241, "Do not use any type assertions.", "583862789"],
[161, 14, 227, "Do not use any type assertions.", "578877230"],
[174, 5, 3, "Unexpected any. Specify a different type.", "193409811"],
[186, 56, 87, "Do not use any type assertions.", "3591252716"],
[188, 23, 3, "Unexpected any. Specify a different type.", "193409811"],
[188, 28, 3, "Unexpected any. Specify a different type.", "193409811"],
[189, 53, 90, "Do not use any type assertions.", "3360422103"],
[190, 6, 3, "Unexpected any. Specify a different type.", "193409811"],
[191, 6, 3, "Unexpected any. Specify a different type.", "193409811"],
[198, 43, 93, "Do not use any type assertions.", "491507647"],
[198, 43, 79, "Do not use any type assertions.", "2198135124"],
[202, 9, 3, "Unexpected any. Specify a different type.", "193409811"],
[224, 43, 122, "Do not use any type assertions.", "1400972852"],
[224, 43, 108, "Do not use any type assertions.", "2513195871"],
[229, 9, 3, "Unexpected any. Specify a different type.", "193409811"],
[251, 5, 46, "Do not use any type assertions.", "3849301614"],
[251, 5, 25, "Do not use any type assertions.", "2832141036"],
[251, 27, 3, "Unexpected any. Specify a different type.", "193409811"],
[253, 43, 70, "Do not use any type assertions.", "4292164046"],
[253, 43, 56, "Do not use any type assertions.", "2628506213"],
[256, 9, 3, "Unexpected any. Specify a different type.", "193409811"]
[257, 5, 46, "Do not use any type assertions.", "3849301614"],
[257, 5, 25, "Do not use any type assertions.", "2832141036"],
[257, 27, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/alerting/unified/Receivers.test.tsx:3742116867": [
[143, 34, 29, "Do not use any type assertions.", "2249960884"]
@ -4496,9 +4484,8 @@ exports[`better eslint`] = {
"public/app/features/annotations/components/AnnotationResultMapper.tsx:1382385589": [
[131, 41, 15, "Do not use any type assertions.", "3610795007"]
],
"public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx:46885179": [
[28, 10, 11, "Do not use any type assertions.", "750480870"],
[78, 17, 16, "Do not use any type assertions.", "388222280"]
"public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx:1738271764": [
[28, 10, 11, "Do not use any type assertions.", "750480870"]
],
"public/app/features/annotations/events_processing.ts:311785085": [
[2, 46, 3, "Unexpected any. Specify a different type.", "193409811"]
@ -4578,16 +4565,14 @@ exports[`better eslint`] = {
"public/app/features/canvas/runtime/root.tsx:2845174121": [
[24, 19, 36, "Do not use any type assertions.", "1413431594"]
],
"public/app/features/canvas/runtime/scene.tsx:4285479205": [
"public/app/features/canvas/runtime/scene.tsx:4221384430": [
[155, 61, 25, "Do not use any type assertions.", "588553285"],
[160, 42, 25, "Do not use any type assertions.", "588553285"]
],
"public/app/features/comments/CommentView.tsx:3338885322": [
[31, 20, 32, "Do not use any type assertions.", "3501587761"]
],
"public/app/features/dashboard/components/AddPanelWidget/AddPanelWidget.test.tsx:1976108855": [
[9, 15, 20, "Do not use any type assertions.", "2923490522"],
[10, 11, 16, "Do not use any type assertions.", "388222280"],
"public/app/features/dashboard/components/AddPanelWidget/AddPanelWidget.test.tsx:3529318871": [
[11, 14, 16, "Do not use any type assertions.", "2607709806"],
[11, 27, 3, "Unexpected any. Specify a different type.", "193409811"]
],
@ -4709,11 +4694,9 @@ exports[`better eslint`] = {
"public/app/features/dashboard/components/DashboardSettings/DashboardSettings.tsx:1752755114": [
[40, 53, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/dashboard/components/DashboardSettings/GeneralSettings.test.tsx:1246666905": [
"public/app/features/dashboard/components/DashboardSettings/GeneralSettings.test.tsx:428611755": [
[13, 14, 50, "Do not use any type assertions.", "3302172944"],
[15, 5, 3, "Unexpected any. Specify a different type.", "193409811"],
[19, 15, 428, "Do not use any type assertions.", "4070674009"],
[19, 15, 410, "Do not use any type assertions.", "815903200"]
[15, 5, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/dashboard/components/DashboardSettings/GeneralSettings.tsx:2117359978": [
[38, 14, 51, "Do not use any type assertions.", "4093646718"]
@ -5054,13 +5037,11 @@ exports[`better eslint`] = {
"public/app/features/dashboard/dashgrid/LazyLoader.tsx:2512448803": [
[52, 23, 60, "Do not use any type assertions.", "1332568031"]
],
"public/app/features/dashboard/dashgrid/PanelChrome.test.tsx:514058263": [
"public/app/features/dashboard/dashgrid/PanelChrome.test.tsx:3660061275": [
[24, 27, 184, "Do not use any type assertions.", "2137031202"],
[24, 27, 164, "Do not use any type assertions.", "4126965436"],
[30, 18, 53, "Do not use any type assertions.", "3326921050"],
[30, 18, 42, "Do not use any type assertions.", "1020693066"],
[36, 11, 258, "Do not use any type assertions.", "3677324054"],
[36, 11, 244, "Do not use any type assertions.", "2585800637"],
[45, 15, 188, "Do not use any type assertions.", "3092730874"],
[45, 15, 170, "Do not use any type assertions.", "2122268803"],
[53, 12, 104, "Do not use any type assertions.", "4098692416"],
@ -5227,7 +5208,7 @@ exports[`better eslint`] = {
[1031, 24, 100, "Do not use any type assertions.", "1490128200"],
[1031, 24, 89, "Do not use any type assertions.", "1592095128"]
],
"public/app/features/dashboard/state/DashboardModel.ts:2545728044": [
"public/app/features/dashboard/state/DashboardModel.ts:2406615335": [
[61, 8, 3, "Unexpected any. Specify a different type.", "193409811"],
[62, 15, 3, "Unexpected any. Specify a different type.", "193409811"],
[69, 6, 3, "Unexpected any. Specify a different type.", "193409811"],
@ -5253,7 +5234,6 @@ exports[`better eslint`] = {
[312, 10, 3, "Unexpected any. Specify a different type.", "193409811"],
[327, 27, 3, "Unexpected any. Specify a different type.", "193409811"],
[423, 32, 3, "Unexpected any. Specify a different type.", "193409811"],
[446, 14, 22, "Do not use any type assertions.", "1197383730"],
[473, 22, 3, "Unexpected any. Specify a different type.", "193409811"],
[689, 61, 3, "Unexpected any. Specify a different type.", "193409811"],
[693, 62, 3, "Unexpected any. Specify a different type.", "193409811"],
@ -5361,20 +5341,6 @@ exports[`better eslint`] = {
"public/app/features/dashboard/state/reducers.ts:2272523560": [
[64, 9, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/dashboard/state/utils.test.ts:1279742222": [
[8, 38, 64, "Do not use any type assertions.", "3380969"],
[8, 38, 50, "Do not use any type assertions.", "3221043074"],
[9, 37, 64, "Do not use any type assertions.", "524183405"],
[9, 37, 50, "Do not use any type assertions.", "420885766"],
[17, 38, 64, "Do not use any type assertions.", "3380969"],
[17, 38, 50, "Do not use any type assertions.", "3221043074"],
[18, 37, 64, "Do not use any type assertions.", "1764689129"],
[18, 37, 50, "Do not use any type assertions.", "560997762"],
[26, 38, 127, "Do not use any type assertions.", "281200413"],
[26, 38, 113, "Do not use any type assertions.", "3150415926"],
[30, 37, 64, "Do not use any type assertions.", "524183405"],
[30, 37, 50, "Do not use any type assertions.", "420885766"]
],
"public/app/features/dashboard/utils/getPanelMenu.test.ts:2133911514": [
[98, 18, 3, "Unexpected any. Specify a different type.", "193409811"],
[99, 19, 3, "Unexpected any. Specify a different type.", "193409811"],
@ -7395,18 +7361,10 @@ exports[`better eslint`] = {
[87, 60, 3, "Unexpected any. Specify a different type.", "193409811"],
[88, 24, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/variables/inspect/utils.test.ts:554142034": [
[224, 11, 103, "Do not use any type assertions.", "2980842252"],
[224, 11, 89, "Do not use any type assertions.", "4144868007"],
[268, 11, 103, "Do not use any type assertions.", "2980842252"],
[268, 11, 89, "Do not use any type assertions.", "4144868007"],
[286, 11, 103, "Do not use any type assertions.", "2980842252"],
[286, 11, 89, "Do not use any type assertions.", "4144868007"],
[304, 11, 103, "Do not use any type assertions.", "2980842252"],
[304, 11, 89, "Do not use any type assertions.", "4144868007"],
[358, 30, 3, "Unexpected any. Specify a different type.", "193409811"],
[1220, 45, 3, "Unexpected any. Specify a different type.", "193409811"],
[1719, 28, 3, "Unexpected any. Specify a different type.", "193409811"]
"public/app/features/variables/inspect/utils.test.ts:1490985138": [
[346, 30, 3, "Unexpected any. Specify a different type.", "193409811"],
[1208, 45, 3, "Unexpected any. Specify a different type.", "193409811"],
[1707, 28, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/features/variables/inspect/utils.ts:3863933569": [
[62, 77, 3, "Unexpected any. Specify a different type.", "193409811"],
@ -10977,7 +10935,7 @@ exports[`better eslint`] = {
[41, 64, 3, "Unexpected any. Specify a different type.", "193409811"],
[41, 69, 3, "Unexpected any. Specify a different type.", "193409811"]
],
"public/app/plugins/panel/canvas/editor/LayerElementListEditor.tsx:374041207": [
"public/app/plugins/panel/canvas/editor/LayerElementListEditor.tsx:2123096129": [
[21, 33, 3, "Unexpected any. Specify a different type.", "193409811"],
[40, 30, 44, "Do not use any type assertions.", "712744497"]
],

View File

@ -159,7 +159,7 @@ const dashboard = {
},
} as DashboardModel;
const panel = {
const panel = new PanelModel({
datasource: {
type: 'prometheus',
uid: dataSources.prometheus.uid,
@ -172,7 +172,7 @@ const panel = {
refId: 'A',
},
],
} as any as PanelModel;
});
const ui = {
row: byTestId('row'),
@ -196,11 +196,14 @@ describe('PanelAlertTabContent', () => {
});
it('Will take into account panel maxDataPoints', async () => {
await renderAlertTabContent(dashboard, {
...panel,
maxDataPoints: 100,
interval: '10s',
} as any as PanelModel);
await renderAlertTabContent(
dashboard,
new PanelModel({
...panel,
maxDataPoints: 100,
interval: '10s',
})
);
const button = await ui.createButton.find();
const href = button.href;
@ -222,12 +225,15 @@ describe('PanelAlertTabContent', () => {
});
it('Will work with default datasource', async () => {
await renderAlertTabContent(dashboard, {
...panel,
datasource: undefined,
maxDataPoints: 100,
interval: '10s',
} as any as PanelModel);
await renderAlertTabContent(
dashboard,
new PanelModel({
...panel,
datasource: undefined,
maxDataPoints: 100,
interval: '10s',
})
);
const button = await ui.createButton.find();
const href = button.href;
@ -251,10 +257,13 @@ describe('PanelAlertTabContent', () => {
it('Will take into account datasource minInterval', async () => {
(getDatasourceSrv() as any as MockDataSourceSrv).datasources[dataSources.prometheus.uid].interval = '7m';
await renderAlertTabContent(dashboard, {
...panel,
maxDataPoints: 100,
} as any as PanelModel);
await renderAlertTabContent(
dashboard,
new PanelModel({
...panel,
maxDataPoints: 100,
})
);
const button = await ui.createButton.find();
const href = button.href;

View File

@ -76,7 +76,7 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
executeAnnotationQuery(
{
range: getTimeSrv().timeRange(),
panel: {} as PanelModel,
panel: new PanelModel({}),
dashboard,
},
datasource,

View File

@ -7,8 +7,8 @@ import { AddPanelWidgetUnconnected as AddPanelWidget, Props } from './AddPanelWi
const getTestContext = (propOverrides?: object) => {
const props: Props = {
dashboard: {} as DashboardModel,
panel: {} as PanelModel,
dashboard: new DashboardModel({}),
panel: new PanelModel({}),
addPanel: jest.fn() as any,
};
Object.assign(props, propOverrides);

View File

@ -17,19 +17,21 @@ setBackendSrv({
const setupTestContext = (options: Partial<Props>) => {
const defaults: Props = {
dashboard: {
title: 'test dashboard title',
description: 'test dashboard description',
timepicker: {
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d', '2d'],
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
dashboard: new DashboardModel(
{
title: 'test dashboard title',
description: 'test dashboard description',
timepicker: {
refresh_intervals: ['5s', '10s', '30s', '1m', '5m', '15m', '30m', '1h', '2h', '1d', '2d'],
time_options: ['5m', '15m', '1h', '6h', '12h', '24h', '2d', '7d', '30d'],
},
timezone: 'utc',
},
meta: {
{
folderId: 1,
folderTitle: 'test',
},
timezone: 'utc',
} as unknown as DashboardModel,
}
),
updateTimeZone: jest.fn(),
updateWeekStart: jest.fn(),
};

View File

@ -34,15 +34,15 @@ function setupTestContext(options: Partial<Props>) {
setTimeSrv(timeSrv);
const defaults: Props = {
panel: {
panel: new PanelModel({
id: 123,
hasTitle: jest.fn(),
replaceVariables: jest.fn(),
events: { subscribe: jest.fn() },
events: new EventBusSrv(),
getQueryRunner: () => panelQueryRunner,
getOptions: jest.fn(),
getDisplayTitle: jest.fn(),
} as unknown as PanelModel,
}),
dashboard: {
panelInitialized: jest.fn(),
getTimezone: () => 'browser',

View File

@ -444,7 +444,7 @@ export class DashboardModel implements TimeModel {
const rowPanels = panel.panels ?? [];
for (const rowPanel of rowPanels) {
yield rowPanel as PanelModel;
yield rowPanel;
}
}
}

View File

@ -6,8 +6,8 @@ import { deleteScopeVars, isOnTheSameGridRow } from './utils';
describe('isOnTheSameGridRow', () => {
describe('when source panel is next to a panel', () => {
it('then it should return true', () => {
const sourcePanel: PanelModel = { gridPos: { x: 0, y: 1, w: 4, h: 4 } } as unknown as PanelModel;
const otherPanel: PanelModel = { gridPos: { x: 4, y: 1, w: 4, h: 4 } } as unknown as PanelModel;
const sourcePanel = new PanelModel({ gridPos: { x: 0, y: 1, w: 4, h: 4 } });
const otherPanel = new PanelModel({ gridPos: { x: 4, y: 1, w: 4, h: 4 } });
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(true);
});
@ -15,8 +15,8 @@ describe('isOnTheSameGridRow', () => {
describe('when source panel is not next to a panel', () => {
it('then it should return false', () => {
const sourcePanel: PanelModel = { gridPos: { x: 0, y: 1, w: 4, h: 4 } } as unknown as PanelModel;
const otherPanel: PanelModel = { gridPos: { x: 4, y: 5, w: 4, h: 4 } } as unknown as PanelModel;
const sourcePanel = new PanelModel({ gridPos: { x: 0, y: 1, w: 4, h: 4 } });
const otherPanel = new PanelModel({ gridPos: { x: 4, y: 5, w: 4, h: 4 } });
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false);
});
@ -24,11 +24,11 @@ describe('isOnTheSameGridRow', () => {
describe('when source panel is repeated horizontally', () => {
it('then it should return false', () => {
const sourcePanel: PanelModel = {
const sourcePanel = new PanelModel({
gridPos: { x: 0, y: 1, w: 4, h: 4 },
repeatDirection: REPEAT_DIR_HORIZONTAL,
} as unknown as PanelModel;
const otherPanel: PanelModel = { gridPos: { x: 4, y: 1, w: 4, h: 4 } } as unknown as PanelModel;
});
const otherPanel = new PanelModel({ gridPos: { x: 4, y: 1, w: 4, h: 4 } });
expect(isOnTheSameGridRow(sourcePanel, otherPanel)).toBe(false);
});

View File

@ -220,13 +220,10 @@ describe('getPropsWithVariable', () => {
describe('getAffectedPanelIdsForVariable', () => {
describe('when called with a real world example with rows and repeats', () => {
it('then it should return correct panel ids', () => {
const panels = dashWithRepeatsAndRows.panels.map(
(panel: PanelModel) =>
({
id: panel.id,
getSaveModel: () => panel,
} as unknown as PanelModel)
);
const panels = dashWithRepeatsAndRows.panels.map((panel: PanelModel) => ({
id: panel.id,
getSaveModel: () => panel,
}));
const result = getAffectedPanelIdsForVariable('query0', panels);
expect(result).toEqual([15, 16, 17, 11, 12, 13, 2, 5, 7, 6]);
});
@ -264,13 +261,10 @@ describe('getAllAffectedPanelIdsForVariableChange ', () => {
panels: panelsAsJson,
templating: { list: variables },
} = dashWithTemplateDependenciesAndPanels;
const panels = panelsAsJson.map(
(panel: PanelModel) =>
({
id: panel.id,
getSaveModel: () => panel,
} as unknown as PanelModel)
);
const panels = panelsAsJson.map((panel: PanelModel) => ({
id: panel.id,
getSaveModel: () => panel,
}));
const result = getAllAffectedPanelIdsForVariableChange('ds_instance', variables, panels);
expect(result).toEqual([2, 3, 4, 5]);
});
@ -282,13 +276,10 @@ describe('getAllAffectedPanelIdsForVariableChange ', () => {
panels: panelsAsJson,
templating: { list: variables },
} = dashWithTemplateDependenciesAndPanels;
const panels = panelsAsJson.map(
(panel: PanelModel) =>
({
id: panel.id,
getSaveModel: () => panel,
} as unknown as PanelModel)
);
const panels = panelsAsJson.map((panel: PanelModel) => ({
id: panel.id,
getSaveModel: () => panel,
}));
const result = getAllAffectedPanelIdsForVariableChange('depends_on_all', variables, panels);
expect(result).toEqual([2]);
});
@ -300,13 +291,10 @@ describe('getAllAffectedPanelIdsForVariableChange ', () => {
panels: panelsAsJson,
templating: { list: variables },
} = dashWithAllVariables;
const panels = panelsAsJson.map(
(panel: PanelModel) =>
({
id: panel.id,
getSaveModel: () => panel,
} as unknown as PanelModel)
);
const panels = panelsAsJson.map((panel: PanelModel) => ({
id: panel.id,
getSaveModel: () => panel,
}));
const result = getAllAffectedPanelIdsForVariableChange('unknown', variables, panels);
expect(result).toEqual([2, 3]);
});