diff --git a/.betterer.results b/.betterer.results index adceefd5cfe..041c00af5e6 100644 --- a/.betterer.results +++ b/.betterer.results @@ -1,5 +1,5 @@ // BETTERER RESULTS V2. -// +// // If this file contains merge conflicts, use `betterer merge` to automatically resolve them: // https://phenomnomnominal.github.io/betterer/docs/results-file/#merge // @@ -14,10 +14,6 @@ exports[`better eslint`] = { "packages/grafana-data/src/dataframe/CircularDataFrame.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], - "packages/grafana-data/src/dataframe/DataFrameJSON.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"] - ], "packages/grafana-data/src/dataframe/DataFrameView.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -43,8 +39,7 @@ exports[`better eslint`] = { [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.", "5"] + [0, 0, 0, "Do not use any type assertions.", "4"] ], "packages/grafana-data/src/dataframe/dimensions.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] @@ -194,10 +189,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], "packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.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.", "3"] + [0, 0, 0, "Unexpected any. Specify a different type.", "0"], + [0, 0, 0, "Unexpected any. Specify a different type.", "1"] ], "packages/grafana-data/src/transformations/transformers/reduce.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -323,8 +316,7 @@ exports[`better eslint`] = { [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, "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.", "7"] ], "packages/grafana-data/src/types/options.ts:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -681,9 +673,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "17"], [0, 0, 0, "Styles should be written using objects.", "18"] ], - "packages/grafana-prometheus/src/querybuilder/operationUtils.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "packages/grafana-prometheus/src/querybuilder/shared/OperationEditor.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"] ], @@ -892,10 +881,8 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "5"], [0, 0, 0, "Do not use any type assertions.", "6"], [0, 0, 0, "Unexpected any. Specify a different type.", "7"], - [0, 0, 0, "Do not use any type assertions.", "8"], - [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.", "8"], + [0, 0, 0, "Unexpected any. Specify a different type.", "9"] ], "packages/grafana-ui/src/components/Select/SelectOptionGroup.tsx:5381": [ [0, 0, 0, "Unexpected any. Specify a different type.", "0"], @@ -1097,12 +1084,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], - "packages/grafana-ui/src/options/builder/axis.tsx: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"] - ], "packages/grafana-ui/src/options/builder/hideSeries.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -1560,11 +1541,10 @@ exports[`better eslint`] = { ], "public/app/features/alerting/unified/RuleList.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.", "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.", "4"], - [0, 0, 0, "Styles should be written using objects.", "5"] + [0, 0, 0, "Styles should be written using objects.", "4"] ], "public/app/features/alerting/unified/components/AlertLabel.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"] @@ -1580,8 +1560,7 @@ exports[`better eslint`] = { ], "public/app/features/alerting/unified/components/AnnotationDetailsField.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.", "1"] ], "public/app/features/alerting/unified/components/Authorize.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], @@ -1702,9 +1681,6 @@ exports[`better eslint`] = { "public/app/features/alerting/unified/components/alert-groups/GroupBy.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/alerting/unified/components/contact-points/ContactPoints.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], @@ -2332,9 +2308,6 @@ exports[`better eslint`] = { [0, 0, 0, "Unexpected any. Specify a different type.", "1"], [0, 0, 0, "Unexpected any. Specify a different type.", "2"] ], - "public/app/features/alerting/unified/utils/misc.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/alerting/unified/utils/receiver-form.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], @@ -2349,8 +2322,7 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "4"], [0, 0, 0, "Do not use any type assertions.", "5"], [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.", "7"] ], "public/app/features/alerting/unified/utils/rulerClient.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] @@ -2541,11 +2513,6 @@ exports[`better eslint`] = { "public/app/features/dashboard-scene/utils/PanelModelCompatibilityWrapper.ts:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], - "public/app/features/dashboard-scene/utils/test-utils.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"], - [0, 0, 0, "Do not use any type assertions.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] - ], "public/app/features/dashboard/components/AddWidgetModal/AddWidgetModal.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"], @@ -3014,8 +2981,7 @@ exports[`better eslint`] = { ], "public/app/features/datasources/components/DataSourceTestingStatus.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], - [0, 0, 0, "Styles should be written using objects.", "1"], - [0, 0, 0, "Do not use any type assertions.", "2"] + [0, 0, 0, "Styles should be written using objects.", "1"] ], "public/app/features/datasources/components/DataSourceTypeCard.tsx:5381": [ [0, 0, 0, "Use data-testid for E2E selectors instead of aria-label", "0"] @@ -3431,9 +3397,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "4"], [0, 0, 0, "Styles should be written using objects.", "5"] ], - "public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/TextList.tsx:5381": [ [0, 0, 0, "Styles should be written using objects.", "0"], [0, 0, 0, "Styles should be written using objects.", "1"], @@ -5554,9 +5517,6 @@ exports[`better eslint`] = { [0, 0, 0, "Styles should be written using objects.", "17"], [0, 0, 0, "Styles should be written using objects.", "18"] ], - "public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/plugins/datasource/prometheus/querybuilder/shared/LabelFilterItem.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"], [0, 0, 0, "Do not use any type assertions.", "1"], diff --git a/packages/grafana-data/src/dataframe/DataFrameJSON.ts b/packages/grafana-data/src/dataframe/DataFrameJSON.ts index 4b4e69cd5ae..fdfcb4dc586 100644 --- a/packages/grafana-data/src/dataframe/DataFrameJSON.ts +++ b/packages/grafana-data/src/dataframe/DataFrameJSON.ts @@ -128,9 +128,10 @@ const ENTITY_MAP: Record = { * @internal use locally */ export function decodeFieldValueEntities(lookup: FieldValueEntityLookup, values: FieldValues) { - for (const key in lookup) { - const repl = ENTITY_MAP[key as keyof FieldValueEntityLookup]; - for (const idx of lookup[key as keyof FieldValueEntityLookup]!) { + let key: keyof typeof lookup; + for (key in lookup) { + const repl = ENTITY_MAP[key]; + for (const idx of lookup[key]!) { if (idx < values.length) { values[idx] = repl; } diff --git a/packages/grafana-data/src/dataframe/StreamingDataFrame.ts b/packages/grafana-data/src/dataframe/StreamingDataFrame.ts index 36fe7a77e22..b39b7ab15a1 100644 --- a/packages/grafana-data/src/dataframe/StreamingDataFrame.ts +++ b/packages/grafana-data/src/dataframe/StreamingDataFrame.ts @@ -115,7 +115,7 @@ export class StreamingDataFrame implements DataFrame { const dataFrameDTO = toFilteredDataFrameDTO(this, fieldPredicate); const numberOfItemsToRemove = getNumberOfItemsToRemove( - dataFrameDTO.fields.map((f) => f.values) as unknown[][], + dataFrameDTO.fields.map((f) => f.values ?? []), typeof trimValues?.maxLength === 'number' ? Math.min(trimValues.maxLength, options.maxLength) : options.maxLength, this.timeFieldIndex, options.maxDelta diff --git a/packages/grafana-data/src/dataframe/frameComparisons.ts b/packages/grafana-data/src/dataframe/frameComparisons.ts index 67eee91bae4..e01c0a449d2 100644 --- a/packages/grafana-data/src/dataframe/frameComparisons.ts +++ b/packages/grafana-data/src/dataframe/frameComparisons.ts @@ -46,18 +46,12 @@ export function compareDataFrameStructures(a: DataFrame, b: DataFrame, skipConfi const cfgA = fA.config; const cfgB = fB.config; - // need to type assert on the object keys here - // see e.g. https://github.com/Microsoft/TypeScript/issues/12870 - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - let aKeys = Object.keys(cfgA) as Array; - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - let bKeys = Object.keys(cfgB) as Array; - - if (aKeys.length !== bKeys.length) { + if (Object.keys(cfgA).length !== Object.keys(cfgB).length) { return false; } - for (const key of aKeys) { + let key: keyof typeof cfgA; + for (key in cfgA) { if (!(key in cfgB)) { return false; } @@ -110,15 +104,12 @@ export function shallowCompare(a: T, b: T, cmp: Cmp = defaultCmp) return true; } - const aKeys = Object.keys(a); - const bKeys = Object.keys(b); - - if (aKeys.length !== bKeys.length) { + if (Object.keys(a).length !== Object.keys(b).length) { return false; } - for (let key of aKeys) { - //@ts-ignore + let key: keyof typeof a; + for (key in a) { if (!cmp(a[key], b[key])) { return false; } diff --git a/packages/grafana-data/src/field/displayProcessor.test.ts b/packages/grafana-data/src/field/displayProcessor.test.ts index 2997e8049d9..0a5762430b5 100644 --- a/packages/grafana-data/src/field/displayProcessor.test.ts +++ b/packages/grafana-data/src/field/displayProcessor.test.ts @@ -19,11 +19,9 @@ function getDisplayProcessorFromConfig(config: FieldConfig, fieldType: FieldType function assertSame(input: unknown, processors: DisplayProcessor[], match: DisplayValue) { processors.forEach((processor) => { const value = processor(input); - for (const key of Object.keys(match)) { - // need to type assert on the object keys here - // see e.g. https://github.com/Microsoft/TypeScript/issues/12870 - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions - expect(value[key as keyof typeof match]).toEqual(match[key as keyof typeof match]); + let key: keyof typeof match; + for (key in match) { + expect(value[key]).toEqual(match[key]); } }); } diff --git a/packages/grafana-data/src/transformations/transformers/calculateField.test.ts b/packages/grafana-data/src/transformations/transformers/calculateField.test.ts index a820514c95e..5ed845178ed 100644 --- a/packages/grafana-data/src/transformations/transformers/calculateField.test.ts +++ b/packages/grafana-data/src/transformations/transformers/calculateField.test.ts @@ -377,7 +377,7 @@ describe('calculateField transformer w/ timeseries', () => { text: '10000', }, }; - for (const key of Object.keys(variables)) { + for (const key in variables) { if (target === `$${key}`) { return variables[key]!.value + ''; } diff --git a/packages/grafana-data/src/transformations/transformers/filterByName.test.ts b/packages/grafana-data/src/transformations/transformers/filterByName.test.ts index d6b4f7e839e..e357b2c6b40 100644 --- a/packages/grafana-data/src/transformations/transformers/filterByName.test.ts +++ b/packages/grafana-data/src/transformations/transformers/filterByName.test.ts @@ -218,7 +218,7 @@ describe('filterByName transformer', () => { text: 'Test', }, }; - for (const key of Object.keys(variables)) { + for (const key in variables) { return target.replace(`$${key}`, variables[key]!.value); } return target; @@ -256,7 +256,7 @@ describe('filterByName transformer', () => { text: 'Test', }, }; - for (const key of Object.keys(variables)) { + for (const key in variables) { return target.replace(`$${key}`, variables[key]!.value); } return target; @@ -293,7 +293,7 @@ describe('filterByName transformer', () => { text: 'Test', }, }; - for (const key of Object.keys(variables)) { + for (const key in variables) { return target.replace(`$${key}`, variables[key]!.value); } return target; diff --git a/packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.ts b/packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.ts index 94d8dd2e3c0..6da2748415e 100644 --- a/packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.ts +++ b/packages/grafana-data/src/transformations/transformers/nulls/nullInsertThreshold.ts @@ -50,9 +50,9 @@ export function applyNullInsertThreshold(opts: NullInsertOptions): DataFrame { const thresholds = frame.fields.map((field) => field.config.custom?.insertNulls || refField.config.interval || null); - const uniqueThresholds = new Set(thresholds); + const uniqueThresholds = new Set(thresholds); - uniqueThresholds.delete(null as any); + uniqueThresholds.delete(null); if (uniqueThresholds.size === 0) { return frame; diff --git a/packages/grafana-data/src/transformations/transformers/reduce.ts b/packages/grafana-data/src/transformations/transformers/reduce.ts index d7e8ba8cda5..79587beb103 100644 --- a/packages/grafana-data/src/transformations/transformers/reduce.ts +++ b/packages/grafana-data/src/transformations/transformers/reduce.ts @@ -122,7 +122,7 @@ function reduceSeriesToRows( if (labelsToFields) { names[i] = field.name; if (field.labels) { - for (const key of Object.keys(field.labels)) { + for (const key in field.labels) { labels[key][i] = field.labels[key]; } } diff --git a/packages/grafana-data/src/types/live.ts b/packages/grafana-data/src/types/live.ts index 0321ef79e00..565a6d3fcae 100644 --- a/packages/grafana-data/src/types/live.ts +++ b/packages/grafana-data/src/types/live.ts @@ -185,7 +185,7 @@ export function toLiveChannelId(addr: LiveChannelAddress): LiveChannelId { if (!addr.scope) { return ''; } - let id = addr.scope as string; + let id: string = addr.scope; if (!addr.namespace) { return id; } diff --git a/packages/grafana-data/src/utils/location.ts b/packages/grafana-data/src/utils/location.ts index 5c0a2167025..0e33f3da102 100644 --- a/packages/grafana-data/src/utils/location.ts +++ b/packages/grafana-data/src/utils/location.ts @@ -73,7 +73,7 @@ const getUrlForPartial = (location: Location, searchParamsToUpdate: UrlQueryMap) const searchParams = urlUtil.parseKeyValue( location.search.startsWith('?') ? location.search.substring(1) : location.search ); - for (const key of Object.keys(searchParamsToUpdate)) { + for (const key in searchParamsToUpdate) { // removing params with null | undefined if (searchParamsToUpdate[key] === null || searchParamsToUpdate[key] === undefined) { delete searchParams[key]; diff --git a/packages/grafana-prometheus/src/querybuilder/operationUtils.ts b/packages/grafana-prometheus/src/querybuilder/operationUtils.ts index b7eec3ec160..9be994d73da 100644 --- a/packages/grafana-prometheus/src/querybuilder/operationUtils.ts +++ b/packages/grafana-prometheus/src/querybuilder/operationUtils.ts @@ -124,31 +124,33 @@ export function getOperationParamId(operationId: string, paramIndex: number) { } export function getRangeVectorParamDef(withRateInterval = false): QueryBuilderOperationParamDef { - const param: QueryBuilderOperationParamDef = { - name: 'Range', - type: 'string', - options: [ - { - label: '$__interval', - value: '$__interval', - // tooltip: 'Dynamic interval based on max data points, scrape and min interval', - }, - { label: '1m', value: '1m' }, - { label: '5m', value: '5m' }, - { label: '10m', value: '10m' }, - { label: '1h', value: '1h' }, - { label: '24h', value: '24h' }, - ], - }; + const options: Array> = [ + { + label: '$__interval', + value: '$__interval', + // tooltip: 'Dynamic interval based on max data points, scrape and min interval', + }, + { label: '1m', value: '1m' }, + { label: '5m', value: '5m' }, + { label: '10m', value: '10m' }, + { label: '1h', value: '1h' }, + { label: '24h', value: '24h' }, + ]; if (withRateInterval) { - (param.options as Array>).unshift({ + options.unshift({ label: '$__rate_interval', value: '$__rate_interval', // tooltip: 'Always above 4x scrape interval', }); } + const param: QueryBuilderOperationParamDef = { + name: 'Range', + type: 'string', + options, + }; + return param; } diff --git a/packages/grafana-runtime/src/services/LocationService.ts b/packages/grafana-runtime/src/services/LocationService.ts index d09b4590447..af707b0b93e 100644 --- a/packages/grafana-runtime/src/services/LocationService.ts +++ b/packages/grafana-runtime/src/services/LocationService.ts @@ -59,7 +59,7 @@ export class HistoryWrapper implements LocationService { const currentLocation = this.history.location; const newQuery = this.getSearchObject(); - for (const key of Object.keys(query)) { + for (const key in query) { // removing params with null | undefined if (query[key] === null || query[key] === undefined) { delete newQuery[key]; diff --git a/packages/grafana-ui/src/components/Select/SelectBase.tsx b/packages/grafana-ui/src/components/Select/SelectBase.tsx index 19817471e07..487f1a118ea 100644 --- a/packages/grafana-ui/src/components/Select/SelectBase.tsx +++ b/packages/grafana-ui/src/components/Select/SelectBase.tsx @@ -272,7 +272,7 @@ export function SelectBase({ // Instead of having AsyncSelect, as a separate component we render ReactAsyncSelect if (loadOptions) { - ReactSelectComponent = (allowCustomValue ? AsyncCreatable : ReactAsyncSelect) as any; + ReactSelectComponent = allowCustomValue ? AsyncCreatable : ReactAsyncSelect; asyncSelectProps = { loadOptions, cacheOptions, diff --git a/packages/grafana-ui/src/options/builder/axis.tsx b/packages/grafana-ui/src/options/builder/axis.tsx index 2b8400be138..6bbb5c32ccf 100644 --- a/packages/grafana-ui/src/options/builder/axis.tsx +++ b/packages/grafana-ui/src/options/builder/axis.tsx @@ -100,8 +100,8 @@ export function addAxisConfig( path: 'scaleDistribution', name: 'Scale', category, - editor: ScaleDistributionEditor as any, - override: ScaleDistributionEditor as any, + editor: ScaleDistributionEditor, + override: ScaleDistributionEditor, defaultValue: { type: ScaleDistribution.Linear }, shouldApply: (f) => f.type === FieldType.number, process: identityOverrideProcessor, diff --git a/public/app/angular/AngularLocationWrapper.ts b/public/app/angular/AngularLocationWrapper.ts index 3da42635bd2..05e82e2e245 100644 --- a/public/app/angular/AngularLocationWrapper.ts +++ b/public/app/angular/AngularLocationWrapper.ts @@ -107,7 +107,7 @@ export class AngularLocationWrapper { newQuery = locationSearchToObject(search); } - for (const key of Object.keys(newQuery)) { + for (const key in newQuery) { // removing params with null | undefined if (newQuery[key] === null || newQuery[key] === undefined) { delete newQuery[key]; diff --git a/public/app/features/alerting/unified/RuleList.tsx b/public/app/features/alerting/unified/RuleList.tsx index d30b8936b06..571f98ffae8 100644 --- a/public/app/features/alerting/unified/RuleList.tsx +++ b/public/app/features/alerting/unified/RuleList.tsx @@ -47,9 +47,8 @@ const RuleList = withErrorBoundary( const [queryParams] = useQueryParams(); const { filterState, hasActiveFilters } = useRulesFilter(); - const view = VIEWS[queryParams['view'] as keyof typeof VIEWS] - ? (queryParams['view'] as keyof typeof VIEWS) - : 'groups'; + const queryParamView = queryParams['view'] as keyof typeof VIEWS; + const view = VIEWS[queryParamView] ? queryParamView : 'groups'; const ViewComponent = VIEWS[view]; diff --git a/public/app/features/alerting/unified/components/AnnotationDetailsField.tsx b/public/app/features/alerting/unified/components/AnnotationDetailsField.tsx index d3ce186f377..c3b7dae4f65 100644 --- a/public/app/features/alerting/unified/components/AnnotationDetailsField.tsx +++ b/public/app/features/alerting/unified/components/AnnotationDetailsField.tsx @@ -19,9 +19,10 @@ interface Props { } export const AnnotationDetailsField = ({ annotationKey, value, valueLink }: Props) => { - const label = annotationLabels[annotationKey as Annotation] ? ( + const annotation = annotationKey as Annotation; + const label = annotationLabels[annotation] ? ( - {annotationLabels[annotationKey as Annotation]} + {annotationLabels[annotation]} ) : ( annotationKey diff --git a/public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx b/public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx index 02dab1c9eea..4f8a2745173 100644 --- a/public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx +++ b/public/app/features/alerting/unified/components/alert-groups/MatcherFilter.tsx @@ -20,7 +20,7 @@ export const MatcherFilter = ({ onFilterChange, defaultQueryString }: Props) => () => debounce((e: FormEvent) => { logInfo(LogMessages.filterByLabel); - const target = e.target as HTMLInputElement; + const target = e.currentTarget; onFilterChange(target.value); }, 600), [onFilterChange] diff --git a/public/app/features/alerting/unified/utils/misc.ts b/public/app/features/alerting/unified/utils/misc.ts index 7f956f050b0..32fc700f0ae 100644 --- a/public/app/features/alerting/unified/utils/misc.ts +++ b/public/app/features/alerting/unified/utils/misc.ts @@ -226,7 +226,7 @@ export function isLocalDevEnv() { } export function isErrorLike(error: unknown): error is Error { - return 'message' in (error as Error); + return Boolean(error && typeof error === 'object' && 'message' in error); } export function stringifyErrorLike(error: unknown): string { diff --git a/public/app/features/alerting/unified/utils/redux.ts b/public/app/features/alerting/unified/utils/redux.ts index 5334f82c3bc..679eea9b296 100644 --- a/public/app/features/alerting/unified/utils/redux.ts +++ b/public/app/features/alerting/unified/utils/redux.ts @@ -6,6 +6,8 @@ import { appEvents } from 'app/core/core'; import { logInfo, LogMessages } from '../Analytics'; +import { isErrorLike } from './misc'; + export interface AsyncRequestState { result?: T; loading: boolean; @@ -158,9 +160,8 @@ export function messageFromError(e: Error | FetchError | SerializedError): strin } } // message in e object, return message - const errorMessage = (e as Error)?.message; - if (errorMessage) { - return errorMessage; + if (isErrorLike(e)) { + return e.message; } // for some reason (upstream this code), sometimes we get an object without the message field neither in the e.data and nor in e.message // in this case we want to avoid String(e) printing [object][object] diff --git a/public/app/features/dashboard-scene/utils/test-utils.ts b/public/app/features/dashboard-scene/utils/test-utils.ts index ad7b377fb28..2f5a3f24ef0 100644 --- a/public/app/features/dashboard-scene/utils/test-utils.ts +++ b/public/app/features/dashboard-scene/utils/test-utils.ts @@ -21,10 +21,10 @@ import { RowRepeaterBehavior } from '../scene/RowRepeaterBehavior'; export function setupLoadDashboardMock(rsp: DeepPartial, spy?: jest.Mock) { const loadDashboardMock = (spy || jest.fn()).mockResolvedValue(rsp); + // disabling type checks since this is a test util + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions setDashboardLoaderSrv({ loadDashboard: loadDashboardMock, - // disabling type checks since this is a test util - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions } as unknown as DashboardLoaderSrv); return loadDashboardMock; } @@ -35,6 +35,8 @@ export function mockResizeObserver() { setTimeout(() => { callback( [ + // disabling type checks since this is a test util + // eslint-disable-next-line @typescript-eslint/consistent-type-assertions { contentRect: { x: 1, @@ -46,8 +48,6 @@ export function mockResizeObserver() { left: 100, right: 0, }, - // disabling type checks since this is a test util - // eslint-disable-next-line @typescript-eslint/consistent-type-assertions } as ResizeObserverEntry, ], this diff --git a/public/app/features/dashboard-scene/utils/urlBuilders.ts b/public/app/features/dashboard-scene/utils/urlBuilders.ts index 7ece19aae83..e3e7ae8331c 100644 --- a/public/app/features/dashboard-scene/utils/urlBuilders.ts +++ b/public/app/features/dashboard-scene/utils/urlBuilders.ts @@ -57,7 +57,7 @@ export function getDashboardUrl(options: DashboardUrlOptions) { const params = options.currentQueryParams ? locationSearchToObject(options.currentQueryParams) : {}; if (options.updateQuery) { - for (const key of Object.keys(options.updateQuery)) { + for (const key in options.updateQuery) { // removing params with null | undefined if (options.updateQuery[key] === null || options.updateQuery[key] === undefined) { delete params[key]; diff --git a/public/app/features/datasources/components/DataSourceTestingStatus.tsx b/public/app/features/datasources/components/DataSourceTestingStatus.tsx index f3268a61bc9..4b32028ffa0 100644 --- a/public/app/features/datasources/components/DataSourceTestingStatus.tsx +++ b/public/app/features/datasources/components/DataSourceTestingStatus.tsx @@ -74,8 +74,8 @@ const AlertSuccessMessage = ({ title, exploreUrl, dataSourceId, onDashboardLinkC AlertSuccessMessage.displayName = 'AlertSuccessMessage'; -const alertVariants = new Set(['success', 'info', 'warning', 'error']); -const isAlertVariant = (str: string): str is AlertVariant => alertVariants.has(str as AlertVariant); +const alertVariants = new Set(['success', 'info', 'warning', 'error']); +const isAlertVariant = (str: string): str is AlertVariant => alertVariants.has(str); const getAlertVariant = (status: string): AlertVariant => { if (status.toLowerCase() === 'ok') { return 'success'; diff --git a/public/app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditorModal.tsx b/public/app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditorModal.tsx index 0c1eef75097..cce6d85614c 100644 --- a/public/app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditorModal.tsx +++ b/public/app/features/dimensions/editors/ValueMappingsEditor/ValueMappingsEditorModal.tsx @@ -264,7 +264,7 @@ export function buildEditRowModels(value: ValueMapping[]) { for (const mapping of value) { switch (mapping.type) { case MappingType.ValueToText: - for (const key of Object.keys(mapping.options)) { + for (const key in mapping.options) { editRows.push( createRow({ type: mapping.type, diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx index b8c435175b0..d3042939834 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/SpanDetail/SpanFlameGraph.tsx @@ -17,7 +17,6 @@ import { TraceToProfilesOptions } from '@grafana/o11y-ds-frontend'; import { config, DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime'; import { useStyles2 } from '@grafana/ui'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; -import { PyroscopeQueryType } from 'app/plugins/datasource/grafana-pyroscope-datasource/dataquery.gen'; import { Query } from 'app/plugins/datasource/grafana-pyroscope-datasource/types'; import { @@ -125,7 +124,7 @@ export default function SpanFlameGraph(props: SpanFlameGraphProps) { labelSelector, groupBy: [], profileTypeId: traceToProfilesOptions.profileTypeId ?? '', - queryType: 'profile' as PyroscopeQueryType, + queryType: 'profile' as const, spanSelector: [profileTagValue], refId: 'span-flamegraph-refId', datasource: { diff --git a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx index cf81e80bbd4..dd33913e41b 100644 --- a/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx +++ b/public/app/features/explore/TraceView/components/TraceTimelineViewer/VirtualizedTraceView.test.tsx @@ -47,11 +47,12 @@ let props = { describe('', () => { beforeEach(() => { jest.mocked(SpanTreeOffset).mockReturnValue(
); - Object.keys(props).forEach((key) => { - if (typeof props[key as keyof VirtualizedTraceViewProps] === 'function') { - (props[key as keyof VirtualizedTraceViewProps] as jest.Mock).mockReset(); + let key: keyof VirtualizedTraceViewProps; + for (key in props) { + if (typeof props[key] === 'function') { + (props[key] as jest.Mock).mockReset(); } - }); + } }); it('renders service name, operation name and duration for each span', () => { diff --git a/public/app/plugins/datasource/elasticsearch/datasource.ts b/public/app/plugins/datasource/elasticsearch/datasource.ts index 226e069c2bf..46ed43eaf7d 100644 --- a/public/app/plugins/datasource/elasticsearch/datasource.ts +++ b/public/app/plugins/datasource/elasticsearch/datasource.ts @@ -903,7 +903,7 @@ export class ElasticDatasource return false; } - for (const key of Object.keys(obj)) { + for (const key in obj) { if (Array.isArray(obj[key])) { for (const item of obj[key]) { if (this.objectContainsTemplate(item)) { diff --git a/public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts b/public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts index b7eec3ec160..9be994d73da 100644 --- a/public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts +++ b/public/app/plugins/datasource/prometheus/querybuilder/operationUtils.ts @@ -124,31 +124,33 @@ export function getOperationParamId(operationId: string, paramIndex: number) { } export function getRangeVectorParamDef(withRateInterval = false): QueryBuilderOperationParamDef { - const param: QueryBuilderOperationParamDef = { - name: 'Range', - type: 'string', - options: [ - { - label: '$__interval', - value: '$__interval', - // tooltip: 'Dynamic interval based on max data points, scrape and min interval', - }, - { label: '1m', value: '1m' }, - { label: '5m', value: '5m' }, - { label: '10m', value: '10m' }, - { label: '1h', value: '1h' }, - { label: '24h', value: '24h' }, - ], - }; + const options: Array> = [ + { + label: '$__interval', + value: '$__interval', + // tooltip: 'Dynamic interval based on max data points, scrape and min interval', + }, + { label: '1m', value: '1m' }, + { label: '5m', value: '5m' }, + { label: '10m', value: '10m' }, + { label: '1h', value: '1h' }, + { label: '24h', value: '24h' }, + ]; if (withRateInterval) { - (param.options as Array>).unshift({ + options.unshift({ label: '$__rate_interval', value: '$__rate_interval', // tooltip: 'Always above 4x scrape interval', }); } + const param: QueryBuilderOperationParamDef = { + name: 'Range', + type: 'string', + options, + }; + return param; } diff --git a/public/app/plugins/panel/geomap/utils/getFeatures.ts b/public/app/plugins/panel/geomap/utils/getFeatures.ts index 48f37446173..158be92f6e7 100644 --- a/public/app/plugins/panel/geomap/utils/getFeatures.ts +++ b/public/app/plugins/panel/geomap/utils/getFeatures.ts @@ -13,7 +13,7 @@ export function getLayerPropertyInfo(features: FeatureLike[]): LayerContentInfo const types = new Set(); const props = new Set(); features.some((feature, idx) => { - for (const key of Object.keys(feature.getProperties())) { + for (const key in feature.getProperties()) { if (key === 'geometry') { continue; } diff --git a/public/app/plugins/panel/timeseries/migrations.ts b/public/app/plugins/panel/timeseries/migrations.ts index fd67bfb9436..c27205c84a6 100644 --- a/public/app/plugins/panel/timeseries/migrations.ts +++ b/public/app/plugins/panel/timeseries/migrations.ts @@ -685,7 +685,7 @@ function validNumber(val: unknown): number | undefined { function getReducersFromLegend(obj: Record): string[] { const ids: string[] = []; - for (const key of Object.keys(obj)) { + for (const key in obj) { const r = fieldReducers.getIfExists(key); if (r) { ids.push(r.id);