Skip to content

Commit

Permalink
[presUtils/fleet] stop importing test helpers in bundles (elastic#148825
Browse files Browse the repository at this point in the history
)

This PR stops importing:
- `functionWrapper` and `fontStyle` test helpers in
`@kbn/presentation-util-plugin/common`
 - `createFleetAuthzMock` test helper in `@kbn/fleet-plugin/common`

These are instead imported from a `*/mocks` or `*/test_helpers` import
target and the related `eslint-disable` comments were removed.

While working through some changes to the package system I fixed a bug
in the source classifier which made these issues clear and made a fix
required. The changes have been broken out of my massive PR to make
review simpler.
  • Loading branch information
Spencer authored and jennypavlova committed Jan 13, 2023
1 parent c4c4d05 commit 9387913
Show file tree
Hide file tree
Showing 71 changed files with 112 additions and 110 deletions.
61 changes: 38 additions & 23 deletions packages/kbn-eslint-config/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ module.exports = {
/**
* ESLint rule to aid with breaking up packages:
*
* `fromPacakge` the package name which was broken up
* `toPackage` the package where the removed exports were placed
* `exportNames` the list of exports which used to be found in `fromPacakge` and are now found in `toPackage`
* `from` the package/request where the exports used to be
* `to` the package/request where the exports are now
* `exportNames` the list of exports which used to be found in `from` and are now found in `to`
*
* TODO(@spalger): once packages have types we should be able to filter this rule based on the package type
* of the file being linted so that we could re-route imports from `plugin-client` types to a different package
* than `plugin-server` types.
*/
'@kbn/imports/exports_moved_packages': ['error', [
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/tooling-log',
from: '@kbn/dev-utils',
to: '@kbn/tooling-log',
exportNames: [
'DEFAULT_LOG_LEVEL',
'getLogLevelFlagsHelp',
Expand All @@ -171,8 +171,8 @@ module.exports = {
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/ci-stats-reporter',
from: '@kbn/dev-utils',
to: '@kbn/ci-stats-reporter',
exportNames: [
'CiStatsMetric',
'CiStatsReporter',
Expand All @@ -188,15 +188,15 @@ module.exports = {
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/ci-stats-core',
from: '@kbn/dev-utils',
to: '@kbn/ci-stats-core',
exportNames: [
'Config',
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/jest-serializers',
from: '@kbn/dev-utils',
to: '@kbn/jest-serializers',
exportNames: [
'createAbsolutePathSerializer',
'createStripAnsiSerializer',
Expand All @@ -206,23 +206,23 @@ module.exports = {
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/stdio-dev-helpers',
from: '@kbn/dev-utils',
to: '@kbn/stdio-dev-helpers',
exportNames: [
'observeReadable',
'observeLines',
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/sort-package-json',
from: '@kbn/dev-utils',
to: '@kbn/sort-package-json',
exportNames: [
'sortPackageJson',
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/dev-cli-runner',
from: '@kbn/dev-utils',
to: '@kbn/dev-cli-runner',
exportNames: [
'run',
'Command',
Expand All @@ -242,25 +242,25 @@ module.exports = {
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/dev-cli-errors',
from: '@kbn/dev-utils',
to: '@kbn/dev-cli-errors',
exportNames: [
'createFailError',
'createFlagError',
'isFailError',
]
},
{
fromPackage: '@kbn/dev-utils',
toPackage: '@kbn/dev-proc-runner',
from: '@kbn/dev-utils',
to: '@kbn/dev-proc-runner',
exportNames: [
'withProcRunner',
'ProcRunner',
]
},
{
fromPackage: '@kbn/utils',
toPackage: '@kbn/repo-info',
from: '@kbn/utils',
to: '@kbn/repo-info',
exportNames: [
'REPO_ROOT',
'UPSTREAM_BRANCH',
Expand All @@ -269,6 +269,21 @@ module.exports = {
'fromRoot',
]
},
{
from: '@kbn/presentation-util-plugin/common',
to: '@kbn/presentation-util-plugin/test_helpers',
exportNames: [
'functionWrapper',
'fontStyle'
]
},
{
from: '@kbn/fleet-plugin/common',
to: '@kbn/fleet-plugin/common/mocks',
exportNames: [
'createFleetAuthzMock'
]
}
]],

'@kbn/disable/no_protected_eslint_disable': 'error',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { RUNNING_IN_EDITOR } from './helpers/running_in_editor';
let importResolverCache: ImportResolver | undefined;

/**
* Create a request resolver for ESLint, requires a PluginPackageResolver from @kbn/bazel-packages which will
* Create a request resolver for ESLint, requires a PluginPackageResolver from @kbn/repo-packages which will
* be created and cached on contextServices automatically.
*
* All import requests in the repository should return a result, if they don't it's a bug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ const OPTIONS: MovedExportsRule[][] = [
[
{
exportNames: ['foo', 'bar'],
fromPackage: 'old',
toPackage: 'new',
from: 'old',
to: 'new',
},
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { TSESTree } from '@typescript-eslint/typescript-estree';
import { visitAllImportStatements, Importer } from '../helpers/visit_all_import_statements';

export interface MovedExportsRule {
fromPackage: string;
toPackage: string;
from: string;
to: string;
exportNames: string[];
}

Expand Down Expand Up @@ -71,7 +71,7 @@ function getBadImports(imported: Imported[], rules: MovedExportsRule[]): BadImpo
node: i.node,
id: i.id,
name: i.name,
newPkg: match.toPackage,
newPkg: match.to,
};
});
}
Expand Down Expand Up @@ -203,10 +203,10 @@ export const ExportsMovedPackagesRule: Rule.RuleModule = {
items: {
type: 'object',
properties: {
fromPackage: {
from: {
type: 'string',
},
toPackage: {
to: {
type: 'string',
},
exportNames: {
Expand Down Expand Up @@ -268,7 +268,7 @@ export const ExportsMovedPackagesRule: Rule.RuleModule = {
return;
}

const rulesForRightPackage = rules.filter((m) => m.fromPackage === req);
const rulesForRightPackage = rules.filter((m) => m.from === req);
if (!rulesForRightPackage.length) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

import expect from '@kbn/expect';
import { ExecutionContext } from '@kbn/expressions-plugin/common';
import {
functionWrapper,
getElasticLogo,
getElasticOutline,
} from '@kbn/presentation-util-plugin/common';
import { getElasticLogo, getElasticOutline } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { imageFunction as image } from './image_function';

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

import { ExecutionContext } from '@kbn/expressions-plugin/common';
import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/common';
import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/test_helpers';
import { metricFunction } from './metric_function';

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

import { ExecutionContext } from '@kbn/expressions-plugin/common';
import {
getElasticLogo,
getElasticOutline,
functionWrapper,
} from '@kbn/presentation-util-plugin/common';
import { getElasticLogo, getElasticOutline } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { repeatImageFunction } from './repeat_image_function';

describe('repeatImage', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@
* Side Public License, v 1.
*/

import {
functionWrapper,
getElasticOutline,
getElasticLogo,
} from '@kbn/presentation-util-plugin/common';
import { getElasticOutline, getElasticLogo } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { revealImageFunction, errors } from './reveal_image_function';
import { Origin } from '../types';
import { ExecutionContext } from '@kbn/expressions-plugin/common';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import { ExecutionContext } from '@kbn/expressions-plugin/common';
import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/common';
import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/test_helpers';
import { progressFunction, errors } from './progress_function';

describe('progress', () => {
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/presentation_util/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export {
export {
defaultTheme$,
getElasticLogo,
fontStyle,
functionWrapper,
getElasticOutline,
isValidUrl,
resolveWithMissingImage,
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/presentation_util/common/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@
*/

export * from './utils';
// eslint-disable-next-line @kbn/imports/no_boundary_crossing
export * from './test_helpers';
1 change: 1 addition & 0 deletions src/plugins/presentation_util/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"public/**/*",
"public/**/*.json",
"server/**/*",
"test_helpers/**/*",
"storybook/**/*",
"../../../typings/**/*"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/common';
import { functionWrapper, fontStyle } from '@kbn/presentation-util-plugin/test_helpers';
import { testTable } from '../common/__fixtures__/test_tables';
import { markdown } from './markdown';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { all } from './all';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { getFunctionErrors } from '../../../i18n';
import { emptyTable, testTable } from './__fixtures__/test_tables';
import { alterColumn } from './alterColumn';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { any } from './any';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { asFn } from './as';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { getFunctionErrors } from '../../../i18n';
import { testTable } from './__fixtures__/test_tables';
import { axisConfig } from './axisConfig';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { of } from 'rxjs';
import { TestScheduler } from 'rxjs/testing';
import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { caseFn } from './case';

describe('case', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { testTable } from './__fixtures__/test_tables';
import { clear } from './clear';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { emptyTable, testTable } from './__fixtures__/test_tables';
import { columns } from './columns';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { getFunctionErrors } from '../../../i18n';
import { compare } from './compare';

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

import { functionWrapper, getElasticLogo } from '@kbn/presentation-util-plugin/common';
import { getElasticLogo } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { getFunctionErrors } from '../../../i18n';
import { containerStyle } from './containerStyle';

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

import { functionWrapper } from '@kbn/presentation-util-plugin/common';
import { functionWrapper } from '@kbn/presentation-util-plugin/test_helpers';
import { testTable, emptyTable } from './__fixtures__/test_tables';
import { context } from './context';

Expand Down
Loading

0 comments on commit 9387913

Please sign in to comment.