diff --git a/.betterer.results b/.betterer.results index ccb647cb185..8ca72ebce09 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1748,12 +1748,6 @@ exports[`better eslint`] = { "public/app/features/alerting/components/OptionElement.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/alerting/getAlertingValidationMessage.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Unexpected any. Specify a different type.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Unexpected any. Specify a different type.", "3"] - ], "public/app/features/alerting/state/ThresholdMapper.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -2182,9 +2176,8 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Styles should be written using objects.", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"] + [0, 0, 0, "Styles should be written using objects.", "3"], + [0, 0, 0, "Styles should be written using objects.", "4"] ], "public/app/features/alerting/unified/components/receivers/form/TestContactPointModal.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], @@ -2199,12 +2192,10 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], [0, 0, 0, "Unexpected any. Specify a different type.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"], - [0, 0, 0, "Unexpected any. Specify a different type.", "5"], - [0, 0, 0, "Styles should be written using objects.", "6"], - [0, 0, 0, "Styles should be written using objects.", "7"], - [0, 0, 0, "Unexpected any. Specify a different type.", "8"], - [0, 0, 0, "Unexpected any. Specify a different type.", "9"] + [0, 0, 0, "Styles should be written using objects.", "4"], + [0, 0, 0, "Styles should be written using objects.", "5"], + [0, 0, 0, "Unexpected any. Specify a different type.", "6"], + [0, 0, 0, "Unexpected any. Specify a different type.", "7"] ], "public/app/features/alerting/unified/components/receivers/form/fields/StringArrayInput.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], @@ -2732,8 +2723,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Do not use any type assertions.", "4"] + [0, 0, 0, "Do not use any type assertions.", "3"] ], "public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -3280,9 +3270,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "3"], [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "4"] ], - "public/app/features/dashboard/dashgrid/DashboardGrid.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/dashboard/dashgrid/DashboardPanel.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -4327,9 +4314,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "3"], [0, 0, 0, "Do not use any type assertions.", "4"] ], - "public/app/features/live/index.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/logs/components/LogDetailsRow.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"], @@ -4683,9 +4667,7 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "1"] ], "public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Unexpected any. Specify a different type.", "2"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "public/app/features/plugins/sql/components/visual-query-builder/SQLWhereRow.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -4835,9 +4817,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "2"], [0, 0, 0, "Styles should be written using objects.", "3"] ], - "public/app/features/search/hooks/useSearchKeyboardSelection.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/search/page/components/ActionRow.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"] @@ -5179,9 +5158,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "1"], [0, 0, 0, "Styles should be written using objects.", "2"] ], - "public/app/features/users/state/reducers.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/variables/adapters.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"], @@ -5202,9 +5178,6 @@ exports[`better eslint`] = { "public/app/features/variables/datasource/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "public/app/features/variables/datasource/reducer.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/variables/editor/LegacyVariableQueryEditor.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] ], @@ -5286,9 +5259,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "8"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], - "public/app/features/variables/interval/reducer.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/variables/pickers/OptionsPicker/actions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Unexpected any. Specify a different type.", "1"] @@ -5370,9 +5340,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/features/variables/query/reducer.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "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"], + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "public/app/features/variables/query/variableQueryObserver.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -5585,22 +5554,22 @@ exports[`better eslint`] = { [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, "Do not use any type assertions.", "5"], + [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"], [0, 0, 0, "Unexpected any. Specify a different type.", "9"], - [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Do not use any type assertions.", "11"], - [0, 0, 0, "Do not use any type assertions.", "12"], + [0, 0, 0, "Do not use any type assertions.", "10"], + [0, 0, 0, "Unexpected any. Specify a different type.", "11"], + [0, 0, 0, "Unexpected any. Specify a different type.", "12"], [0, 0, 0, "Unexpected any. Specify a different type.", "13"], [0, 0, 0, "Unexpected any. Specify a different type.", "14"], [0, 0, 0, "Unexpected any. Specify a different type.", "15"], [0, 0, 0, "Unexpected any. Specify a different type.", "16"], [0, 0, 0, "Unexpected any. Specify a different type.", "17"], - [0, 0, 0, "Unexpected any. Specify a different type.", "18"], + [0, 0, 0, "Do not use any type assertions.", "18"], [0, 0, 0, "Unexpected any. Specify a different type.", "19"], - [0, 0, 0, "Do not use any type assertions.", "20"], + [0, 0, 0, "Unexpected any. Specify a different type.", "20"], [0, 0, 0, "Unexpected any. Specify a different type.", "21"], [0, 0, 0, "Unexpected any. Specify a different type.", "22"], [0, 0, 0, "Unexpected any. Specify a different type.", "23"], @@ -5613,9 +5582,7 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "30"], [0, 0, 0, "Unexpected any. Specify a different type.", "31"], [0, 0, 0, "Unexpected any. Specify a different type.", "32"], - [0, 0, 0, "Unexpected any. Specify a different type.", "33"], - [0, 0, 0, "Unexpected any. Specify a different type.", "34"], - [0, 0, 0, "Unexpected any. Specify a different type.", "35"] + [0, 0, 0, "Unexpected any. Specify a different type.", "33"] ], "public/app/plugins/datasource/elasticsearch/LanguageProvider.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -5726,12 +5693,11 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "2"] ], "public/app/plugins/datasource/elasticsearch/datasource.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], + [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.", "4"] ], "public/app/plugins/datasource/elasticsearch/hooks/useStatelessReducer.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -5757,9 +5723,8 @@ exports[`better eslint`] = { ], "public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "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.", "1"], + [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], "public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationSchemaForm.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -6147,9 +6112,7 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "10"], [0, 0, 0, "Styles should be written using objects.", "11"], [0, 0, 0, "Styles should be written using objects.", "12"], - [0, 0, 0, "Styles should be written using objects.", "13"], - [0, 0, 0, "Do not use any type assertions.", "14"], - [0, 0, 0, "Do not use any type assertions.", "15"] + [0, 0, 0, "Styles should be written using objects.", "13"] ], "public/app/plugins/datasource/loki/components/LokiOptionFields.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], @@ -6411,20 +6374,12 @@ exports[`better eslint`] = { [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, "Do not use any type assertions.", "5"] + [0, 0, 0, "Unexpected any. Specify a different type.", "4"] ], "public/app/plugins/datasource/prometheus/language_utils.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, "Do not use any type assertions.", "2"], - [0, 0, 0, "Do not use any type assertions.", "3"], - [0, 0, 0, "Unexpected any. Specify a different type.", "4"], - [0, 0, 0, "Do not use any type assertions.", "5"], - [0, 0, 0, "Unexpected any. Specify a different type.", "6"], - [0, 0, 0, "Do not use any type assertions.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "9"] + [0, 0, 0, "Do not use any type assertions.", "2"] ], "public/app/plugins/datasource/prometheus/metric_find_query.test.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -6610,9 +6565,8 @@ exports[`better eslint`] = { ], "public/app/plugins/datasource/tempo/ServiceGraphSection.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Styles should be written using objects.", "2"], - [0, 0, 0, "Styles should be written using objects.", "3"] + [0, 0, 0, "Styles should be written using objects.", "1"], + [0, 0, 0, "Styles should be written using objects.", "2"] ], "public/app/plugins/datasource/tempo/configuration/ConfigEditor.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -6652,10 +6606,9 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "6"], [0, 0, 0, "Do not use any type assertions.", "7"], [0, 0, 0, "Do not use any type assertions.", "8"], - [0, 0, 0, "Do not use any type assertions.", "9"], + [0, 0, 0, "Unexpected any. Specify a different type.", "9"], [0, 0, 0, "Unexpected any. Specify a different type.", "10"], - [0, 0, 0, "Unexpected any. Specify a different type.", "11"], - [0, 0, 0, "Unexpected any. Specify a different type.", "12"] + [0, 0, 0, "Unexpected any. Specify a different type.", "11"] ], "public/app/plugins/datasource/tempo/language_provider.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] diff --git a/public/app/features/alerting/getAlertingValidationMessage.ts b/public/app/features/alerting/getAlertingValidationMessage.ts index 52184d0d1df..69a3aed00ea 100644 --- a/public/app/features/alerting/getAlertingValidationMessage.ts +++ b/public/app/features/alerting/getAlertingValidationMessage.ts @@ -4,8 +4,8 @@ import { DataSourceSrv } from '@grafana/runtime'; export const getDefaultCondition = () => ({ type: 'query', query: { params: ['A', '5m', 'now'] }, - reducer: { type: 'avg', params: [] as any[] }, - evaluator: { type: 'gt', params: [null] as any[] }, + reducer: { type: 'avg', params: [] }, + evaluator: { type: 'gt', params: [null] }, operator: { type: 'and' }, }); diff --git a/public/app/features/alerting/unified/components/receivers/form/ReceiverForm.tsx b/public/app/features/alerting/unified/components/receivers/form/ReceiverForm.tsx index 5f0476e9456..48ccc6e5bc2 100644 --- a/public/app/features/alerting/unified/components/receivers/form/ReceiverForm.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/ReceiverForm.tsx @@ -177,7 +177,7 @@ export function ReceiverForm({ type="button" icon="plus" variant="secondary" - onClick={() => append({ ...defaultItem, __id: String(Math.random()) } as R)} + onClick={() => append({ ...defaultItem, __id: String(Math.random()) })} > Add contact point integration diff --git a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx index 7083b0024ae..02384e0c63c 100644 --- a/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx +++ b/public/app/features/alerting/unified/components/receivers/form/fields/OptionField.tsx @@ -41,7 +41,7 @@ export const OptionField: FC = ({ readOnly={readOnly} defaultValue={defaultValue} option={option} - errors={error as DeepMap | undefined} + errors={error} pathPrefix={optionPath} /> ); diff --git a/public/app/features/alerting/unified/utils/rules.ts b/public/app/features/alerting/unified/utils/rules.ts index 5b56d1affb6..05759a8df69 100644 --- a/public/app/features/alerting/unified/utils/rules.ts +++ b/public/app/features/alerting/unified/utils/rules.ts @@ -171,8 +171,7 @@ export function getFirstActiveAt(promRule?: AlertingRule) { return null; } return promRule.alerts.reduce((prev, alert) => { - const isNotNormal = - mapStateWithReasonToBaseState(alert.state as GrafanaAlertStateWithReason) !== GrafanaAlertState.Normal; + const isNotNormal = mapStateWithReasonToBaseState(alert.state) !== GrafanaAlertState.Normal; if (alert.activeAt && isNotNormal) { const activeAt = new Date(alert.activeAt); if (prev === null || prev.getTime() > activeAt.getTime()) { diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index b4220cc25c7..532ebd73217 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -71,11 +71,8 @@ export class DashboardGrid extends PureComponent { if (e.payload.variable?.id === PANEL_FILTER_VARIABLE) { if ('current' in e.payload.variable) { let variable = e.payload.variable.current; - if ('value' in variable) { - let value = variable.value; - if (typeof value === 'string') { - this.setPanelFilter(value as string); - } + if ('value' in variable && typeof variable.value === 'string') { + this.setPanelFilter(variable.value); } } } diff --git a/public/app/features/live/index.ts b/public/app/features/live/index.ts index 9b1c10e3573..f434a7149fd 100644 --- a/public/app/features/live/index.ts +++ b/public/app/features/live/index.ts @@ -1,4 +1,4 @@ -import { config, getBackendSrv, getGrafanaLiveSrv, setGrafanaLiveSrv } from '@grafana/runtime'; +import { GrafanaLiveSrv, config, getBackendSrv, getGrafanaLiveSrv, setGrafanaLiveSrv } from '@grafana/runtime'; import { liveTimer } from 'app/features/dashboard/dashgrid/liveTimer'; import { contextSrv } from '../../core/services/context_srv'; @@ -30,6 +30,6 @@ export function initGrafanaLive() { ); } -export function getGrafanaLiveCentrifugeSrv() { - return getGrafanaLiveSrv() as GrafanaLiveService; +export function getGrafanaLiveCentrifugeSrv(): GrafanaLiveSrv { + return getGrafanaLiveSrv(); } diff --git a/public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx b/public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx index 4e911fcf3d9..9ddf96dc600 100644 --- a/public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx +++ b/public/app/features/plugins/sql/components/visual-query-builder/AwesomeQueryBuilder.tsx @@ -183,7 +183,7 @@ const enum Op { MACROS = 'macros', } // eslint-ignore -const customOperators = getCustomOperators(BasicConfig) as typeof BasicConfig.operators; +const customOperators = getCustomOperators(BasicConfig); const textWidget = BasicConfig.types.text.widgets.text; const opers = [...(textWidget.operators || []), Op.IN, Op.NOT_IN]; const customTextWidget = { @@ -216,7 +216,7 @@ export const raqbConfig: Config = { ...BasicConfig, widgets, settings, - operators: customOperators as typeof BasicConfig.operators, + operators: customOperators, types: customTypes, }; diff --git a/public/app/features/search/hooks/useSearchKeyboardSelection.ts b/public/app/features/search/hooks/useSearchKeyboardSelection.ts index ee9a35f11c1..1eb05bc9145 100644 --- a/public/app/features/search/hooks/useSearchKeyboardSelection.ts +++ b/public/app/features/search/hooks/useSearchKeyboardSelection.ts @@ -85,8 +85,8 @@ export function useSearchKeyboardNavigation( setHighlightIndex({ ...highlightIndexRef.current }); break; } - const url = urlsRef.current.values?.[idx] as string; - if (url) { + const url: unknown = urlsRef.current.values?.[idx]; + if (typeof url === 'string') { locationService.push(locationUtil.stripBaseFromUrl(url)); } } diff --git a/public/app/features/users/state/reducers.ts b/public/app/features/users/state/reducers.ts index 5d9b576b9a0..f74fea6ad1d 100644 --- a/public/app/features/users/state/reducers.ts +++ b/public/app/features/users/state/reducers.ts @@ -4,7 +4,7 @@ import config from 'app/core/config'; import { OrgUser, UsersState } from 'app/types'; export const initialState: UsersState = { - users: [] as OrgUser[], + users: [], searchQuery: '', page: 0, perPage: 30, diff --git a/public/app/features/variables/datasource/reducer.ts b/public/app/features/variables/datasource/reducer.ts index d28abaf014f..550c4c700af 100644 --- a/public/app/features/variables/datasource/reducer.ts +++ b/public/app/features/variables/datasource/reducer.ts @@ -10,7 +10,7 @@ import { DataSourceVariableModel, initialVariableModelState, VariableOption, Var export const initialDataSourceVariableModelState: DataSourceVariableModel = { ...initialVariableModelState, type: 'datasource', - current: {} as VariableOption, + current: {}, regex: '', options: [], query: '', diff --git a/public/app/features/variables/interval/reducer.ts b/public/app/features/variables/interval/reducer.ts index a0d7d2de27b..a51919d28c0 100644 --- a/public/app/features/variables/interval/reducer.ts +++ b/public/app/features/variables/interval/reducer.ts @@ -14,7 +14,7 @@ export const initialIntervalVariableModelState: IntervalVariableModel = { auto: false, query: '1m,10m,30m,1h,6h,12h,1d,7d,14d,30d', refresh: VariableRefresh.onTimeRangeChanged, - current: {} as VariableOption, + current: {}, }; export const intervalVariableSlice = createSlice({ diff --git a/public/app/features/variables/query/reducer.ts b/public/app/features/variables/query/reducer.ts index fb4c4fe0374..b59354013b6 100644 --- a/public/app/features/variables/query/reducer.ts +++ b/public/app/features/variables/query/reducer.ts @@ -25,7 +25,7 @@ export const initialQueryVariableModelState: QueryVariableModel = { includeAll: false, allValue: null, options: [], - current: {} as VariableOption, + current: {}, definition: '', }; diff --git a/public/app/plugins/datasource/elasticsearch/ElasticResponse.ts b/public/app/plugins/datasource/elasticsearch/ElasticResponse.ts index 5455555451c..46994b11ba6 100644 --- a/public/app/plugins/datasource/elasticsearch/ElasticResponse.ts +++ b/public/app/plugins/datasource/elasticsearch/ElasticResponse.ts @@ -84,7 +84,7 @@ export class ElasticResponse { } case 'extended_stats': { for (const statName in metric.meta) { - if (!metric.meta[statName as ExtendedStatMetaType]) { + if (!metric.meta[statName]) { continue; } @@ -210,7 +210,7 @@ export class ElasticResponse { } case 'extended_stats': { for (const statName in metric.meta) { - if (!metric.meta[statName as ExtendedStatMetaType]) { + if (!metric.meta[statName]) { continue; } diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index d0c1af10068..0eb102cbcf3 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -134,7 +134,7 @@ export class ElasticDatasource this.url = instanceSettings.url!; this.name = instanceSettings.name; this.isProxyAccess = instanceSettings.access === 'proxy'; - const settingsData = instanceSettings.jsonData || ({} as ElasticsearchOptions); + const settingsData = instanceSettings.jsonData || {}; this.index = settingsData.index ?? instanceSettings.database ?? ''; this.timeField = settingsData.timeField; diff --git a/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx b/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx index ac131ceb02b..225f3fba094 100644 --- a/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx +++ b/public/app/plugins/datasource/grafana-testdata-datasource/components/SimulationQueryEditor.tsx @@ -25,7 +25,7 @@ interface SimInfo { export const SimulationQueryEditor = ({ onChange, query, ds }: EditorProps) => { const simQuery = query.sim ?? ({} as SimulationQuery); - const simKey = simQuery.key ?? ({} as typeof simQuery.key); + const simKey = simQuery.key ?? {}; // keep track of updated config state to pass down to form const [cfgValue, setCfgValue] = useState>({}); diff --git a/public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx b/public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx index 2c32e36549d..cbb72d70d3d 100644 --- a/public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx +++ b/public/app/plugins/datasource/loki/components/LokiLabelBrowser.tsx @@ -188,7 +188,7 @@ const getStyles = (theme: GrafanaTheme2) => ({ export class UnthemedLokiLabelBrowser extends React.Component { state: BrowserState = { - labels: [] as SelectableLabel[], + labels: [], searchTerm: '', status: 'Ready', error: '', @@ -497,7 +497,7 @@ export class UnthemedLokiLabelBrowser extends React.Component (label.values as FacettableValue[])[i].name} + itemKey={(i) => label.values?.[i].name ?? i} width={200} className={styles.valueList} > diff --git a/public/app/plugins/datasource/prometheus/language_provider.ts b/public/app/plugins/datasource/prometheus/language_provider.ts index 6bf27153180..b498f2bad6b 100644 --- a/public/app/plugins/datasource/prometheus/language_provider.ts +++ b/public/app/plugins/datasource/prometheus/language_provider.ts @@ -348,9 +348,10 @@ export default class PromQlLanguageProvider extends LanguageProvider { function getNameLabelValue(promQuery: string, tokens: any): string { let nameLabelValue = ''; - for (let prop in tokens) { - if (typeof tokens[prop] === 'string') { - nameLabelValue = tokens[prop] as string; + + for (const token of tokens) { + if (typeof token === 'string') { + nameLabelValue = token; break; } } diff --git a/public/app/plugins/datasource/prometheus/language_utils.ts b/public/app/plugins/datasource/prometheus/language_utils.ts index 8f024b030af..cf1ee42c217 100644 --- a/public/app/plugins/datasource/prometheus/language_utils.ts +++ b/public/app/plugins/datasource/prometheus/language_utils.ts @@ -287,6 +287,7 @@ const FromPromLikeMap: Record = { '=~': AbstractLabelOperator.EqualRegEx, '!~': AbstractLabelOperator.NotEqualRegEx, }; + const ToPromLikeMap: Record = invert(FromPromLikeMap) as Record< AbstractLabelOperator, string @@ -321,38 +322,49 @@ export interface PromLikeQuery extends DataQuery { range: boolean; } +function getMaybeTokenStringContent(token: Token): string { + if (typeof token.content === 'string') { + return token.content; + } + + return ''; +} + export function extractLabelMatchers(tokens: Array): AbstractLabelMatcher[] { const labelMatchers: AbstractLabelMatcher[] = []; - for (let prop in tokens) { - if (tokens[prop] instanceof Token) { - let token: Token = tokens[prop] as Token; - if (token.type === 'context-labels') { - let labelKey = ''; - let labelValue = ''; - let labelOperator = ''; - let contentTokens: any[] = token.content as any[]; - for (let currentToken in contentTokens) { - if (typeof contentTokens[currentToken] === 'string') { - let currentStr: string; - currentStr = contentTokens[currentToken] as string; - if (currentStr === '=' || currentStr === '!=' || currentStr === '=~' || currentStr === '!~') { - labelOperator = currentStr; - } - } else if (contentTokens[currentToken] instanceof Token) { - switch (contentTokens[currentToken].type) { - case 'label-key': - labelKey = contentTokens[currentToken].content as string; - break; - case 'label-value': - labelValue = contentTokens[currentToken].content as string; - labelValue = labelValue.substring(1, labelValue.length - 1); - const labelComparator = FromPromLikeMap[labelOperator]; - if (labelComparator) { - labelMatchers.push({ name: labelKey, operator: labelComparator, value: labelValue }); - } - break; - } + for (const token of tokens) { + if (!(token instanceof Token)) { + continue; + } + + if (token.type === 'context-labels') { + let labelKey = ''; + let labelValue = ''; + let labelOperator = ''; + + const contentTokens = Array.isArray(token.content) ? token.content : [token.content]; + + for (let currentToken of contentTokens) { + if (typeof currentToken === 'string') { + let currentStr: string; + currentStr = currentToken; + if (currentStr === '=' || currentStr === '!=' || currentStr === '=~' || currentStr === '!~') { + labelOperator = currentStr; + } + } else if (currentToken instanceof Token) { + switch (currentToken.type) { + case 'label-key': + labelKey = getMaybeTokenStringContent(currentToken); + break; + case 'label-value': + labelValue = getMaybeTokenStringContent(currentToken); + labelValue = labelValue.substring(1, labelValue.length - 1); + const labelComparator = FromPromLikeMap[labelOperator]; + if (labelComparator) { + labelMatchers.push({ name: labelKey, operator: labelComparator, value: labelValue }); + } + break; } } } diff --git a/public/app/plugins/datasource/tempo/ServiceGraphSection.tsx b/public/app/plugins/datasource/tempo/ServiceGraphSection.tsx index fc174bf971d..b1cbd7c337e 100644 --- a/public/app/plugins/datasource/tempo/ServiceGraphSection.tsx +++ b/public/app/plugins/datasource/tempo/ServiceGraphSection.tsx @@ -50,7 +50,7 @@ export function ServiceGraphSection({ return null; } - const ds = dsState.value as PrometheusDatasource; + const ds = dsState.value; if (!graphDatasourceUid) { return getWarning( diff --git a/public/app/plugins/datasource/tempo/datasource.ts b/public/app/plugins/datasource/tempo/datasource.ts index 73898ceb31b..c276aab167e 100644 --- a/public/app/plugins/datasource/tempo/datasource.ts +++ b/public/app/plugins/datasource/tempo/datasource.ts @@ -986,7 +986,7 @@ function makePromLink(title: string, expr: string, datasourceUid: string, instan range: !instant, exemplar: !instant, instant: instant, - } as PromQuery, + }, datasourceUid, datasourceName: getDatasourceSrv().getDataSourceSettingsByUid(datasourceUid)?.name ?? '', },