Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix no-restricted-imports #195456

Merged
merged 19 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1007,6 +1007,7 @@ module.exports = {
'error',
{
patterns: ['**/legacy_uptime/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1048,6 +1049,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1106,6 +1108,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1177,13 +1180,7 @@ module.exports = {
// to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are
// finding yourself turning this off a lot for "new code" consider renaming the file and functions if it is has valid uses.
patterns: ['*legacy*'],
paths: [
{
name: 'react-router-dom',
importNames: ['Route'],
message: "import { Route } from '@kbn/kibana-react-plugin/public'",
},
],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1341,6 +1338,7 @@ module.exports = {
{
// prevents UI code from importing server side code and then webpack including it when doing builds
patterns: ['**/server/*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down Expand Up @@ -1518,6 +1516,7 @@ module.exports = {
// to help deprecation and prevent accidental re-use/continued use of code we plan on removing. If you are
// finding yourself turning this off a lot for "new code" consider renaming the file and functions if it has valid uses.
patterns: ['*legacy*'],
paths: RESTRICTED_IMPORTS,
},
],
},
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,8 @@ x-pack/test_serverless/**/test_suites/observability/ai_assistant @elastic/obs-ai
/x-pack/dev-tools @elastic/kibana-operations
/catalog-info.yaml @elastic/kibana-operations @elastic/kibana-tech-leads
/.devcontainer/ @elastic/kibana-operations
/.eslintrc.js @elastic/kibana-operations
/.eslintignore @elastic/kibana-operations

# Appex QA
/x-pack/test_serverless/tsconfig.json @elastic/appex-qa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { useLoadConnectors } from '../connectorland/use_load_connectors';

import { DefinedUseQueryResult, UseQueryResult } from '@tanstack/react-query';

import { useLocalStorage, useSessionStorage } from 'react-use';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import useSessionStorage from 'react-use/lib/useSessionStorage';
import { QuickPrompts } from './quick_prompts/quick_prompts';
import { mockAssistantAvailability, TestProviders } from '../mock/test_providers/test_providers';
import { useFetchCurrentUserConversations } from './api';
Expand All @@ -27,7 +28,8 @@ import { omit } from 'lodash';

jest.mock('../connectorland/use_load_connectors');
jest.mock('../connectorland/connector_setup');
jest.mock('react-use');
jest.mock('react-use/lib/useLocalStorage');
jest.mock('react-use/lib/useSessionStorage');

jest.mock('./quick_prompts/quick_prompts', () => ({ QuickPrompts: jest.fn() }));
jest.mock('./api/conversations/use_fetch_current_user_conversations');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ const testTitle = 'SPL_QUERY_CONVERSION_TITLE';
const testPrompt = 'SPL_QUERY_CONVERSION_PROMPT';
const customTitle = 'A_CUSTOM_OPTION';

jest.mock('react-use', () => ({
...jest.requireActual('react-use'),
useMeasure: () => [
() => {},
{
width: 500,
},
],
}));
jest.mock('react-use/lib/useMeasure', () => () => [
() => {},
{
width: 500,
},
]);

jest.mock('../../assistant_context', () => ({
...jest.requireActual('../../assistant_context'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
EuiButtonIcon,
EuiButtonEmpty,
} from '@elastic/eui';
import { useMeasure } from 'react-use';
import useMeasure from 'react-use/lib/useMeasure';

import { css } from '@emotion/react';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import { renderHook } from '@testing-library/react-hooks';

import { useAssistantContext } from '.';
import { useLocalStorage } from 'react-use';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { TestProviders } from '../mock/test_providers/test_providers';

jest.mock('react-use', () => ({
useLocalStorage: jest.fn().mockReturnValue(['456', jest.fn()]),
useSessionStorage: jest.fn().mockReturnValue(['456', jest.fn()]),
}));
jest.mock('react-use/lib/useLocalStorage', () => jest.fn().mockReturnValue(['456', jest.fn()]));
jest.mock('react-use/lib/useSessionStorage', () => jest.fn().mockReturnValue(['456', jest.fn()]));

describe('AssistantContext', () => {
beforeEach(() => jest.clearAllMocks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { omit } from 'lodash/fp';
import React, { useCallback, useMemo, useState, useRef } from 'react';
import type { IToasts } from '@kbn/core-notifications-browser';
import { ActionTypeRegistryContract } from '@kbn/triggers-actions-ui-plugin/public';
import { useLocalStorage, useSessionStorage } from 'react-use';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import useSessionStorage from 'react-use/lib/useSessionStorage';
import type { DocLinksStart } from '@kbn/core-doc-links-browser';
import { AssistantFeatures, defaultAssistantFeatures } from '@kbn/elastic-assistant-common';
import { NavigateToAppOptions } from '@kbn/core/public';
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/common/types/domain/user/v1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { set } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { UserRt, UserWithProfileInfoRt, UsersRt, CaseUserProfileRt, CaseAssigneesRt } from './v1';

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

import { set } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import React from 'react';
import { screen } from '@testing-library/react';
import type { AppMockRenderer } from '../../common/mock';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { loggingSystemMock } from '@kbn/core-logging-server-mocks';

import { CasesOracleService } from './cases_oracle_service';
import { CASE_RULES_SAVED_OBJECT } from '../../../common/constants';
import { isEmpty, set } from 'lodash';
import { isEmpty } from 'lodash';
import { set } from '@kbn/safer-lodash-set';

describe('CasesOracleService', () => {
const savedObjectsClient = savedObjectsClientMock.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
import { createHash } from 'node:crypto';
import stringify from 'json-stable-stringify';

import { isEmpty, set } from 'lodash';
import { isEmpty } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { CasesService } from './cases_service';

describe('CasesService', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { set, omit, unset } from 'lodash';
import { omit, unset } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { loggerMock } from '@kbn/logging-mocks';
import { savedObjectsClientMock } from '@kbn/core/server/mocks';
import type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { createSavedObjectsSerializerMock } from '../../../client/mocks';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import { loggerMock } from '@kbn/logging-mocks';
import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks';
import { set, unset } from 'lodash';
import { unset } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { createConnectorObject } from '../../test_utils';
import { UserActionPersister } from './create';
import { createUserActionSO } from '../test_utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useMemo } from 'react';
import { useObservable } from 'react-use';
import useObservable from 'react-use/lib/useObservable';
import { MINIMUM_LICENSE_TYPE } from '../../../common/constants';
import { useKibana } from './use_kibana';
import type { RenderUpselling } from '../../services';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/
import React from 'react';
import { Redirect, Switch } from 'react-router-dom';
import { Route } from '@kbn/shared-ux-router';
import { Redirect } from 'react-router-dom';
import { Route, Routes } from '@kbn/shared-ux-router';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { Services } from '../../services';
import { TelemetryContextProvider } from './telemetry';
Expand All @@ -33,7 +33,7 @@ const CreateIntegrationRouter = React.memo(() => {
const { canUseIntegrationAssistant, canUseIntegrationUpload } = useRoutesAuthorization();
const isAvailable = useIsAvailable();
return (
<Switch>
<Routes>
{isAvailable && canUseIntegrationAssistant && (
<Route path={PagePath[Page.assistant]} exact component={CreateIntegrationAssistant} />
)}
Expand All @@ -44,7 +44,7 @@ const CreateIntegrationRouter = React.memo(() => {
<Route path={PagePath[Page.landing]} exact component={CreateIntegrationLanding} />

<Route render={() => <Redirect to={PagePath[Page.landing]} />} />
</Switch>
</Routes>
);
});
CreateIntegrationRouter.displayName = 'CreateIntegrationRouter';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useDispatch, useSelector } from 'react-redux';
import { EuiButton, EuiButtonEmpty, EuiCallOut, EuiMarkdownFormat, EuiSpacer } from '@elastic/eui';
import { syntheticsSettingsLocatorID } from '@kbn/observability-plugin/common';
import { useFetcher } from '@kbn/observability-shared-plugin/public';
import { useSessionStorage } from 'react-use';
import useSessionStorage from 'react-use/lib/useSessionStorage';
import { i18n } from '@kbn/i18n';
import { isEmpty } from 'lodash';
import { useKibana } from '@kbn/kibana-react-plugin/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { useCallback, useState } from 'react';
import { EuiFormRow, EuiFormRowProps } from '@elastic/eui';
import { useSelector } from 'react-redux';
import { useDebounce } from 'react-use';
import useDebounce from 'react-use/lib/useDebounce';
import { ControllerRenderProps, ControllerFieldState, useFormContext } from 'react-hook-form';
import { useKibanaSpace, useIsEditFlow } from '../hooks';
import { selectServiceLocationsState } from '../../../state';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useCallback, useEffect, useMemo, useState } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { useDebounce } from 'react-use';
import useDebounce from 'react-use/lib/useDebounce';
import { useLocation } from 'react-router-dom';

import { useSyntheticsRefreshContext } from '../../../contexts/synthetics_refresh_context';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useCallback, useEffect, useRef } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { useDebounce } from 'react-use';
import useDebounce from 'react-use/lib/useDebounce';
import { useMonitorFiltersState } from '../common/monitor_filters/use_filters';
import {
fetchMonitorListAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import React, { useState } from 'react';
import { i18n } from '@kbn/i18n';
import { useSelector } from 'react-redux';
import { useKey } from 'react-use';
import useKey from 'react-use/lib/useKey';
import { FlyoutParamProps } from '../types';
import { OverviewLoader } from '../overview_loader';
import { useFilteredGroupMonitors } from './use_filtered_group_monitors';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/basic_table';
import { useDebounce } from 'react-use';
import useDebounce from 'react-use/lib/useDebounce';
import { TableTitle } from '../../common/components/table_title';
import { ParamsText } from './params_text';
import { SyntheticsParams } from '../../../../../../common/runtime_types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React, {
FC,
} from 'react';
import useLocalStorage from 'react-use/lib/useLocalStorage';
import { useEvent } from 'react-use';
import useEvent from 'react-use/lib/useEvent';
import moment from 'moment';
import { Subject } from 'rxjs';
import { i18n } from '@kbn/i18n';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ChromeBreadcrumb } from '@kbn/core/public';
import { render } from '../utils/testing';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Route } from 'react-router-dom';
import { Route } from '@kbn/shared-ux-router';
import { OVERVIEW_ROUTE } from '../../../../common/constants';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { useMemo, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useDebounce } from 'react-use';
import useDebounce from 'react-use/lib/useDebounce';
import { useFetcher } from '@kbn/observability-shared-plugin/public';

import { fetchMonitorManagementList, getMonitorListPageStateWithDefaults } from '../state';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import moment from 'moment';
import { Moment } from 'moment-timezone';
import * as redux from 'react-redux';
// eslint-disable-next-line no-restricted-imports
import * as reactRouterDom from 'react-router-dom';

export function mockMoment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
/* eslint-disable max-classes-per-file */

import type { DeepPartial } from 'utility-types';
import { merge, set } from 'lodash';
import { merge } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { gte } from 'semver';
import type { EndpointCapabilities } from '../service/response_actions/constants';
import { BaseDataGenerator } from './base_data_generator';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import {
checkIfPopupMessagesContainCustomNotifications,
resetCustomNotifications,
} from './policy_config_helpers';
import { get, merge, set } from 'lodash';
import { get, merge } from 'lodash';
import { set } from '@kbn/safer-lodash-set';

describe('Policy Config helpers', () => {
describe('disableProtections', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { get, set } from 'lodash';
import { get } from 'lodash';
import { set } from '@kbn/safer-lodash-set';
import { DefaultPolicyNotificationMessage } from './policy_config';
import type { PolicyConfig } from '../types';
import { PolicyOperatingSystem, ProtectionModes, AntivirusRegistrationModes } from '../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* 2.0.
*/

import { merge, setWith } from 'lodash';
import { merge } from 'lodash';
import { setWith } from '@kbn/safer-lodash-set';

/*
* Expands an object with "dotted" fields to a nested object with unflattened fields.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { createAddToTimelineCellActionFactory } from './add_to_timeline';
import type { CellActionExecutionContext } from '@kbn/cell-actions';
import { GEO_FIELD_TYPE } from '../../../../timelines/components/timeline/body/renderers/constants';
import { createStartServicesMock } from '../../../../common/lib/kibana/kibana_react.mock';
import { set } from 'lodash/fp';
import { set } from '@kbn/safer-lodash-set/fp';
import { KBN_FIELD_TYPES } from '@kbn/field-types';

const services = createStartServicesMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ const data = {

const mockUseObservable = jest.fn();

jest.mock('react-use', () => ({
...jest.requireActual('react-use'),
useObservable: () => mockUseObservable(),
}));
jest.mock('react-use/lib/useObservable', () => () => mockUseObservable());

jest.mock('../../../common/lib/kibana', () => {
const original = jest.requireActual('../../../common/lib/kibana');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useCallback } from 'react';
import { EuiWrappingPopover } from '@elastic/eui';
import { useLocation } from 'react-router-dom';
import { useObservable } from 'react-use';
import useObservable from 'react-use/lib/useObservable';
import { StatefulTopN } from '../../../common/components/top_n';
import { getScopeFromPath } from '../../../sourcerer/containers/sourcerer_paths';
import { useSourcererDataView } from '../../../sourcerer/containers';
Expand Down
Loading