Skip to content

Commit

Permalink
[chore] Enable core's eslint rule: @ts-expect-error (elastic#93086)
Browse files Browse the repository at this point in the history
* [chore] Enable core's eslint rules

* Change comment from platform-team to core-team
  • Loading branch information
afharo authored and kibanamachine committed Mar 2, 2021
1 parent 30e4689 commit 42676d5
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 39 deletions.
10 changes: 9 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1320,7 +1320,7 @@ module.exports = {

{
files: [
// platform-team owned code
// core-team owned code
'src/core/**',
'x-pack/plugins/features/**',
'x-pack/plugins/licensing/**',
Expand All @@ -1329,6 +1329,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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
1 change: 0 additions & 1 deletion src/plugins/telemetry/server/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import { Observable, Subscription, timer } from 'rxjs';
import { take } from 'rxjs/operators';
// @ts-ignore
import fetch from 'node-fetch';
import {
TelemetryCollectionManagerPluginStart,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) => [
Expand Down Expand Up @@ -294,7 +294,7 @@ function mockEsClient(
);
return { body };
});
// @ts-ignore
// @ts-expect-error
esClient.indices.stats.mockImplementationOnce(async () => {
return { body: indexStats };
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({});
Expand Down

0 comments on commit 42676d5

Please sign in to comment.