[chore] Enable core's eslint rule: @ts-expect-error (#93086)

* [chore] Enable core's eslint rules

* Change comment from platform-team to core-team
This commit is contained in:
Alejandro Fernández Haro 2021-03-02 10:53:36 +00:00 committed by GitHub
parent 03cc5cc0c2
commit c0535abc06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 35 additions and 39 deletions

View file

@ -1316,7 +1316,7 @@ module.exports = {
{ {
files: [ files: [
// platform-team owned code // core-team owned code
'src/core/**', 'src/core/**',
'x-pack/plugins/features/**', 'x-pack/plugins/features/**',
'x-pack/plugins/licensing/**', 'x-pack/plugins/licensing/**',
@ -1325,6 +1325,14 @@ module.exports = {
'packages/kbn-config-schema', 'packages/kbn-config-schema',
'src/plugins/status_page/**', 'src/plugins/status_page/**',
'src/plugins/saved_objects_management/**', '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: { rules: {
'@typescript-eslint/prefer-ts-expect-error': 'error', '@typescript-eslint/prefer-ts-expect-error': 'error',

View file

@ -12,7 +12,7 @@ import { getSavedObjectsCounts } from './get_saved_object_counts';
export function mockGetSavedObjectsCounts(params: any) { export function mockGetSavedObjectsCounts(params: any) {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
esClient.search.mockResolvedValue( esClient.search.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
{ {
body: { ...params }, body: { ...params },
} }

View file

@ -126,9 +126,7 @@ describe('TelemetrySender', () => {
originalFetch = window.fetch; originalFetch = window.fetch;
}); });
// @ts-ignore
beforeEach(() => (window.fetch = mockFetch = jest.fn())); beforeEach(() => (window.fetch = mockFetch = jest.fn()));
// @ts-ignore
afterAll(() => (window.fetch = originalFetch)); afterAll(() => (window.fetch = originalFetch));
it('does not send if already sending', async () => { it('does not send if already sending', async () => {
@ -250,9 +248,7 @@ describe('TelemetrySender', () => {
originalSetInterval = window.setInterval; originalSetInterval = window.setInterval;
}); });
// @ts-ignore
beforeEach(() => (window.setInterval = mockSetInterval = jest.fn())); beforeEach(() => (window.setInterval = mockSetInterval = jest.fn()));
// @ts-ignore
afterAll(() => (window.setInterval = originalSetInterval)); afterAll(() => (window.setInterval = originalSetInterval));
it('calls sendIfDue every 60000 ms', () => { it('calls sendIfDue every 60000 ms', () => {

View file

@ -211,9 +211,7 @@ describe('TelemetryService', () => {
originalFetch = window.fetch; originalFetch = window.fetch;
}); });
// @ts-ignore
beforeEach(() => (window.fetch = mockFetch = jest.fn())); beforeEach(() => (window.fetch = mockFetch = jest.fn()));
// @ts-ignore
afterAll(() => (window.fetch = originalFetch)); afterAll(() => (window.fetch = originalFetch));
it('reports opt-in status to telemetry url', async () => { it('reports opt-in status to telemetry url', async () => {

View file

@ -8,7 +8,6 @@
import { Observable, Subscription, timer } from 'rxjs'; import { Observable, Subscription, timer } from 'rxjs';
import { take } from 'rxjs/operators'; import { take } from 'rxjs/operators';
// @ts-ignore
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import { import {
TelemetryCollectionManagerPluginStart, TelemetryCollectionManagerPluginStart,

View file

@ -7,7 +7,6 @@
*/ */
jest.mock('node-fetch'); jest.mock('node-fetch');
// @ts-ignore
import fetch from 'node-fetch'; import fetch from 'node-fetch';
import { sendTelemetryOptInStatus } from './telemetry_opt_in_stats'; import { sendTelemetryOptInStatus } from './telemetry_opt_in_stats';
import { StatsGetterConfig } from 'src/plugins/telemetry_collection_manager/server'; import { StatsGetterConfig } from 'src/plugins/telemetry_collection_manager/server';

View file

@ -11,10 +11,8 @@ import { getClusterInfo } from './get_cluster_info';
export function mockGetClusterInfo(clusterInfo: any) { export function mockGetClusterInfo(clusterInfo: any) {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
esClient.info esClient.info.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
.mockResolvedValue(
// @ts-ignore we only care about the response body
{ {
body: { ...clusterInfo }, body: { ...clusterInfo },
} }

View file

@ -21,7 +21,7 @@ describe('get_cluster_stats', () => {
const response = Promise.resolve({ body: { cluster_uuid: '1234' } }); const response = Promise.resolve({ body: { cluster_uuid: '1234' } });
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
esClient.cluster.stats.mockImplementationOnce( 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 }) => { async (_params = { timeout: TIMEOUT }) => {
return response; return response;
} }

View file

@ -265,7 +265,7 @@ function mockEsClient(
indexStats: any = {} indexStats: any = {}
) { ) {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
// @ts-ignore // @ts-expect-error
esClient.indices.getMapping.mockImplementationOnce(async () => { esClient.indices.getMapping.mockImplementationOnce(async () => {
const body = Object.fromEntries( const body = Object.fromEntries(
indicesMappings.map((index) => [ indicesMappings.map((index) => [
@ -294,7 +294,7 @@ function mockEsClient(
); );
return { body }; return { body };
}); });
// @ts-ignore // @ts-expect-error
esClient.indices.stats.mockImplementationOnce(async () => { esClient.indices.stats.mockImplementationOnce(async () => {
return { body: indexStats }; return { body: indexStats };
}); });

View file

@ -24,19 +24,17 @@ function mockUsageCollection(kibanaUsage = {}) {
// set up successful call mocks for info, cluster stats, nodes usage and data telemetry // set up successful call mocks for info, cluster stats, nodes usage and data telemetry
function mockGetLocalStats(clusterInfo: any, clusterStats: any) { function mockGetLocalStats(clusterInfo: any, clusterStats: any) {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
esClient.info esClient.info.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
.mockResolvedValue(
// @ts-ignore we only care about the response body
{ {
body: { ...clusterInfo }, body: { ...clusterInfo },
} }
); );
esClient.cluster.stats 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 } }); .mockResolvedValue({ body: { ...clusterStats } });
esClient.nodes.usage.mockResolvedValue( esClient.nodes.usage.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
{ {
body: { body: {
cluster_name: 'testCluster', 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: {} } }); 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: {} } }); esClient.indices.stats.mockResolvedValue({ body: { indices: {} } });
return esClient; return esClient;
} }

View file

@ -40,7 +40,7 @@ describe('get_nodes_usage', () => {
const response = Promise.resolve({ body: mockedNodesFetchResponse }); const response = Promise.resolve({ body: mockedNodesFetchResponse });
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
esClient.nodes.usage.mockImplementationOnce( esClient.nodes.usage.mockImplementationOnce(
// @ts-ignore // @ts-expect-error
async (_params = { timeout: TIMEOUT }) => { async (_params = { timeout: TIMEOUT }) => {
return response; return response;
} }

View file

@ -61,22 +61,22 @@ function mockEsClient() {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser;
// mock for license should return a basic license // mock for license should return a basic license
esClient.license.get.mockResolvedValue( 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' } } } { body: { license: { type: 'basic' } } }
); );
// mock for xpack usage should return an empty object // mock for xpack usage should return an empty object
esClient.xpack.usage.mockResolvedValue( esClient.xpack.usage.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
{ body: {} } { body: {} }
); );
// mock for nodes usage should resolve for this test // mock for nodes usage should resolve for this test
esClient.nodes.usage.mockResolvedValue( 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 } } { body: { cluster_name: 'test cluster', nodes: nodesUsage } }
); );
// mock for info should resolve for this test // mock for info should resolve for this test
esClient.info.mockResolvedValue( esClient.info.mockResolvedValue(
// @ts-ignore we only care about the response body // @ts-expect-error we only care about the response body
{ {
body: { body: {
cluster_uuid: 'test', cluster_uuid: 'test',

View file

@ -12,7 +12,7 @@ describe('get_xpack', () => {
describe('getXPackUsage', () => { describe('getXPackUsage', () => {
it('uses esClient to get /_xpack/usage API', async () => { it('uses esClient to get /_xpack/usage API', async () => {
const esClient = elasticsearchServiceMock.createClusterClient().asInternalUser; 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: {} }); esClient.xpack.usage.mockResolvedValue({ body: {} });
const result = await getXPackUsage(esClient); const result = await getXPackUsage(esClient);
expect(result).toEqual({}); expect(result).toEqual({});