From c0535abc06f61ae823768c5df80cbfd0cd8409d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Fern=C3=A1ndez=20Haro?= Date: Tue, 2 Mar 2021 10:53:36 +0000 Subject: [PATCH] [chore] Enable core's eslint rule: `@ts-expect-error` (#93086) * [chore] Enable core's eslint rules * Change comment from platform-team to core-team --- .eslintrc.js | 10 ++++++++- .../kibana/get_saved_object_counts.test.ts | 2 +- .../public/services/telemetry_sender.test.ts | 4 ---- .../public/services/telemetry_service.test.ts | 2 -- src/plugins/telemetry/server/fetcher.ts | 1 - .../routes/telemetry_opt_in_stats.test.ts | 1 - .../get_cluster_info.test.ts | 14 +++++------- .../get_cluster_stats.test.ts | 2 +- .../get_data_telemetry.test.ts | 4 ++-- .../get_local_stats.test.ts | 22 +++++++++---------- .../get_nodes_usage.test.ts | 2 +- .../get_stats_with_xpack.test.ts | 8 +++---- .../telemetry_collection/get_xpack.test.ts | 2 +- 13 files changed, 35 insertions(+), 39 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 7608bcb40a0b9..9cc7985b8bce2 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1316,7 +1316,7 @@ module.exports = { { files: [ - // platform-team owned code + // core-team owned code 'src/core/**', 'x-pack/plugins/features/**', 'x-pack/plugins/licensing/**', @@ -1325,6 +1325,14 @@ module.exports = { 'packages/kbn-config-schema', 'src/plugins/status_page/**', 'src/plugins/saved_objects_management/**', + 'packages/kbn-analytics/**', + 'packages/kbn-telemetry-tools/**', + 'src/plugins/kibana_usage_collection/**', + 'src/plugins/usage_collection/**', + 'src/plugins/telemetry/**', + 'src/plugins/telemetry_collection_manager/**', + 'src/plugins/telemetry_management_section/**', + 'x-pack/plugins/telemetry_collection_xpack/**', ], rules: { '@typescript-eslint/prefer-ts-expect-error': 'error', diff --git a/src/plugins/kibana_usage_collection/server/collectors/kibana/get_saved_object_counts.test.ts b/src/plugins/kibana_usage_collection/server/collectors/kibana/get_saved_object_counts.test.ts index dcc3af949878e..15cbecde386f7 100644 --- a/src/plugins/kibana_usage_collection/server/collectors/kibana/get_saved_object_counts.test.ts +++ b/src/plugins/kibana_usage_collection/server/collectors/kibana/get_saved_object_counts.test.ts @@ -12,7 +12,7 @@ import { getSavedObjectsCounts } from './get_saved_object_counts'; export function mockGetSavedObjectsCounts(params: any) { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; esClient.search.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: { ...params }, } diff --git a/src/plugins/telemetry/public/services/telemetry_sender.test.ts b/src/plugins/telemetry/public/services/telemetry_sender.test.ts index 805b53379c815..82dbdb49f38f5 100644 --- a/src/plugins/telemetry/public/services/telemetry_sender.test.ts +++ b/src/plugins/telemetry/public/services/telemetry_sender.test.ts @@ -126,9 +126,7 @@ describe('TelemetrySender', () => { originalFetch = window.fetch; }); - // @ts-ignore beforeEach(() => (window.fetch = mockFetch = jest.fn())); - // @ts-ignore afterAll(() => (window.fetch = originalFetch)); it('does not send if already sending', async () => { @@ -250,9 +248,7 @@ describe('TelemetrySender', () => { originalSetInterval = window.setInterval; }); - // @ts-ignore beforeEach(() => (window.setInterval = mockSetInterval = jest.fn())); - // @ts-ignore afterAll(() => (window.setInterval = originalSetInterval)); it('calls sendIfDue every 60000 ms', () => { diff --git a/src/plugins/telemetry/public/services/telemetry_service.test.ts b/src/plugins/telemetry/public/services/telemetry_service.test.ts index 465daf1e66048..c06352208651a 100644 --- a/src/plugins/telemetry/public/services/telemetry_service.test.ts +++ b/src/plugins/telemetry/public/services/telemetry_service.test.ts @@ -211,9 +211,7 @@ describe('TelemetryService', () => { originalFetch = window.fetch; }); - // @ts-ignore beforeEach(() => (window.fetch = mockFetch = jest.fn())); - // @ts-ignore afterAll(() => (window.fetch = originalFetch)); it('reports opt-in status to telemetry url', async () => { diff --git a/src/plugins/telemetry/server/fetcher.ts b/src/plugins/telemetry/server/fetcher.ts index 76dfa398ec5e4..5db1b62cb3e26 100644 --- a/src/plugins/telemetry/server/fetcher.ts +++ b/src/plugins/telemetry/server/fetcher.ts @@ -8,7 +8,6 @@ import { Observable, Subscription, timer } from 'rxjs'; import { take } from 'rxjs/operators'; -// @ts-ignore import fetch from 'node-fetch'; import { TelemetryCollectionManagerPluginStart, diff --git a/src/plugins/telemetry/server/routes/telemetry_opt_in_stats.test.ts b/src/plugins/telemetry/server/routes/telemetry_opt_in_stats.test.ts index deb8e10280065..6660a36e76199 100644 --- a/src/plugins/telemetry/server/routes/telemetry_opt_in_stats.test.ts +++ b/src/plugins/telemetry/server/routes/telemetry_opt_in_stats.test.ts @@ -7,7 +7,6 @@ */ jest.mock('node-fetch'); -// @ts-ignore import fetch from 'node-fetch'; import { sendTelemetryOptInStatus } from './telemetry_opt_in_stats'; import { StatsGetterConfig } from 'src/plugins/telemetry_collection_manager/server'; diff --git a/src/plugins/telemetry/server/telemetry_collection/get_cluster_info.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_cluster_info.test.ts index 2fc6fd355d7ac..9e70e31925226 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_cluster_info.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_cluster_info.test.ts @@ -11,14 +11,12 @@ import { getClusterInfo } from './get_cluster_info'; export function mockGetClusterInfo(clusterInfo: any) { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; - esClient.info - // @ts-ignore we only care about the response body - .mockResolvedValue( - // @ts-ignore we only care about the response body - { - body: { ...clusterInfo }, - } - ); + esClient.info.mockResolvedValue( + // @ts-expect-error we only care about the response body + { + body: { ...clusterInfo }, + } + ); return esClient; } diff --git a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts index 40325ba854ea2..a2c22fbbb0a78 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_cluster_stats.test.ts @@ -21,7 +21,7 @@ describe('get_cluster_stats', () => { const response = Promise.resolve({ body: { cluster_uuid: '1234' } }); const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; esClient.cluster.stats.mockImplementationOnce( - // @ts-ignore the method only cares about the response body + // @ts-expect-error the method only cares about the response body async (_params = { timeout: TIMEOUT }) => { return response; } diff --git a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts index 986b4c45849ca..c892f27905e0d 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_data_telemetry/get_data_telemetry.test.ts @@ -265,7 +265,7 @@ function mockEsClient( indexStats: any = {} ) { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; - // @ts-ignore + // @ts-expect-error esClient.indices.getMapping.mockImplementationOnce(async () => { const body = Object.fromEntries( indicesMappings.map((index) => [ @@ -294,7 +294,7 @@ function mockEsClient( ); return { body }; }); - // @ts-ignore + // @ts-expect-error esClient.indices.stats.mockImplementationOnce(async () => { return { body: indexStats }; }); diff --git a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts index 7a6e7f2cf56ea..45db15bbdedb0 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_local_stats.test.ts @@ -24,19 +24,17 @@ function mockUsageCollection(kibanaUsage = {}) { // set up successful call mocks for info, cluster stats, nodes usage and data telemetry function mockGetLocalStats(clusterInfo: any, clusterStats: any) { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; - esClient.info - // @ts-ignore we only care about the response body - .mockResolvedValue( - // @ts-ignore we only care about the response body - { - body: { ...clusterInfo }, - } - ); + esClient.info.mockResolvedValue( + // @ts-expect-error we only care about the response body + { + body: { ...clusterInfo }, + } + ); esClient.cluster.stats - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body .mockResolvedValue({ body: { ...clusterStats } }); esClient.nodes.usage.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: { cluster_name: 'testCluster', @@ -64,9 +62,9 @@ function mockGetLocalStats(clusterInfo: any, clusterStats: any) { }, } ); - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body esClient.indices.getMapping.mockResolvedValue({ body: { mappings: {} } }); - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body esClient.indices.stats.mockResolvedValue({ body: { indices: {} } }); return esClient; } diff --git a/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.test.ts b/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.test.ts index 145ad89e7d462..9192afd3376d5 100644 --- a/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.test.ts +++ b/src/plugins/telemetry/server/telemetry_collection/get_nodes_usage.test.ts @@ -40,7 +40,7 @@ describe('get_nodes_usage', () => { const response = Promise.resolve({ body: mockedNodesFetchResponse }); const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; esClient.nodes.usage.mockImplementationOnce( - // @ts-ignore + // @ts-expect-error async (_params = { timeout: TIMEOUT }) => { return response; } diff --git a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts index 047337bb48673..fed18bcb461e3 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_stats_with_xpack.test.ts @@ -61,22 +61,22 @@ function mockEsClient() { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; // mock for license should return a basic license esClient.license.get.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: { license: { type: 'basic' } } } ); // mock for xpack usage should return an empty object esClient.xpack.usage.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: {} } ); // mock for nodes usage should resolve for this test esClient.nodes.usage.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: { cluster_name: 'test cluster', nodes: nodesUsage } } ); // mock for info should resolve for this test esClient.info.mockResolvedValue( - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body { body: { cluster_uuid: 'test', diff --git a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_xpack.test.ts b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_xpack.test.ts index c438abda8ca83..48b58c7679789 100644 --- a/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_xpack.test.ts +++ b/x-pack/plugins/telemetry_collection_xpack/server/telemetry_collection/get_xpack.test.ts @@ -12,7 +12,7 @@ describe('get_xpack', () => { describe('getXPackUsage', () => { it('uses esClient to get /_xpack/usage API', async () => { const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; - // @ts-ignore we only care about the response body + // @ts-expect-error we only care about the response body esClient.xpack.usage.mockResolvedValue({ body: {} }); const result = await getXPackUsage(esClient); expect(result).toEqual({});