Skip to content

Commit

Permalink
Use consistent-type-imports lint rule to autofix type-only imports (#…
Browse files Browse the repository at this point in the history
…94464)

## Summary

Use the [`consistent-type-imports` lint rule ](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md) to use `import type ...` where possible

Code-only changes like this were recently added in #92979, but it was a more manual process.  This PR adds an autofixable lint rule which will keep the changes up-to-date and Just Work ™️
  • Loading branch information
John Schulz authored Mar 15, 2021
1 parent df98465 commit a4fa4a6
Show file tree
Hide file tree
Showing 160 changed files with 348 additions and 307 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ module.exports = {
{
files: ['x-pack/plugins/fleet/**/*.{js,mjs,ts,tsx}'],
rules: {
'@typescript-eslint/consistent-type-imports': 'error',
'import/order': [
'warn',
{
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/services/license.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { Observable, Subscription } from 'rxjs';
import type { Observable, Subscription } from 'rxjs';

import type { ILicense } from '../../../licensing/common/types';

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/fleet/common/types/models/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
* 2.0.
*/

import { AGENT_TYPE_EPHEMERAL, AGENT_TYPE_PERMANENT, AGENT_TYPE_TEMPORARY } from '../../constants';
import type {
AGENT_TYPE_EPHEMERAL,
AGENT_TYPE_PERMANENT,
AGENT_TYPE_TEMPORARY,
} from '../../constants';

import type { FullAgentPolicy } from './agent_policy';

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { agentPolicyStatuses } from '../../constants';
import type { agentPolicyStatuses } from '../../constants';
import type { DataType, ValueOf } from '../../types';

import type { PackagePolicy, PackagePolicyPackage } from './package_policy';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/epm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// TODO: Update when https://github.com/elastic/kibana/issues/53021 is closed
import type { SavedObject, SavedObjectAttributes, SavedObjectReference } from 'src/core/public';

import {
import type {
ASSETS_SAVED_OBJECT_TYPE,
agentAssetTypes,
dataTypes,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/common/types/models/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { outputType } from '../../constants';
import type { outputType } from '../../constants';
import type { ValueOf } from '../index';

export type OutputType = typeof outputType;
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/fleet/public/applications/fleet/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
*/

import React, { memo, useEffect, useState } from 'react';
import { AppMountParameters } from 'kibana/public';
import type { AppMountParameters } from 'kibana/public';
import { EuiCode, EuiEmptyPrompt, EuiErrorBoundary, EuiPanel } from '@elastic/eui';
import { createHashHistory, History } from 'history';
import type { History } from 'history';
import { createHashHistory } from 'history';
import { Router, Redirect, Route, Switch } from 'react-router-dom';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import styled from 'styled-components';
import useObservable from 'react-use/lib/useObservable';

import { FleetConfigType, FleetStartServices } from '../../plugin';
import type { FleetConfigType, FleetStartServices } from '../../plugin';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { EuiThemeProvider } from '../../../../../../src/plugins/kibana_react/common';

Expand All @@ -39,7 +40,7 @@ import { DataStreamApp } from './sections/data_stream';
import { FleetApp } from './sections/agents';
import { IngestManagerOverview } from './sections/overview';
import { ProtectedRoute } from './index';
import { UIExtensionsStorage } from './types';
import type { UIExtensionsStorage } from './types';
import { UIExtensionsContext } from './hooks/use_ui_extension';

const ErrorLayout = ({ children }: { children: JSX.Element }) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
EuiPopover,
EuiButton,
} from '@elastic/eui';
import { EuiButtonProps } from '@elastic/eui/src/components/button/button';
import { EuiContextMenuProps } from '@elastic/eui/src/components/context_menu/context_menu';
import { EuiContextMenuPanelProps } from '@elastic/eui/src/components/context_menu/context_menu_panel';
import type { EuiButtonProps } from '@elastic/eui/src/components/button/button';
import type { EuiContextMenuProps } from '@elastic/eui/src/components/context_menu/context_menu';
import type { EuiContextMenuPanelProps } from '@elastic/eui/src/components/context_menu/context_menu_panel';

type Props = {
button?: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styled from 'styled-components';
import { EuiText, EuiSpacer, EuiLink, EuiTitle, EuiCodeBlock } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { EnrollmentAPIKey } from '../../../types';
import type { EnrollmentAPIKey } from '../../../types';

interface Props {
kibanaUrl: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import React, { memo, ReactNode, Suspense } from 'react';
import type { ReactNode } from 'react';
import React, { memo, Suspense } from 'react';
import { EuiErrorBoundary } from '@elastic/eui';

import { Loading } from './loading';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import React, { memo } from 'react';
import styled from 'styled-components';
import { EuiFlexGroup, EuiFlexItem, EuiTabs, EuiTab, EuiSpacer } from '@elastic/eui';
import { Props as EuiTabProps } from '@elastic/eui/src/components/tabs/tab';
import { EuiFlexItemProps } from '@elastic/eui/src/components/flex/flex_item';
import type { Props as EuiTabProps } from '@elastic/eui/src/components/tabs/tab';
import type { EuiFlexItemProps } from '@elastic/eui/src/components/flex/flex_item';

const Container = styled.div`
border-bottom: ${(props) => props.theme.eui.euiBorderThin};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { memo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiText, EuiLink, EuiSpacer } from '@elastic/eui';
import { TutorialModuleNoticeComponent } from 'src/plugins/home/public';
import type { TutorialModuleNoticeComponent } from 'src/plugins/home/public';

import { useGetPackages, useLink, useCapabilities } from '../../hooks';
import { pkgKeyFromPackageInfo } from '../../services/pkg_key_from_package_info';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import { EuiFlexGroup, EuiFlexItem, EuiLink, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React, { CSSProperties, memo } from 'react';
import { EuiLinkProps } from '@elastic/eui/src/components/link/link';
import type { CSSProperties } from 'react';
import React, { memo } from 'react';
import type { EuiLinkProps } from '@elastic/eui/src/components/link/link';

const MIN_WIDTH: CSSProperties = { minWidth: 0 };
const NO_WRAP_WHITE_SPACE: CSSProperties = { whiteSpace: 'nowrap' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
*/

import React, { memo } from 'react';
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import type { EuiLinkAnchorProps } from '@elastic/eui';
import { EuiLink } from '@elastic/eui';

import { useLink } from '../hooks';
import { AGENT_SAVED_OBJECT_TYPE } from '../constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiLoadingSpinner } from '@elastic/eui';
import { EuiLoadingSpinnerSize } from '@elastic/eui/src/components/loading/loading_spinner';
import type { EuiLoadingSpinnerSize } from '@elastic/eui/src/components/loading/loading_spinner';

export const Loading: React.FunctionComponent<{ size?: EuiLoadingSpinnerSize }> = ({ size }) => (
<EuiFlexGroup justifyContent="spaceAround">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/

import React from 'react';
import { EuiIcon, EuiIconProps } from '@elastic/eui';
import type { EuiIconProps } from '@elastic/eui';
import { EuiIcon } from '@elastic/eui';

import { usePackageIconType, UsePackageIconType } from '../hooks';
import type { UsePackageIconType } from '../hooks';
import { usePackageIconType } from '../hooks';

export const PackageIcon: React.FunctionComponent<
UsePackageIconType & Omit<EuiIconProps, 'type'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

import React, { useState, useEffect, useMemo } from 'react';

import {
QueryStringInput,
IFieldType,
esKuery,
} from '../../../../../../../src/plugins/data/public';
import type { IFieldType } from '../../../../../../../src/plugins/data/public';
import { QueryStringInput, esKuery } from '../../../../../../../src/plugins/data/public';
import { useStartServices } from '../hooks';
import { INDEX_NAME, AGENT_SAVED_OBJECT_TYPE } from '../constants';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*/

import { i18n } from '@kbn/i18n';
import { ChromeBreadcrumb } from 'src/core/public';
import type { ChromeBreadcrumb } from 'src/core/public';

import { BASE_PATH, Page, DynamicPagePathValues, pagePathGetters } from '../constants';
import type { Page, DynamicPagePathValues } from '../constants';
import { BASE_PATH, pagePathGetters } from '../constants';

import { useStartServices } from './use_core';

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

import React, { useState, useContext, useEffect } from 'react';

import { GetFleetStatusResponse } from '../types';
import type { GetFleetStatusResponse } from '../types';

import { useConfig } from './use_config';
import { sendGetFleetStatus } from './use_request';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
*/

import React, { memo, useContext, useMemo } from 'react';
import { AppMountParameters } from 'kibana/public';
import type { AppMountParameters } from 'kibana/public';
import { useLocation } from 'react-router-dom';

import { AnyIntraAppRouteState } from '../types';
import type { AnyIntraAppRouteState } from '../types';

interface IntraAppState<S extends AnyIntraAppRouteState = AnyIntraAppRouteState> {
forRoute: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { useState, useEffect } from 'react';
import type { HttpSetup } from 'src/core/public';

import {
UseRequestConfig as _UseRequestConfig,
sendRequest as _sendRequest,
useRequest as _useRequest,
} from '../../../../../../../../src/plugins/es_ui_shared/public';
import type {
SendRequestConfig,
SendRequestResponse,
UseRequestConfig,
} from '../../../../../../../../src/plugins/es_ui_shared/public';

let httpClient: HttpSetup;

export type UseRequestConfig = _UseRequestConfig;
export type { UseRequestConfig } from '../../../../../../../../src/plugins/es_ui_shared/public';

/**
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useState } from 'react';
import { CriteriaWithPagination } from '@elastic/eui/src/components/basic_table/basic_table';
import type { CriteriaWithPagination } from '@elastic/eui/src/components/basic_table/basic_table';

export function useSorting<T>(defaultSorting: CriteriaWithPagination<T>['sort']) {
const [sorting, setSorting] = useState<CriteriaWithPagination<T>['sort']>(defaultSorting);
Expand Down
9 changes: 5 additions & 4 deletions x-pack/plugins/fleet/public/applications/fleet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { Redirect, Route, RouteProps } from 'react-router-dom';
import { CoreStart, AppMountParameters } from 'src/core/public';
import type { RouteProps } from 'react-router-dom';
import { Redirect, Route } from 'react-router-dom';
import type { CoreStart, AppMountParameters } from 'src/core/public';

import { FleetConfigType, FleetStartServices } from '../../plugin';
import type { FleetConfigType, FleetStartServices } from '../../plugin';

import { licenseService } from './hooks';
import { UIExtensionsStorage } from './types';
import type { UIExtensionsStorage } from './types';
import { AppRoutes, FleetAppContext, WithPermissionsAndSetup } from './app';

export interface ProtectedRouteProps extends RouteProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import styled from 'styled-components';
import { EuiTabs, EuiTab, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { Section } from '../sections';
import type { Section } from '../sections';
import { AlphaMessaging, SettingFlyout } from '../components';
import { useLink, useConfig } from '../hooks';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import React, { Fragment } from 'react';
import { EuiPageBody, EuiSpacer } from '@elastic/eui';

import { Header, HeaderProps } from '../components';
import type { HeaderProps } from '../components';
import { Header } from '../components';

import { Page, ContentWrapper } from './without_header';

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

import { createMemoryHistory, History, createHashHistory } from 'history';
import type { History } from 'history';
import { createMemoryHistory, createHashHistory } from 'history';
import React, { memo } from 'react';
import { render as reactRender, RenderOptions, RenderResult, act } from '@testing-library/react';
import type { RenderOptions, RenderResult } from '@testing-library/react';
import { render as reactRender, act } from '@testing-library/react';

import { ScopedHistory } from '../../../../../../../src/core/public';
import { FleetAppContext } from '../app';
import { FleetConfigType } from '../../../plugin';
import { UIExtensionsStorage } from '../types';
import type { FleetConfigType } from '../../../plugin';
import type { UIExtensionsStorage } from '../types';

import { createConfigurationMock } from './plugin_configuration';
import { createStartMock } from './plugin_interfaces';
import { createStartServices } from './fleet_start_services';
import { MockedFleetStart, MockedFleetStartServices } from './types';
import type { MockedFleetStart, MockedFleetStartServices } from './types';

type UiRender = (ui: React.ReactElement, options?: RenderOptions) => RenderResult;

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

import React from 'react';
import { I18nProvider } from '@kbn/i18n/react';
import { MockedKeys } from '@kbn/utility-types/jest';
import type { MockedKeys } from '@kbn/utility-types/jest';

import { coreMock } from '../../../../../../../src/core/public/mocks';
import { IStorage, Storage } from '../../../../../../../src/plugins/kibana_utils/public';
import type { IStorage } from '../../../../../../../src/plugins/kibana_utils/public';
import { Storage } from '../../../../../../../src/plugins/kibana_utils/public';
import { setHttpClient } from '../hooks/use_request';

import { createStartDepsMock } from './plugin_dependencies';
import { MockedFleetStartServices } from './types';
import type { MockedFleetStartServices } from './types';

// Taken from core. See: src/plugins/kibana_utils/public/storage/storage.test.ts
const createMockStore = (): MockedKeys<IStorage> => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { memo, useState, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiContextMenuItem, EuiPortal } from '@elastic/eui';

import { AgentPolicy } from '../../../types';
import type { AgentPolicy } from '../../../types';
import { useCapabilities } from '../../../hooks';
import { ContextMenuActions } from '../../../components';
import { AgentEnrollmentFlyout } from '../../agents/components';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiConfirmModal, EuiFormRow, EuiFieldText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

import { AgentPolicy } from '../../../types';
import type { AgentPolicy } from '../../../types';
import { sendCopyAgentPolicy, useStartServices } from '../../../hooks';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { i18n } from '@kbn/i18n';
import styled from 'styled-components';

import { dataTypes } from '../../../../../../common';
import { NewAgentPolicy, AgentPolicy } from '../../../types';
import type { NewAgentPolicy, AgentPolicy } from '../../../types';
import { isValidNamespace } from '../../../services';

import { AgentPolicyDeleteProvider } from './agent_policy_delete_provider';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { EuiCallOut, EuiConfirmModal, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';

import { AgentPolicy } from '../../../types';
import type { AgentPolicy } from '../../../types';

export const ConfirmDeployAgentPolicyModal: React.FunctionComponent<{
onConfirm: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FormattedMessage } from '@kbn/i18n/react';

import { useStartServices, sendRequest, sendDeletePackagePolicy, useConfig } from '../../../hooks';
import { AGENT_API_ROUTES, AGENT_SAVED_OBJECT_TYPE } from '../../../constants';
import { AgentPolicy } from '../../../types';
import type { AgentPolicy } from '../../../types';

interface Props {
agentPolicy: AgentPolicy;
Expand Down
Loading

0 comments on commit a4fa4a6

Please sign in to comment.