Loki: Remove any type from logs.test.ts (#55303)

* Remove any type from logs.test.ts

* Replace unknown types and move type casting to variables
This commit is contained in:
Gareth Dawson 2022-09-16 16:57:42 +01:00 committed by GitHub
parent 0c4d181d1e
commit 98a8908910
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 21 deletions

View File

@ -860,13 +860,6 @@ exports[`better eslint`] = {
[0, 0, 0, "Unexpected any. Specify a different type.", "2"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"]
],
"packages/grafana-data/src/utils/logs.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"],
[0, 0, 0, "Unexpected any. Specify a different type.", "3"],
[0, 0, 0, "Unexpected any. Specify a different type.", "4"]
],
"packages/grafana-data/src/utils/logs.ts:5381": [
[0, 0, 0, "Do not use any type assertions.", "0"],
[0, 0, 0, "Unexpected any. Specify a different type.", "1"],

View File

@ -1,4 +1,5 @@
import { MutableDataFrame } from '../dataframe/MutableDataFrame';
import { Labels } from '../types/data';
import { LogLevel, LogsModel, LogRowModel, LogsSortOrder } from '../types/logs';
import {
@ -66,11 +67,11 @@ describe('calculateLogsLabelStats()', () => {
entry: 'foo 1',
labels: {
foo: 'bar',
},
} as Labels,
},
];
] as LogRowModel[];
expect(calculateLogsLabelStats(rows as any, 'baz')).toEqual([]);
expect(calculateLogsLabelStats(rows, 'baz')).toEqual([]);
});
test('should return stats for found labels', () => {
@ -79,23 +80,23 @@ describe('calculateLogsLabelStats()', () => {
entry: 'foo 1',
labels: {
foo: 'bar',
},
} as Labels,
},
{
entry: 'foo 0',
labels: {
foo: 'xxx',
},
} as Labels,
},
{
entry: 'foo 2',
labels: {
foo: 'bar',
},
} as Labels,
},
];
] as LogRowModel[];
expect(calculateLogsLabelStats(rows as any, 'foo')).toMatchObject([
expect(calculateLogsLabelStats(rows, 'foo')).toMatchObject([
{
value: 'bar',
count: 2,
@ -215,9 +216,9 @@ describe('calculateFieldStats()', () => {
{
entry: 'foo=bar',
},
];
] as LogRowModel[];
expect(calculateFieldStats(rows as any, /baz=(.*)/)).toEqual([]);
expect(calculateFieldStats(rows, /baz=(.*)/)).toEqual([]);
});
test('should return stats for found field', () => {
@ -234,9 +235,9 @@ describe('calculateFieldStats()', () => {
{
entry: 't=2018-12-05T07:44:59+0000 foo=503',
},
];
] as LogRowModel[];
expect(calculateFieldStats(rows as any, /foo=("[^"]*"|\S+)/)).toMatchObject([
expect(calculateFieldStats(rows, /foo=("[^"]*"|\S+)/)).toMatchObject([
{
value: '"42 + 1"',
count: 2,
@ -363,8 +364,8 @@ describe('checkLogsError()', () => {
labels: {
__error__: 'Error Message',
foo: 'boo',
},
} as any as LogRowModel;
} as Labels,
} as LogRowModel;
test('should return correct error if error is present', () => {
expect(checkLogsError(log)).toStrictEqual({ hasError: true, errorMessage: 'Error Message' });
});