Skip to content

Commit

Permalink
Remove the any type usages from the expressions plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic committed Oct 1, 2021
1 parent f313da6 commit b70d5fc
Show file tree
Hide file tree
Showing 53 changed files with 377 additions and 271 deletions.
8 changes: 4 additions & 4 deletions src/plugins/expressions/common/ast/build_expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ import { parse } from './parse';
* @param val Value you want to check.
* @return boolean
*/
export function isExpressionAstBuilder(val: any): val is ExpressionAstExpressionBuilder {
return val?.type === 'expression_builder';
export function isExpressionAstBuilder(val: unknown): val is ExpressionAstExpressionBuilder {
return (val as Record<string, unknown> | undefined)?.type === 'expression_builder';
}

/** @internal */
export function isExpressionAst(val: any): val is ExpressionAstExpression {
return val?.type === 'expression';
export function isExpressionAst(val: unknown): val is ExpressionAstExpression {
return (val as Record<string, unknown> | undefined)?.type === 'expression';
}

export interface ExpressionAstExpressionBuilder {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/expressions/common/ast/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type ExpressionAstFunctionDebug = {
/**
* Raw error that was thrown by the function, if any.
*/
rawError?: any | Error;
rawError?: any | Error; // eslint-disable-line @typescript-eslint/no-explicit-any

/**
* Time in milliseconds it took to execute the function. Duration can be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('Execution abortion tests', () => {
const completed = jest.fn();
const aborted = jest.fn();

const defer: ExpressionFunctionDefinition<'defer', any, { time: number }, any> = {
const defer: ExpressionFunctionDefinition<'defer', unknown, { time: number }, unknown> = {
name: 'defer',
args: {
time: {
Expand Down
46 changes: 28 additions & 18 deletions src/plugins/expressions/common/execution/execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { ExecutionContract } from './execution_contract';

beforeAll(() => {
if (typeof performance === 'undefined') {
(global as any).performance = { now: Date.now };
global.performance = { now: Date.now } as typeof performance;
}
});

Expand All @@ -41,7 +41,7 @@ const createExecution = (
const run = async (
expression: string = 'foo bar=123',
context?: Record<string, unknown>,
input: any = null
input: unknown = null
) => {
const execution = createExecution(expression, context);
execution.start(input);
Expand Down Expand Up @@ -262,45 +262,45 @@ describe('Execution', () => {

describe('execution context', () => {
test('context.variables is an object', async () => {
const { result } = (await run('introspectContext key="variables"')) as any;
const { result } = await run('introspectContext key="variables"');

expect(result).toHaveProperty('result', expect.any(Object));
});

test('context.types is an object', async () => {
const { result } = (await run('introspectContext key="types"')) as any;
const { result } = await run('introspectContext key="types"');

expect(result).toHaveProperty('result', expect.any(Object));
});

test('context.abortSignal is an object', async () => {
const { result } = (await run('introspectContext key="abortSignal"')) as any;
const { result } = await run('introspectContext key="abortSignal"');

expect(result).toHaveProperty('result', expect.any(Object));
});

test('context.inspectorAdapters is an object', async () => {
const { result } = (await run('introspectContext key="inspectorAdapters"')) as any;
const { result } = await run('introspectContext key="inspectorAdapters"');

expect(result).toHaveProperty('result', expect.any(Object));
});

test('context.getKibanaRequest is a function if provided', async () => {
const { result } = (await run('introspectContext key="getKibanaRequest"', {
const { result } = await run('introspectContext key="getKibanaRequest"', {
kibanaRequest: {},
})) as any;
});

expect(result).toHaveProperty('result', expect.any(Function));
});

test('context.getKibanaRequest is undefined if not provided', async () => {
const { result } = (await run('introspectContext key="getKibanaRequest"')) as any;
const { result } = await run('introspectContext key="getKibanaRequest"');

expect(result).toHaveProperty('result', undefined);
});

test('unknown context key is undefined', async () => {
const { result } = (await run('introspectContext key="foo"')) as any;
const { result } = await run('introspectContext key="foo"');

expect(result).toHaveProperty('result', undefined);
});
Expand All @@ -314,7 +314,7 @@ describe('Execution', () => {

describe('inspector adapters', () => {
test('by default, "tables" and "requests" inspector adapters are available', async () => {
const { result } = (await run('introspectContext key="inspectorAdapters"')) as any;
const { result } = await run('introspectContext key="inspectorAdapters"');
expect(result).toHaveProperty(
'result',
expect.objectContaining({
Expand All @@ -326,9 +326,9 @@ describe('Execution', () => {

test('can set custom inspector adapters', async () => {
const inspectorAdapters = {};
const { result } = (await run('introspectContext key="inspectorAdapters"', {
const { result } = await run('introspectContext key="inspectorAdapters"', {
inspectorAdapters,
})) as any;
});
expect(result).toHaveProperty('result', inspectorAdapters);
});

Expand All @@ -351,7 +351,7 @@ describe('Execution', () => {

describe('expression abortion', () => {
test('context has abortSignal object', async () => {
const { result } = (await run('introspectContext key="abortSignal"')) as any;
const { result } = await run('introspectContext key="abortSignal"');

expect(result).toHaveProperty('result.aborted', false);
});
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('Execution', () => {
testScheduler.run(({ cold, expectObservable }) => {
const arg = cold(' -a-b-c|', { a: 1, b: 2, c: 3 });
const expected = ' -a-b-c|';
const observable: ExpressionFunctionDefinition<'observable', any, {}, any> = {
const observable: ExpressionFunctionDefinition<'observable', unknown, {}, unknown> = {
name: 'observable',
args: {},
help: '',
Expand Down Expand Up @@ -468,7 +468,7 @@ describe('Execution', () => {
});

test('does not execute remaining functions in pipeline', async () => {
const spy: ExpressionFunctionDefinition<'spy', any, {}, any> = {
const spy: ExpressionFunctionDefinition<'spy', unknown, {}, unknown> = {
name: 'spy',
args: {},
help: '',
Expand Down Expand Up @@ -621,7 +621,12 @@ describe('Execution', () => {
help: '',
fn: () => arg2,
};
const max: ExpressionFunctionDefinition<'max', any, { val1: number; val2: number }, any> = {
const max: ExpressionFunctionDefinition<
'max',
unknown,
{ val1: number; val2: number },
unknown
> = {
name: 'max',
args: {
val1: { help: '', types: ['number'] },
Expand Down Expand Up @@ -679,7 +684,12 @@ describe('Execution', () => {

describe('when arguments are missing', () => {
it('when required argument is missing and has not alias, returns error', async () => {
const requiredArg: ExpressionFunctionDefinition<'requiredArg', any, { arg: any }, any> = {
const requiredArg: ExpressionFunctionDefinition<
'requiredArg',
unknown,
{ arg: unknown },
unknown
> = {
name: 'requiredArg',
args: {
arg: {
Expand Down
Loading

0 comments on commit b70d5fc

Please sign in to comment.