[eslint] add rule for auto-fixing unused imports (#131772)

* [eslint] add rule for auto-fixing unused imports

* [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'

* Update index_table.test.js

* Update follower_indices_list.test.js

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Spencer 2022-05-11 11:16:48 -05:00 committed by GitHub
parent ca0f874c2a
commit 67376ed53e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 360 additions and 148 deletions

View file

@ -196,5 +196,6 @@ module.exports = {
'@kbn/eslint/no_this_in_property_initializers': 'error',
'@kbn/imports/no_unresolvable_imports': 'error',
'@kbn/imports/uniform_imports': 'error',
'@kbn/imports/no_unused_imports': 'error',
},
};

View file

@ -53,4 +53,8 @@ Config example:
This config will find any import of `@kbn/kitchen-sink` which specifically references the `Spatula` or `isSpatula` exports, remove the old exports from the import (potentially removing the entire import), and add a new import after the previous following it's style pointing to the new package.
The auto-fixer here covers the vast majority of import styles in the repository but might not cover everything, including `import * as Namespace from '@kbn/kitchen-sink'`. Imports like this will need to be found and updated manually, though TypeScript should be able to find the vast majority of those.
The auto-fixer here covers the vast majority of import styles in the repository but might not cover everything, including `import * as Namespace from '@kbn/kitchen-sink'`. Imports like this will need to be found and updated manually, though TypeScript should be able to find the vast majority of those.
## `@kbn/imports/no_unused_imports`
This rule finds imports that are unused and provides an auto-fix to remove them. When ESLint appears to be running in an editor, as defined by [`helpers/running_in_editor.ts`](src/helpers/running_in_editor.ts), this rule provided suggestions instead of fixes so that the removals are not applied automatically in case you are debugging, returning early, or something else which makes ESLint think that the import is unused when it isn't. On CI and in the pre-commit hook though, this fix will be applied automatically.

View file

@ -7,7 +7,8 @@
*/
export const RUNNING_IN_EDITOR =
!process.env.IS_KIBANA_PRECOMIT_HOOK &&
// vscode sets this in the env for all workers
!!process.env.VSCODE_CWD ||
// MacOS sets this for intellij processes, not sure if it works in webstorm but we could expand this check later
!!process.env.__CFBundleIdentifier?.startsWith('com.jetbrains.intellij');
(!!process.env.VSCODE_CWD ||
// MacOS sets this for intellij processes, not sure if it works in webstorm but we could expand this check later
!!process.env.__CFBundleIdentifier?.startsWith('com.jetbrains.intellij'));

View file

@ -10,6 +10,7 @@ export * from './get_import_resolver';
import { NoUnresolvableImportsRule } from './rules/no_unresolvable_imports';
import { UniformImportsRule } from './rules/uniform_imports';
import { ExportsMovedPackagesRule } from './rules/exports_moved_packages';
import { NoUnusedImportsRule } from './rules/no_unused_imports';
/**
* Custom ESLint rules, add `'@kbn/eslint-plugin-imports'` to your eslint config to use them
@ -19,4 +20,5 @@ export const rules = {
no_unresolvable_imports: NoUnresolvableImportsRule,
uniform_imports: UniformImportsRule,
exports_moved_packages: ExportsMovedPackagesRule,
no_unused_imports: NoUnusedImportsRule,
};

View file

@ -0,0 +1,151 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { RuleTester } from 'eslint';
import { NoUnusedImportsRule } from './no_unused_imports';
import dedent from 'dedent';
const fmt = (str: TemplateStringsArray) => dedent(str) + '\n';
const tsTester = [
'@typescript-eslint/parser',
new RuleTester({
parser: require.resolve('@typescript-eslint/parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
ecmaFeatures: {
jsx: true,
},
},
}),
] as const;
const babelTester = [
'@babel/eslint-parser',
new RuleTester({
parser: require.resolve('@babel/eslint-parser'),
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
requireConfigFile: false,
babelOptions: {
presets: ['@kbn/babel-preset/node_preset'],
},
},
}),
] as const;
for (const [name, tester] of [tsTester, babelTester]) {
describe(name, () => {
tester.run('@kbn/imports/no_unused_imports', NoUnusedImportsRule, {
valid: [
{
filename: 'foo.ts',
code: fmt`
import { foo, bar as Bar } from 'new'
use(foo, Bar)
`,
},
{
filename: 'foo.ts',
code: fmt`
import Old from 'old'
use(Old)
`,
},
],
invalid: [
{
filename: 'foo.ts',
code: fmt`
import { foo, bar as Bar } from 'old'
`,
errors: [
{
line: 1,
message: 'All imports from "old" are unused and should be removed',
},
],
output: '',
},
{
filename: 'foo.ts',
code: fmt`
import type { foo, bar as Bar } from 'old'
`,
errors: [
{
line: 1,
message: 'All imports from "old" are unused and should be removed',
},
],
output: '',
},
{
filename: 'foo.ts',
code: fmt`
import type { foo, bar as Bar } from 'old'
use(foo)
`,
errors: [
{
line: 1,
message: 'Bar is unused and should be removed',
},
],
output: fmt`
import type { foo, } from 'old'
use(foo)
`,
},
{
filename: 'foo.ts',
code: fmt`
import type { foo, bar as Bar } from 'old'
use(Bar)
`,
errors: [
{
line: 1,
message: 'foo is unused and should be removed',
},
],
output: fmt`
import type { bar as Bar } from 'old'
use(Bar)
`,
},
{
filename: 'foo.ts',
code: fmt`
// @ts-expect-error
// @ts-ignore
// foo message
// eslint-disable-next-line some-other-rule
import type { foo, bar as Bar } from 'old'
`,
errors: [
{
line: 4,
message: `Definition for rule 'some-other-rule' was not found.`,
},
{
line: 5,
message: 'All imports from "old" are unused and should be removed',
},
],
output: fmt`
// foo message
`,
},
],
});
});
}

View file

@ -0,0 +1,184 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { Rule, Scope, AST } from 'eslint';
import type { Comment } from 'estree';
import * as T from '@babel/types';
import { TSESTree } from '@typescript-eslint/typescript-estree';
import { RUNNING_IN_EDITOR } from '../helpers/running_in_editor';
type WithParent<T> = T & { parent?: WithParent<T> };
type SomeNode = WithParent<T.Node> | TSESTree.Node;
type SomeImportNode = NonNullable<ReturnType<typeof findImportParent>>;
function findImportParent(def: Scope.Definition) {
let cursor: SomeNode | undefined = def.node;
while (cursor) {
if (
T.isImportDeclaration(cursor) ||
cursor.type === TSESTree.AST_NODE_TYPES.ImportDeclaration
) {
return cursor;
}
cursor = cursor.parent;
}
return;
}
function isEslintUsed(variable: any) {
return !!variable.eslintUsed;
}
function findUnusedImportDefs(globalScope: Scope.Scope) {
if (globalScope.type !== 'global') {
throw new Error('pass the global scope');
}
const unused = [];
for (const scope of globalScope.childScopes) {
if (scope.type !== 'module') {
continue;
}
for (const variable of scope.variables) {
if (variable.references.length > 0 || isEslintUsed(variable)) {
continue;
}
for (const def of variable.defs) {
const importParent = findImportParent(def);
if (importParent) {
unused.push({
def,
importParent,
});
}
}
}
}
return unused;
}
function isTsOrEslintIgnore(comment: Comment) {
const value = comment.value.trim();
return (
value.startsWith('@ts-ignore') ||
value.startsWith('@ts-expect-error') ||
value.startsWith('eslint-disable')
);
}
export const NoUnusedImportsRule: Rule.RuleModule = {
meta: {
fixable: 'code',
docs: {
url: 'https://github.com/elastic/kibana/blob/main/packages/kbn-eslint-plugin-imports/README.md#kbnimportsno_unused_imports',
},
},
create(context) {
const source = context.getSourceCode();
function getRange(
nodeA: { loc?: AST.SourceLocation | null },
nodeB: { loc?: AST.SourceLocation | null } | number = nodeA
): AST.Range {
if (!nodeA.loc) {
throw new Error('unable to use babel AST nodes without locations');
}
const nodeBLoc = typeof nodeB === 'number' ? nodeB : nodeB.loc;
if (nodeBLoc == null) {
throw new Error('unable to use babel AST nodes without locations');
}
return [
source.getIndexFromLoc(nodeA.loc.start),
typeof nodeBLoc === 'number'
? source.getIndexFromLoc(nodeA.loc.end) + nodeBLoc
: source.getIndexFromLoc(nodeBLoc.end),
];
}
function report(
node: SomeNode,
msg: string,
fix: (fixer: Rule.RuleFixer) => IterableIterator<Rule.Fix>
) {
context.report({
node: node as any,
message: msg,
...(RUNNING_IN_EDITOR
? {
suggest: [
{
desc: 'Remove',
fix,
},
],
}
: {
fix,
}),
});
}
return {
'Program:exit': () => {
const unusedByImport = new Map<SomeImportNode, Scope.Definition[]>();
for (const { importParent, def } of findUnusedImportDefs(context.getScope())) {
const group = unusedByImport.get(importParent);
if (group) {
group.push(def);
} else {
unusedByImport.set(importParent, [def]);
}
}
for (const [importParent, defs] of unusedByImport) {
if (importParent.specifiers.length === defs.length) {
report(
importParent,
`All imports from "${importParent.source.value}" are unused and should be removed`,
function* (fixer) {
// remove entire import including trailing newline if it's detected
const textPlus1 = source.getText(importParent as any, 0, 1);
const range = getRange(importParent, textPlus1.endsWith('\n') ? 1 : importParent);
// if the import is preceeded by one or more eslint/tslint disable comments then remove them
for (const comment of source.getCommentsBefore(importParent as any)) {
if (isTsOrEslintIgnore(comment)) {
const cRange = getRange(comment);
yield fixer.removeRange(
source.text[cRange[1]] !== '\n' ? cRange : getRange(comment, 1)
);
}
}
yield fixer.removeRange(range);
}
);
} else {
for (const def of defs) {
report(
def.node,
`${def.name.name} is unused and should be removed`,
function* (fixer) {
const nextToken = source.getTokenAfter(def.node);
yield fixer.removeRange(
getRange(def.node, nextToken?.value === ',' ? nextToken : undefined)
);
}
);
}
}
}
},
};
},
};

View file

@ -6,8 +6,6 @@
* Side Public License, v 1.
*/
// eslint-disable-next-line @kbn/eslint/module_migration
import { InjectedIntl as _InjectedIntl, InjectedIntlProps as _InjectedIntlProps } from 'react-intl';
// eslint-disable-next-line @kbn/eslint/module_migration
export type { InjectedIntl, InjectedIntlProps } from 'react-intl';

View file

@ -6,7 +6,7 @@
* Side Public License, v 1.
*/
import { Suite } from 'mocha';
import 'mocha';
declare module 'mocha' {
interface Suite {

View file

@ -12,9 +12,6 @@ import { join } from 'path';
import * as Rx from 'rxjs';
import { map, mergeAll, mergeMap } from 'rxjs/operators';
// @ts-ignore
import { assertAbsolute } from './fs';
const getStat$ = Rx.bindNodeCallback<[string], [Fs.Stats]>(Fs.stat);
const getReadDir$ = Rx.bindNodeCallback<[string], [string[]]>(Fs.readdir);

View file

@ -9,7 +9,7 @@
// @ts-ignore
import parser from 'intl-messageformat-parser';
// @ts-ignore
import { createParserErrorMessage, traverseNodes } from './utils';
import { createParserErrorMessage } from './utils';
import { SelectFormatNode } from './intl_types';
export function checkEnglishOnly(message: string) {

View file

@ -16,6 +16,8 @@ import { getFilesForCommit, checkFileCasing } from './precommit_hook';
run(
async ({ log, flags }) => {
process.env.IS_KIBANA_PRECOMIT_HOOK = 'true';
const files = await getFilesForCommit(flags.ref);
const errors = [];

View file

@ -6,8 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {
ViewMode,

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import { NotificationsStart } from '@kbn/core/public';
import { Action, IncompatibleActionError } from '../../services/ui_actions';
import {

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import React from 'react';
import ReactDOM from 'react-dom';
import { I18nProvider } from '@kbn/i18n-react';

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import { History } from 'history';
import { debounceTime, switchMap } from 'rxjs/operators';
import { useCallback, useEffect, useMemo, useState } from 'react';

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import type { KibanaExecutionContext } from '@kbn/core/public';
import { DashboardSavedObject } from '../../saved_dashboards';
import { DashboardContainer, DASHBOARD_CONTAINER_TYPE } from '../embeddable';

View file

@ -6,8 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import { getDashboard60Warning, dashboardLoadingErrorStrings } from '../../dashboard_strings';
import { savedObjectToDashboardState } from './convert_dashboard_state';
import { DashboardState, DashboardBuildContext } from '../../types';

View file

@ -7,7 +7,7 @@
*/
import moment from 'moment';
import _, { isArray } from 'lodash';
import { isArray } from 'lodash';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { RangeFilter } from '@kbn/es-query';

View file

@ -13,9 +13,6 @@ import { httpServiceMock } from '@kbn/core/public/mocks';
import { ImportSummary, ImportSummaryProps } from './import_summary';
import { FailedImport } from '../../../lib';
// @ts-expect-error
import { findTestSubject } from '@elastic/eui/lib/test';
describe('ImportSummary', () => {
let basePath: ReturnType<typeof httpServiceMock.createBasePath>;

View file

@ -6,7 +6,6 @@
* Side Public License, v 1.
*/
import _ from 'lodash';
import React from 'react';
import { IndexPatternsContract } from '@kbn/data-plugin/public';

View file

@ -6,8 +6,6 @@
* Side Public License, v 1.
*/
// @ts-ignore
import numeral from '@elastic/numeral';
import { getFormatService } from '../services';
export function getValueForPercentageMode(value: string | number, percentageFormatPattern: string) {

View file

@ -8,8 +8,6 @@
import { setTimeout as setTimeoutAsync } from 'timers/promises';
import expect from '@kbn/expect';
// @ts-ignore
import fetch from 'node-fetch';
import { getUrl } from '@kbn/test';
import moment from 'moment';
import { FtrService } from '../ftr_provider_context';

View file

@ -8,8 +8,6 @@
import { FtrService } from '../ftr_provider_context';
import { WebElementWrapper } from './lib/web_element_wrapper';
// @ts-ignore not supported yet
import { scrollIntoViewIfNecessary } from './lib/web_element_wrapper/scroll_into_view_if_necessary';
/**
* wrapper around EuiComboBox interactions

View file

@ -11,9 +11,6 @@ import {
} from '@kbn/expressions-plugin/common';
import { lastValueFrom } from 'rxjs';
// @ts-expect-error untyped local
import { buildESRequest } from '../../../common/lib/request/build_es_request';
import { searchService } from '../../../public/services';
import { ESSQL_SEARCH_STRATEGY } from '../../../common/lib/constants';
import { EssqlSearchStrategyRequest, EssqlSearchStrategyResponse } from '../../../types';

View file

@ -13,13 +13,9 @@ import { encode } from '@kbn/presentation-util-plugin/public';
import { findExistingAsset } from '../../lib/find_existing_asset';
import { VALID_IMAGE_TYPES } from '../../../common/lib/constants';
import { getId } from '../../lib/get_id';
// @ts-expect-error untyped local
import { elementsRegistry } from '../../lib/elements_registry';
// @ts-expect-error untyped local
import { addElement } from '../../state/actions/elements';
import { getAssets } from '../../state/selectors/assets';
// @ts-expect-error untyped local
import { removeAsset, createAsset } from '../../state/actions/assets';
import { createAsset } from '../../state/actions/assets';
import { State, AssetType } from '../../../types';
import { AssetManager as Component } from './asset_manager.component';

View file

@ -9,8 +9,6 @@ import { useCallback } from 'react';
import { useHistory } from 'react-router-dom';
import { i18n } from '@kbn/i18n';
// @ts-expect-error
import { getDefaultWorkpad } from '../../../state/defaults';
import { useNotifyService, useWorkpadService } from '../../../services';
import type { CanvasWorkpad } from '../../../../types';

View file

@ -6,8 +6,6 @@
*/
import React, { FC, useState } from 'react';
// @ts-expect-error untyped library
import Dropzone from 'react-dropzone';
import { useNotifyService } from '../../../services';
import { ErrorStrings } from '../../../../i18n';

View file

@ -7,8 +7,6 @@
import React, { FC } from 'react';
import { WorkpadFilters } from '../../workpad_filters';
// @ts-expect-error unconverted component
import { SidebarSection } from '../sidebar_section';
export const FilterConfig: FC = () => {
return <WorkpadFilters />;

View file

@ -20,8 +20,6 @@ import { crawlTree } from '../../workpad_page/integration_utils';
// @ts-expect-error untyped local
import { insertNodes, elementLayer, removeElements } from '../../../state/actions/elements';
// @ts-expect-error untyped local
import { undoHistory, redoHistory } from '../../../state/actions/history';
// @ts-expect-error untyped local
import { selectToplevelNodes } from '../../../state/actions/transient';
import {
getSelectedPage,

View file

@ -9,7 +9,7 @@ import moment from 'moment';
import { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
// @ts-expect-error
import { getDefaultWorkpad, getExportedWorkpad } from '../../state/defaults';
import { getDefaultWorkpad } from '../../state/defaults';
import { CanvasWorkpadService } from '../workpad';
import { CanvasTemplate, CanvasWorkpad } from '../../../types';

View file

@ -13,14 +13,9 @@ import { isFunction } from 'lodash';
import { EVENTS } from './constants';
// @ts-expect-error untyped local
import { resolvedArgs } from '../../../public/state/middleware/resolved_args';
// @ts-expect-error untyped local
import { getRootReducer } from '../../../public/state/reducers';
// @ts-expect-error Untyped local
import { getDefaultWorkpad } from '../../../public/state/defaults';
// @ts-expect-error Untyped local
import { getInitialState as getState } from '../../../public/state/initial_state';
import { State } from '../../../types';

View file

@ -11,8 +11,6 @@ import { Provider as ReduxProvider } from 'react-redux';
import { cloneDeep } from 'lodash';
import { set } from '@elastic/safer-lodash-set';
// @ts-expect-error Untyped local
import { getDefaultWorkpad } from '../../public/state/defaults';
import { CanvasWorkpad, CanvasElement, CanvasAsset, CanvasPage } from '../../types';
// @ts-expect-error untyped local

View file

@ -5,13 +5,6 @@
* 2.0.
*/
/**
* The below import is required to avoid a console error warn from brace package
* console.warn ../node_modules/brace/index.js:3999
Could not load worker ReferenceError: Worker is not defined
at createWorker (/<path-to-repo>/node_modules/brace/index.js:17992:5)
*/
import { stubWebWorker } from '@kbn/test-jest-helpers'; // eslint-disable-line no-unused-vars
import { act } from 'react-dom/test-utils';
import { getFollowerIndexMock } from './fixtures/follower_index';

View file

@ -5,7 +5,7 @@
* 2.0.
*/
import React, { PureComponent } from 'react'; // eslint-disable-line no-unused-vars
import { PureComponent } from 'react'; // eslint-disable-line no-unused-vars
import { loadRemoteClusters } from '../services/api';
export class RemoteClustersProvider extends PureComponent {

View file

@ -9,14 +9,7 @@ import React from 'react';
import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import { findTestSubject } from '@elastic/eui/lib/test';
/**
* The below import is required to avoid a console error warn from brace package
* console.warn ../node_modules/brace/index.js:3999
Could not load worker ReferenceError: Worker is not defined
at createWorker (/<path-to-repo>/node_modules/brace/index.js:17992:5)
*/
import { mountWithIntl, stubWebWorker } from '@kbn/test-jest-helpers'; // eslint-disable-line no-unused-vars
import { mountWithIntl } from '@kbn/test-jest-helpers'; // eslint-disable-line no-unused-vars
import { init as initHttpRequests } from '../client_integration/helpers/http_requests';
import { BASE_PATH } from '../../common/constants';

View file

@ -10,7 +10,7 @@
* package includes them.
*/
import { IconType, ToolTipPositions } from '@elastic/eui';
import { IconType } from '@elastic/eui';
import { CommonProps } from '@elastic/eui/src/components/common';
declare module '@elastic/eui' {

View file

@ -25,8 +25,6 @@ import {
import { PipelineList } from './components/pipeline_list';
import { PipelineEditView } from './pipeline_edit_view';
// @ts-ignore
import { Pipeline } from '../models/pipeline';
// @ts-ignore
import * as Breadcrumbs from './breadcrumbs';
export const renderApp = async (

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import React, { ChangeEvent, Component } from 'react';
import { EuiFieldNumber, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon } from '@elastic/eui';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import React from 'react';
import { EuiTextColor } from '@elastic/eui';
import type { Map as MbMap } from '@kbn/mapbox-gl';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import React, { CSSProperties, ReactElement } from 'react';
import { FeatureIdentifier, Map as MbMap } from '@kbn/mapbox-gl';
import { FeatureCollection } from 'geojson';
@ -27,7 +26,7 @@ import {
} from '../../../../common/constants';
import { StyleMeta } from './style_meta';
// @ts-expect-error
import { getMakiSymbol, PREFERRED_ICONS } from './symbol_utils';
import { getMakiSymbol } from './symbol_utils';
import { VectorIcon } from './components/legend/vector_icon';
import { VectorStyleLegend } from './components/legend/vector_style_legend';
import { getHasLabel } from './style_util';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import React, { Component } from 'react';
import classNames from 'classnames';
import { EuiFlexGroup, EuiFlexItem, EuiCallOut } from '@elastic/eui';

View file

@ -20,8 +20,6 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { DEFAULT_CUSTOM_ICON_CUTOFF, DEFAULT_CUSTOM_ICON_RADIUS } from '../../../common/constants';
import { getIsDarkMode } from '../../kibana_services';
// @ts-expect-error
import { getCustomIconId } from '../../classes/styles/vector/symbol_utils';
import { SymbolIcon } from '../../classes/styles/vector/components/legend/symbol_icon';
import { CustomIconModal } from '../../classes/styles/vector/components/symbol/custom_icon_modal';
import { CustomIcon } from '../../../common/descriptor_types';

View file

@ -9,7 +9,7 @@ import React, { FC, Fragment, useEffect, useState } from 'react';
import { EuiCallOut, EuiFormRow, EuiPanel, EuiSpacer, EuiText } from '@elastic/eui';
import { isEqual } from 'lodash';
// @ts-ignore no declaration
import { LEFT_ALIGNMENT, CENTER_ALIGNMENT, SortableProperties } from '@elastic/eui/lib/services';
import { LEFT_ALIGNMENT, SortableProperties } from '@elastic/eui/lib/services';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { FieldSelectionItem } from '../../../../common/analytics';

View file

@ -5,8 +5,6 @@
* 2.0.
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { TimeRange } from '@kbn/data-plugin/common/query/timefilter/types';
import { CombinedJob, Datafeed, Job } from '../../../common/types/anomaly_detection_jobs';
import { Calendar } from '../../../common/types/calendars';

View file

@ -6,7 +6,6 @@
*/
import { Moment } from 'moment';
import { UI_SETTINGS } from '@kbn/data-plugin/public';
export interface TimeRangeBounds {
min?: Moment;

View file

@ -6,9 +6,6 @@
*/
import { IScopedClusterClient } from '@kbn/core/server';
import { ES_AGGREGATION } from '../../../common/constants/aggregation_types';
import { RuntimeMappings } from '../../../common/types/fields';
import { IndicesOptions } from '../../../common/types/anomaly_detection_jobs';
import { BucketSpanEstimatorData } from '../../../common/types/job_service';
export function estimateBucketSpanFactory({

View file

@ -10,8 +10,6 @@ import { i18n } from '@kbn/i18n';
import { EuiContextMenu, EuiPopover, EuiBadge, EuiSwitch } from '@elastic/eui';
import { AlertState, CommonAlertStatus } from '../../common/types/alerts';
import { AlertSeverity } from '../../common/enums';
// @ts-ignore
import { formatDateTimeLocal } from '../../common/formatting';
import { isInSetupMode } from '../lib/setup_mode';
import { SetupModeContext } from '../components/setup_mode/setup_mode_context';
import { getAlertPanelsByCategory } from './lib/get_alert_panels_by_category';

View file

@ -20,8 +20,6 @@ import { useRouteMatch } from 'react-router-dom';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { GlobalStateContext } from '../../contexts/global_state_context';
import { ComponentProps } from '../../route_init';
// @ts-ignore
import { Listing } from '../../../components/logstash/listing';
import { LogstashTemplate } from './logstash_template';
// @ts-ignore
import { DetailStatus } from '../../../components/logstash/detail_status';

View file

@ -21,8 +21,6 @@ import { useKibana } from '@kbn/kibana-react-plugin/public';
import { GlobalStateContext } from '../../contexts/global_state_context';
import { ComponentProps } from '../../route_init';
// @ts-ignore
import { List } from '../../../components/logstash/pipeline_viewer/models/list';
// @ts-ignore
import { LogstashTemplate } from './logstash_template';
// @ts-ignore
import { DetailStatus } from '../../../components/logstash/detail_status';

View file

@ -13,13 +13,9 @@ import { useKibana } from '@kbn/kibana-react-plugin/public';
import { isPipelineMonitoringSupportedInVersion } from '../../../lib/logstash/pipelines';
import { GlobalStateContext } from '../../contexts/global_state_context';
import { ComponentProps } from '../../route_init';
// @ts-expect-error
import { Listing } from '../../../components/logstash/listing';
import { LogstashTemplate } from './logstash_template';
// @ts-expect-error
import { DetailStatus } from '../../../components/logstash/detail_status';
// @ts-expect-error
import { MonitoringTimeseriesContainer } from '../../../components/chart';
import { useTable } from '../../hooks/use_table';
// @ts-expect-error
import { PipelineListing } from '../../../components/logstash/pipeline_listing/pipeline_listing';

View file

@ -5,8 +5,6 @@
* 2.0.
*/
// @ts-ignore
import { checkParam } from '../error_missing_required';
import { STANDALONE_CLUSTER_CLUSTER_UUID } from '../../../common/constants';
import { ElasticsearchResponse } from '../../../common/types/es';
import { LegacyRequest, Cluster } from '../../types';

View file

@ -5,8 +5,6 @@
* 2.0.
*/
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { createQuery } from '../create_query';
// @ts-ignore

View file

@ -6,8 +6,6 @@
*/
import { find } from 'lodash';
// @ts-ignore
import { checkParam } from '../error_missing_required';
import { ElasticsearchResponse, ElasticsearchModifiedSource } from '../../../common/types/es';
import { LegacyRequest } from '../../types';
import { getNewIndexPatterns } from './get_index_patterns';

View file

@ -5,8 +5,6 @@
* 2.0.
*/
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { createQuery } from '../create_query';
// @ts-ignore

View file

@ -7,8 +7,6 @@
import moment from 'moment';
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { ElasticsearchMetric } from '../metrics';
// @ts-ignore
import { createQuery } from '../create_query';

View file

@ -8,8 +8,6 @@
import moment from 'moment';
import _ from 'lodash';
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { createQuery } from '../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../metrics';

View file

@ -7,8 +7,6 @@
import { includes } from 'lodash';
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { createQuery } from '../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../metrics';

View file

@ -8,8 +8,6 @@
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { checkParam } from '../../error_missing_required';
// @ts-ignore
import { createQuery } from '../../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../../metrics';

View file

@ -8,8 +8,6 @@
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { checkParam } from '../../error_missing_required';
// @ts-ignore
import { ElasticsearchMetric } from '../../metrics';
// @ts-ignore
import { createQuery } from '../../create_query';

View file

@ -7,8 +7,6 @@
import { i18n } from '@kbn/i18n';
// @ts-ignore
import { checkParam } from '../../error_missing_required';
// @ts-ignore
import { createQuery } from '../../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../../metrics';

View file

@ -7,8 +7,6 @@
import { get } from 'lodash';
// @ts-ignore
import { checkParam } from '../../error_missing_required';
// @ts-ignore
import { createQuery } from '../../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../../metrics';

View file

@ -7,8 +7,6 @@
import { get } from 'lodash';
// @ts-ignore
import { checkParam } from '../../error_missing_required';
// @ts-ignore
import { createQuery } from '../../create_query';
// @ts-ignore
import { ElasticsearchMetric } from '../../metrics';

View file

@ -5,8 +5,6 @@
* 2.0.
*/
// @ts-ignore
import { StringOptions } from '@kbn/config-schema/target_types/types';
// @ts-ignore
import { createQuery } from '../../create_query';
// @ts-ignore

View file

@ -7,7 +7,7 @@
import { merge } from 'lodash';
// @ts-ignore
import { checkParam, MissingRequiredError } from '../error_missing_required';
import { MissingRequiredError } from '../error_missing_required';
// @ts-ignore
import { calculateAvailability } from '../calculate_availability';
import { LegacyRequest } from '../../types';

View file

@ -7,8 +7,6 @@
import moment from 'moment';
// @ts-ignore
import { checkParam } from '../error_missing_required';
// @ts-ignore
import { createQuery } from '../create_query';
// @ts-ignore
import { calculateAvailability } from '../calculate_availability';

View file

@ -7,7 +7,6 @@
import { IRouter } from '@kbn/core/server';
import * as t from 'io-ts';
import { id as _id } from '@kbn/securitysolution-io-ts-list-types';
import { transformError } from '@kbn/securitysolution-es-utils';
import { buildRouteValidation } from './utils/route_validation';

View file

@ -7,7 +7,6 @@
import { IRouter } from '@kbn/core/server';
import * as t from 'io-ts';
import { id as _id } from '@kbn/securitysolution-io-ts-list-types';
import { transformError } from '@kbn/securitysolution-es-utils';
import { PositiveInteger } from '@kbn/securitysolution-io-ts-types';

View file

@ -7,7 +7,6 @@
import { IRouter } from '@kbn/core/server';
import * as t from 'io-ts';
import { id as _id } from '@kbn/securitysolution-io-ts-list-types';
import { transformError } from '@kbn/securitysolution-es-utils';
import { validFeatureIds } from '@kbn/rule-data-utils';
import { buildRouteValidation } from './utils/route_validation';

View file

@ -7,7 +7,6 @@
import { IRouter } from '@kbn/core/server';
import * as t from 'io-ts';
import { id as _id } from '@kbn/securitysolution-io-ts-list-types';
import { transformError } from '@kbn/securitysolution-es-utils';
import { buildRouteValidation } from './utils/route_validation';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { exportTimeline } from '../../tasks/timelines';
import { login, visitWithoutDateRange } from '../../tasks/login';
import {

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { exportTimeline } from '../../tasks/timelines';
import { login, visitWithoutDateRange } from '../../tasks/login';

View file

@ -14,7 +14,6 @@ import { TrustedAppsList } from './trusted_apps_list';
import { exceptionsListAllHttpMocks } from '../../mocks/exceptions_list_http_mocks';
import { SEARCHABLE_FIELDS } from '../constants';
import { parseQueryFilterToKQL } from '../../../common/utils';
import { useUserPrivileges as _useUserPrivileges } from '../../../../common/components/user_privileges';
jest.mock('../../../../common/components/user_privileges');

View file

@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import _ from 'lodash';
import memoizeOne from 'memoize-one';
import { useState, useEffect } from 'react';
import {

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { Subject } from 'rxjs';
import { TaskLifecycleEvent } from './polling_lifecycle';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { Subject, of, firstValueFrom } from 'rxjs';
import { fakeSchedulers } from 'rxjs-marbles/jest';
import { sleep } from '../test_utils';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { Subject, of, BehaviorSubject } from 'rxjs';
import { Option, none, some } from 'fp-ts/lib/Option';
import { createTaskPoller, PollingError, PollingErrorType } from './task_poller';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import sinon from 'sinon';
import { Observable, of, Subject } from 'rxjs';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import sinon from 'sinon';
import { shouldBeOneOf, mustBeAllOf } from './query_clauses';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { MustCondition, shouldBeOneOf, mustBeAllOf, matchesClauses } from './query_clauses';
describe('matchesClauses', () => {

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { Subject } from 'rxjs';
import { none, some } from 'fp-ts/lib/Option';

View file

@ -18,8 +18,6 @@ import {
EuiTabbedContent,
EuiText,
} from '@elastic/eui';
// @ts-ignore
import { RIGHT_ALIGNMENT, CENTER_ALIGNMENT } from '@elastic/eui/lib/services';
import { FormattedMessage } from '@kbn/i18n-react';
import moment from 'moment';
import {

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { deprecationsServiceMock } from '@kbn/core/server/mocks';
import { DomainDeprecationDetails } from '@kbn/core/server/types';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import { FtrService } from '../ftr_provider_context';
export class GeoFileUploadPageObject extends FtrService {

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import expect from '@kbn/expect';
import url from 'url';
import supertest from 'supertest';

View file

@ -5,7 +5,6 @@
* 2.0.
*/
import _ from 'lodash';
import expect from '@kbn/expect';
import { firstNonNullValue } from '@kbn/security-solution-plugin/common/endpoint/models/ecs_safety_helpers';
import { NodeID } from '@kbn/security-solution-plugin/server/endpoint/routes/resolver/tree/utils';