Skip to content

Commit

Permalink
Add consistent-type-imports eslint rule in `obs-ux-infra_services-t…
Browse files Browse the repository at this point in the history
…eam` owned plugins (#204549)

Closes #204412

## Summary

This PR enforces `consistent-type-imports` eslint rule in
`x-pack/solutions/observability/plugins/*` plugins owned by
`obs-ux-infra_services-team`.

Detailed list of plugins:
- `x-pack/solutions/observability/plugins/apm`,
- `x-pack/solutions/observability/plugins/apm_data_access`,
- `x-pack/solutions/observability/plugins/infra`,
- `x-pack/solutions/observability/plugins/inventory`,
- `x-pack/solutions/observability/plugins/metrics_data_access`,
- `x-pack/solutions/observability/plugins/profiling`,
- `x-pack/solutions/observability/plugins/profiling_data_access`

Script for fixing eslint rules in above plugins:
```bash
yarn eslint --no-error-on-unmatched-pattern --quiet --fix "x-pack/solutions/observability/plugins/apm/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/apm_data_access/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/infra/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/inventory/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/metrics_data_access/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/profiling/**/*.{js,mjs,ts,tsx}" "x-pack/solutions/observability/plugins/profiling_data_access/**/*.{js,mjs,ts,tsx}"
```

## Results

The affected plugins have been profiled using `node
scripts/build_kibana_platform_plugins.js --dist --profile --focus=apm
--no-cache` command and bundle size checked manually (`du -s` command).

#### APM plugin
Zero benefits in terms of size.
<img width="1728" alt="Screenshot 2024-12-19 at 12 18 36"
src="https://github.com/user-attachments/assets/d86be5d8-a4ad-4d9c-bac1-110a0c6bba81"
/>

#### Infra plugin
Zero benefits in terms of size.
<img width="1728" alt="Screenshot 2024-12-19 at 12 56 08"
src="https://github.com/user-attachments/assets/410bc068-1f20-4de8-ac4e-89c74478ec59"
/>

#### Profiling plugin
Zero benefits in terms of size.
<img width="1725" alt="image"
src="https://github.com/user-attachments/assets/bf47c319-0716-4a5b-9858-94ce7d2a3251"
/>

## Conclusions

- Using [type-only
imports](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
in Kibana doesn't provide any benefits in terms of bundle size,
- Possible safeguarding against edge-case TS errors
- avoiding unintentional side effects
([source](https://typescript-eslint.io/blog/consistent-type-imports-and-exports-why-and-how/#avoiding-unintentional-side-effects))
- circular dependency reference error
[(source)](https://stackoverflow.com/questions/40982927/using-import-type-statement-to-fix-circular-dependency-reference-error)
- Better ground for incoming tooling (improving performance, reliability
with type definition analysis),
- Clearer code intent.
  • Loading branch information
miloszmarcinkowski authored Jan 2, 2025
1 parent 1f8d841 commit 6461b7e
Show file tree
Hide file tree
Showing 2,080 changed files with 5,255 additions and 5,154 deletions.
14 changes: 14 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,20 @@ module.exports = {
],
},
},
{
files: [
'x-pack/solutions/observability/plugins/apm/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/apm_data_access/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/infra/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/inventory/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/metrics_data_access/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/profiling/**/*.{js,mjs,ts,tsx}',
'x-pack/solutions/observability/plugins/profiling_data_access/**/*.{js,mjs,ts,tsx}',
],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
},
},

/**
* Fleet overrides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import t from 'io-ts';
import { agentConfigurationIntakeRt } from './runtime_types/agent_configuration_intake_rt';
import type t from 'io-ts';
import type { agentConfigurationIntakeRt } from './runtime_types/agent_configuration_intake_rt';

export type AgentConfigurationIntake = t.TypeOf<typeof agentConfigurationIntakeRt>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import * as t from 'io-ts';
import { settingDefinitions } from '../setting_definitions';
import { SettingValidation } from '../setting_definitions/types';
import type { SettingValidation } from '../setting_definitions/types';

// retrieve validation from config definitions settings and validate on the server
const knownSettings = settingDefinitions.reduce<Record<string, SettingValidation>>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import * as t from 'io-ts';
import { either } from 'fp-ts/lib/Either';
import moment, { unitOfTime } from 'moment';
import { amountAndUnitToObject, AmountAndUnit } from '../amount_and_unit';
import type { unitOfTime } from 'moment';
import moment from 'moment';
import type { AmountAndUnit } from '../amount_and_unit';
import { amountAndUnitToObject } from '../amount_and_unit';
import { getRangeTypeMessage } from './get_range_type_message';

function toMilliseconds({ amount, unit }: AmountAndUnit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { captureBodyRt } from '../runtime_types/capture_body_rt';
import { logLevelRt } from '../runtime_types/log_level_rt';
import { logEcsReformattingRt } from '../runtime_types/log_ecs_reformatting_rt';
import { traceContinuationStrategyRt } from '../runtime_types/trace_continuation_strategy_rt';
import { RawSettingDefinition } from './types';
import type { RawSettingDefinition } from './types';

export const generalSettings: RawSettingDefinition[] = [
// API Request Size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { omit } from 'lodash';
import { filterByAgent, settingDefinitions } from '.';
import { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import { SettingDefinition } from './types';
import type { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import type { SettingDefinition } from './types';

describe('filterByAgent', () => {
describe('when `excludeAgents` is dotnet and nodejs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import * as t from 'io-ts';
import { sortBy } from 'lodash';
import { isRight } from 'fp-ts/lib/Either';
import { PathReporter } from 'io-ts/lib/PathReporter';
import { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import type { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import { booleanRt } from '../runtime_types/boolean_rt';
import { getIntegerRt } from '../runtime_types/integer_rt';
import { isRumOrMobileAgentName } from '../../agent_name';
import { floatThreeDecimalPlacesRt } from '../runtime_types/float_three_decimal_places_rt';
import { floatFourDecimalPlacesRt } from '../runtime_types/float_four_decimal_places_rt';
import { RawSettingDefinition, SettingDefinition } from './types';
import type { RawSettingDefinition, SettingDefinition } from './types';
import { generalSettings } from './general_settings';
import { javaSettings } from './java_settings';
import { mobileSettings } from './mobile_settings';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { RawSettingDefinition } from './types';
import type { RawSettingDefinition } from './types';

export const javaSettings: RawSettingDefinition[] = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { RawSettingDefinition } from './types';
import type { RawSettingDefinition } from './types';

export const mobileSettings: RawSettingDefinition[] = [
// Session sample rate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import * as t from 'io-ts';
import { AgentName } from '../../../typings/es_schemas/ui/fields/agent';
import type * as t from 'io-ts';
import type { AgentName } from '../../../typings/es_schemas/ui/fields/agent';

// TODO: is it possible to get rid of `any`?
export type SettingValidation = t.Type<any, string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { DATAFEED_STATE, JOB_STATE } from '@kbn/ml-plugin/common';
import { Environment } from '../environment_rt';
import type { DATAFEED_STATE, JOB_STATE } from '@kbn/ml-plugin/common';
import type { Environment } from '../environment_rt';

export interface ApmMlJob {
environment: Environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/
import { v4 as uuidv4 } from 'uuid';
import { ENVIRONMENT_ALL } from '../environment_filter_values';
import { Environment } from '../environment_rt';
import type { Environment } from '../environment_rt';
import { AnomalyDetectorType } from './apm_ml_detectors';
import { getPreferredServiceAnomalyTimeseries } from './get_preferred_service_anomaly_timeseries';
import { ServiceAnomalyTimeseries } from './service_anomaly_timeseries';
import type { ServiceAnomalyTimeseries } from './service_anomaly_timeseries';

const PROD = 'production' as Environment;
const DEV = 'development' as Environment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { Environment } from '../environment_rt';
import { AnomalyDetectorType } from './apm_ml_detectors';
import { ServiceAnomalyTimeseries } from './service_anomaly_timeseries';
import type { Environment } from '../environment_rt';
import type { AnomalyDetectorType } from './apm_ml_detectors';
import type { ServiceAnomalyTimeseries } from './service_anomaly_timeseries';

export function getPreferredServiceAnomalyTimeseries({
preferredEnvironment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n';
import { getSeverityType } from '@kbn/ml-anomaly-utils/get_severity_type';
import { getSeverityColor as mlGetSeverityColor } from '@kbn/ml-anomaly-utils/get_severity_color';
import { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils/anomaly_severity';
import { ServiceHealthStatus } from '../service_health_status';
import type { ServiceHealthStatus } from '../service_health_status';

export interface ServiceAnomalyStats {
transactionType?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { Coordinate } from '../../typings/timeseries';
import { AnomalyDetectorType } from './apm_ml_detectors';
import type { Coordinate } from '../../typings/timeseries';
import type { AnomalyDetectorType } from './apm_ml_detectors';

export interface ServiceAnomalyTimeseries {
jobId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { AgentName } from '../typings/es_schemas/ui/fields/agent';
import { Coordinate } from '../typings/timeseries';
import type { AgentName } from '../typings/es_schemas/ui/fields/agent';
import type { Coordinate } from '../typings/timeseries';

export enum NodeType {
service = 'service',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { FieldValuePair, HistogramItem } from '../types';
import type { FieldValuePair, HistogramItem } from '../types';

import { CORRELATIONS_IMPACT_THRESHOLD } from './constants';
import type { CORRELATIONS_IMPACT_THRESHOLD } from './constants';

export interface FailedTransactionsCorrelation extends FieldValuePair {
doc_count: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { FieldValuePair, HistogramItem } from '../types';
import type { FieldValuePair, HistogramItem } from '../types';

export interface LatencyCorrelation extends FieldValuePair {
correlation: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { Environment } from '../environment_rt';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { Environment } from '../environment_rt';

export interface FieldValuePair {
fieldName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { apm, ApmFields, dedot } from '@kbn/apm-synthtrace-client';
import type { ApmFields } from '@kbn/apm-synthtrace-client';
import { apm, dedot } from '@kbn/apm-synthtrace-client';
import { getWaterfall } from '../../public/components/app/transaction_details/waterfall_with_summary/waterfall_container/waterfall/waterfall_helpers/waterfall_helpers';
import { Span } from '../../typings/es_schemas/ui/span';
import { Transaction } from '../../typings/es_schemas/ui/transaction';
import type { Span } from '../../typings/es_schemas/ui/span';
import type { Transaction } from '../../typings/es_schemas/ui/transaction';
import { getCriticalPath } from './get_critical_path';

describe('getCriticalPath', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
IWaterfall,
IWaterfallSpanOrTransaction,
} from '../../public/components/app/transaction_details/waterfall_with_summary/waterfall_container/waterfall/waterfall_helpers/waterfall_helpers';
import { CriticalPath, CriticalPathSegment } from './types';
import type { CriticalPath, CriticalPathSegment } from './types';

export function getCriticalPath(waterfall: IWaterfall): CriticalPath {
const segments: CriticalPathSegment[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/
import { extractTemplateVariableNames, getEncodedCustomLinkUrl } from '.';
import { Transaction } from '../../typings/es_schemas/ui/transaction';
import type { Transaction } from '../../typings/es_schemas/ui/transaction';

describe('Custom link', () => {
describe('extractTemplateVariableNames', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import {
import type {
SERVICE_NAME,
SERVICE_ENVIRONMENT,
TRANSACTION_NAME,
TRANSACTION_TYPE,
} from '../es_fields/apm';
import { FILTER_OPTIONS } from './custom_link_filter_options';
import type { FILTER_OPTIONS } from './custom_link_filter_options';

export interface CustomLinkES {
id?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { i18n } from '@kbn/i18n';
import { get } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import Mustache from 'mustache';
import { Transaction } from '../../typings/es_schemas/ui/transaction';
import type { Transaction } from '../../typings/es_schemas/ui/transaction';

export const INVALID_LICENSE = i18n.translate('xpack.apm.settings.customLink.license.text', {
defaultMessage:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { i18n } from '@kbn/i18n';
import { escapeKuery } from '@kbn/es-query';
import { SERVICE_ENVIRONMENT } from './es_fields/apm';
import { Environment } from './environment_rt';
import type { Environment } from './environment_rt';

export const ENVIRONMENT_ALL_VALUE = 'ENVIRONMENT_ALL' as const;
const ENVIRONMENT_NOT_DEFINED_VALUE = 'ENVIRONMENT_NOT_DEFINED' as const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import { get } from 'lodash';
import { AllowUnknownProperties } from '../../typings/common';
import { APMError } from '../../typings/es_schemas/ui/apm_error';
import { Span } from '../../typings/es_schemas/ui/span';
import { Transaction } from '../../typings/es_schemas/ui/transaction';
import type { AllowUnknownProperties } from '../../typings/common';
import type { APMError } from '../../typings/es_schemas/ui/apm_error';
import type { Span } from '../../typings/es_schemas/ui/span';
import type { Transaction } from '../../typings/es_schemas/ui/transaction';
import * as allApmFieldNames from './apm';
import * as infraMetricsFieldNames from './infra_metrics';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ILicense, LicenseType } from '@kbn/licensing-plugin/common/types';
import type { ILicense, LicenseType } from '@kbn/licensing-plugin/common/types';

function isActiveLicense(licenseType: LicenseType, license?: ILicense) {
return license && license.isActive && license.hasAtLeast(licenseType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
* 2.0.
*/

import { schema, TypeOf } from '@kbn/config-schema';
import type { TypeOf } from '@kbn/config-schema';
import { schema } from '@kbn/config-schema';
import { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils/anomaly_severity';
import { ApmRuleType } from '@kbn/rule-data-utils';
import type { ApmRuleType } from '@kbn/rule-data-utils';
import { AnomalyDetectorType } from '../anomaly_detection/apm_ml_detectors';
import { AggregationType } from './apm_rule_types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { AgentName } from '@kbn/elastic-agent-utils';
import { ServiceHealthStatus } from './service_health_status';
import type { AgentName } from '@kbn/elastic-agent-utils';
import type { ServiceHealthStatus } from './service_health_status';

export interface ServiceListItem {
serviceName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
*/

import { i18n } from '@kbn/i18n';
import cytoscape from 'cytoscape';
import { Coordinate } from '../typings/timeseries';
import { ServiceAnomalyStats } from './anomaly_detection';
import type cytoscape from 'cytoscape';
import type { Coordinate } from '../typings/timeseries';
import type { ServiceAnomalyStats } from './anomaly_detection';

// These should be imported, but until TypeScript 4.2 we're inlining them here.
// All instances of "agent.name", "service.name", "service.environment", "span.type",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import { AgentName } from '../typings/es_schemas/ui/fields/agent';
import { Environment } from './environment_rt';
import type { AgentName } from '../typings/es_schemas/ui/fields/agent';
import type { Environment } from './environment_rt';

export interface SpanLinkDetails {
traceId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { i18n } from '@kbn/i18n';
import { CustomIntegration } from '@kbn/custom-integrations-plugin/common';
import type { CustomIntegration } from '@kbn/custom-integrations-plugin/common';

const APM_INTEGRATION_CATEGORIES = ['observability', 'apm'];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { ValuesType } from 'utility-types';
import type { ValuesType } from 'utility-types';

// work around a TypeScript limitation described in https://stackoverflow.com/posts/49511416

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { SERVICE_ENVIRONMENT, SERVICE_NODE_NAME } from '../es_fields/apm';
import { ENVIRONMENT_ALL, ENVIRONMENT_NOT_DEFINED } from '../environment_filter_values';
import { SERVICE_NODE_NAME_MISSING } from '../service_nodes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { compact, isObject } from 'lodash';
import { Maybe } from '../../typings/common';
import type { Maybe } from '../../typings/common';

export interface KeyValuePair {
key: string;
Expand Down
Loading

0 comments on commit 6461b7e

Please sign in to comment.