Skip to content

Commit

Permalink
[Enterprise Search] Add eslint import/order rules (#90530)
Browse files Browse the repository at this point in the history
* Add import rules

- newlines between each group
- mocks in test files before everything else
- React before all other externals

* Run --fix on public/applications/workplace_search

* Manually fix errors still present in WS public files

- these appear to be mostly due to jest.mock() or const mixed in with imports, which confuses the autofixer

* Run --fix on public/applications/app_search

+ some manual fixes/tweaks along the way

* Run --fix on public/applications/shared

- some opinionated changes, particularly around IFlashMessages and grouping together types coming from Kibana (src->../../src)

* Run --fix on public/applications/enterprise_search

- mostly straightforward

* Run --fix on public/applications/__mocks__

* Fix remaining top-level public files

- Some opinionated changes (src/core -> ../../src/core) to keep types/mocks together

* Run --fix on server/ files

- same opinionated src->../src changes to keep deps grouped together

- opinionated require->import fetch change in enterprise_esarch_config_api.test.ts

- opinionated [] inclusion of builtins & external imports together (mostly for enterprise_search_request_handler.ts)
  • Loading branch information
Constance authored Feb 9, 2021
1 parent 4b3d1bf commit f339962
Show file tree
Hide file tree
Showing 489 changed files with 1,376 additions and 1,032 deletions.
33 changes: 33 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,39 @@ module.exports = {
// All files
files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'],
rules: {
'import/order': [
'error',
{
groups: ['unknown', ['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
pathGroups: [
{
pattern:
'{../../../../../../,../../../../../,../../../../,../../../,../../,../}{common/,*}__mocks__{*,/**}',
group: 'unknown',
},
{
pattern: '{**,.}/*.mock',
group: 'unknown',
},
{
pattern: 'react*',
group: 'external',
position: 'before',
},
{
pattern: '{@elastic/**,@kbn/**,src/**}',
group: 'internal',
},
],
pathGroupsExcludedImportTypes: [],
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
'newlines-between': 'always-and-inside-groups',
},
],
'import/newline-after-import': 'error',
'react-hooks/exhaustive-deps': 'off',
'react/jsx-boolean-value': ['error', 'never'],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
* NOTE: These variable names MUST start with 'mock*' in order for
* Jest to accept its use within a jest.mock()
*/
import { mockFlashMessagesValues, mockFlashMessagesActions } from './flash_messages_logic.mock';
import { mockHttpValues } from './http_logic.mock';
import { mockKibanaValues } from './kibana_logic.mock';
import { mockLicensingValues } from './licensing_logic.mock';
import { mockHttpValues } from './http_logic.mock';
import { mockTelemetryActions } from './telemetry_logic.mock';
import { mockFlashMessagesValues, mockFlashMessagesActions } from './flash_messages_logic.mock';

export const mockAllValues = {
...mockKibanaValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import { chartPluginMock } from '../../../../../../src/plugins/charts/public/mocks';

import { mockHistory } from './';

export const mockKibanaValues = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import React from 'react';
import { act } from 'react-dom/test-utils';

import { mount, ReactWrapper } from 'enzyme';
import { act } from 'react-dom/test-utils';

import { mountWithIntl } from './';

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

import React from 'react';

import { mount } from 'enzyme';

import { I18nProvider } from '@kbn/i18n/react';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';

import { shallow, mount, ReactWrapper } from 'enzyme';

import { I18nProvider, __IntlProvider } from '@kbn/i18n/react';

// Use fake component to extract `intl` property to use in tests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 2.0.
*/

import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__';
import { LogicMounter } from '../__mocks__';

import { DEFAULT_INITIAL_APP_DATA } from '../../../common/__mocks__';
import { AppLogic } from './app_logic';

describe('AppLogic', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { kea, MakeLogicType } from 'kea';

import { InitialAppData } from '../../../common/types';

import { ConfiguredLimits, Account, Role } from './types';

import { getRoleAbilities } from './utils/role';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import { mockKibanaValues, setMockValues, setMockActions, rerender } from '../..

import React from 'react';
import { useParams } from 'react-router-dom';

import { shallow } from 'enzyme';

import { Loading } from '../../../shared/loading';
import { FlashMessages } from '../../../shared/flash_messages';
import { Loading } from '../../../shared/loading';
import { LogRetentionCallout } from '../log_retention';
import { AnalyticsHeader, AnalyticsUnavailable } from './components';

import { AnalyticsLayout } from './analytics_layout';
import { AnalyticsHeader, AnalyticsUnavailable } from './components';

describe('AnalyticsLayout', () => {
const { history } = mockKibanaValues;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@

import React, { useEffect } from 'react';
import { useParams } from 'react-router-dom';

import { useValues, useActions } from 'kea';

import { EuiSpacer } from '@elastic/eui';

import { KibanaLogic } from '../../../shared/kibana';
import { FlashMessages } from '../../../shared/flash_messages';
import { KibanaLogic } from '../../../shared/kibana';
import { Loading } from '../../../shared/loading';

import { LogRetentionCallout, LogRetentionOptions } from '../log_retention';

import { AnalyticsLogic } from './';
import { AnalyticsHeader, AnalyticsUnavailable } from './components';

import { AnalyticsLogic } from './';

interface Props {
title: string;
isQueryView?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jest.mock('../engine', () => ({
import { nextTick } from '@kbn/test/jest';

import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';

import { AnalyticsLogic } from './';

describe('AnalyticsLogic', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import { kea, MakeLogicType } from 'kea';
import queryString from 'query-string';

import { KibanaLogic } from '../../../shared/kibana';
import { HttpLogic } from '../../../shared/http';
import { flashAPIErrors } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import { KibanaLogic } from '../../../shared/kibana';
import { EngineLogic } from '../engine';

import { DEFAULT_START_DATE, DEFAULT_END_DATE } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import '../../__mocks__/engine_logic.mock';

import React from 'react';
import { shallow } from 'enzyme';

import { Route, Switch } from 'react-router-dom';

import { shallow } from 'enzyme';

import { AnalyticsRouter } from './';

describe('AnalyticsRouter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import React from 'react';

import { shallow } from 'enzyme';

import { EuiStat } from '@elastic/eui';

import { AnalyticsCards } from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React from 'react';

import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiStat } from '@elastic/eui';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import { mockKibanaValues } from '../../../../__mocks__';

import React from 'react';

import { shallow } from 'enzyme';

import { Chart, Settings, LineSeries, Axis } from '@elastic/charts';

import { AnalyticsChart } from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
*/

import React from 'react';

import { useValues } from 'kea';

import moment from 'moment';

import { Chart, Settings, LineSeries, CurveType, Axis } from '@elastic/charts';

import { KibanaLogic } from '../../../../shared/kibana';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
import { setMockValues, mockKibanaValues } from '../../../../__mocks__';

import React, { ReactElement } from 'react';

import { shallow, ShallowWrapper } from 'enzyme';
import moment, { Moment } from 'moment';

import { EuiPageHeader, EuiSelect, EuiDatePickerRange, EuiButton } from '@elastic/eui';

import { LogRetentionTooltip } from '../../log_retention';

import { DEFAULT_START_DATE, DEFAULT_END_DATE } from '../constants';

import { AnalyticsHeader } from './';

describe('AnalyticsHeader', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import React, { useState } from 'react';
import { useValues } from 'kea';

import queryString from 'query-string';
import { useValues } from 'kea';
import moment from 'moment';
import queryString from 'query-string';

import { i18n } from '@kbn/i18n';
import {
EuiPageHeader,
EuiPageHeaderSection,
Expand All @@ -23,11 +22,12 @@ import {
EuiDatePicker,
EuiButton,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { AnalyticsLogic } from '../';
import { KibanaLogic } from '../../../../shared/kibana';
import { LogRetentionTooltip, LogRetentionOptions } from '../../log_retention';

import { AnalyticsLogic } from '../';
import { DEFAULT_START_DATE, DEFAULT_END_DATE, SERVER_DATE_FORMAT } from '../constants';
import { convertTagsToSelectOptions } from '../utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { mockKibanaValues } from '../../../../__mocks__';
import '../../../__mocks__/engine_logic.mock';

import React from 'react';

import { shallow } from 'enzyme';

import { EuiFieldSearch } from '@elastic/eui';

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

import React, { useState } from 'react';

import { useValues } from 'kea';

import { i18n } from '@kbn/i18n';
import { EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiButton, EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { KibanaLogic } from '../../../../shared/kibana';
import { ENGINE_ANALYTICS_QUERY_DETAIL_PATH } from '../../../routes';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React from 'react';

import { shallow } from 'enzyme';

import { AnalyticsSection } from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { mountWithIntl, mockKibanaValues } from '../../../../../__mocks__';
import '../../../../__mocks__/engine_logic.mock';

import React from 'react';

import { EuiBasicTable, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';

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

import React from 'react';
import { i18n } from '@kbn/i18n';

import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { Query } from '../../types';

import {
TERM_COLUMN_PROPS,
TAGS_COLUMN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

import React from 'react';

import { shallow } from 'enzyme';

import { EuiBadge, EuiToolTip } from '@elastic/eui';

import { InlineTagsList } from './inline_tags_list';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import React from 'react';
import { i18n } from '@kbn/i18n';

import { EuiBadgeGroup, EuiBadge, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { Query } from '../../types';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { mountWithIntl } from '../../../../../__mocks__';
import '../../../../__mocks__/engine_logic.mock';

import React from 'react';

import { EuiBasicTable, EuiLink, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';

import { QueryClicksTable } from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

import React from 'react';

import { i18n } from '@kbn/i18n';
import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { EuiLinkTo } from '../../../../../shared/react_router_helpers';
import { ENGINE_DOCUMENT_DETAIL_PATH } from '../../../../routes';
import { generateEnginePath } from '../../../engine';
import { DOCUMENTS_TITLE } from '../../../documents';
import { generateEnginePath } from '../../../engine';

import { QueryClick } from '../../types';

import { FIRST_COLUMN_PROPS, TAGS_COLUMN, COUNT_COLUMN_PROPS } from './shared_columns';

interface Props {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { mountWithIntl, mockKibanaValues } from '../../../../../__mocks__';
import '../../../../__mocks__/engine_logic.mock';

import React from 'react';

import { EuiBasicTable, EuiBadge, EuiEmptyPrompt } from '@elastic/eui';

import { RecentQueriesTable } from './';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import React from 'react';

import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedDate, FormattedTime } from '@kbn/i18n/react';
import { EuiBasicTable, EuiBasicTableColumn, EuiEmptyPrompt } from '@elastic/eui';

import { RecentQuery } from '../../types';

import {
TERM_COLUMN_PROPS,
TAGS_COLUMN,
Expand Down
Loading

0 comments on commit f339962

Please sign in to comment.