Skip to content

Commit

Permalink
lint import from restricted zones for export exressions (elastic#66588)
Browse files Browse the repository at this point in the history
* line restricted zones for export exressions

* more robust rule

* fix or mute eslint errors

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
mshustov and elasticmachine committed May 15, 2020
1 parent 38f469b commit 084275f
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,28 @@ ruleTester.run('@kbn/eslint/no-restricted-paths', rule, {
],

invalid: [
{
code: 'export { b } from "../server/b.js"',
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
options: [
{
basePath: __dirname,
zones: [
{
target: 'files/no_restricted_paths/client/**/*',
from: 'files/no_restricted_paths/server/**/*',
},
],
},
],
errors: [
{
message: 'Unexpected path "../server/b.js" imported in restricted zone.',
line: 1,
column: 19,
},
],
},
{
code: 'import b from "../server/b.js"',
filename: path.join(__dirname, './files/no_restricted_paths/client/a.js'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ module.exports = {
}

return {
ExportNamedDeclaration(node) {
if (!node.source) return;
checkForRestrictedImportPath(node.source.value, node.source);
},
ImportDeclaration(node) {
checkForRestrictedImportPath(node.source.value, node.source);
},
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
export {
ProcessedImportResponse,
processImportResponse,
} from '../../../../plugins/saved_objects_management/public/lib';
} from '../../../../plugins/saved_objects_management/public/lib'; // eslint-disable-line @kbn/eslint/no-restricted-paths
2 changes: 1 addition & 1 deletion src/legacy/ui/public/private/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { IPrivate } from '../../../../plugins/kibana_legacy/public/utils/private';
export { IPrivate } from '../../../../plugins/kibana_legacy/public/';
1 change: 1 addition & 0 deletions src/legacy/ui/public/url/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

export { KbnUrlProvider } from './url';
export { RedirectWhenMissingProvider } from './redirect_when_missing';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { modifyUrl } from '../../../../core/utils';
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
* under the License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { buildPipeline } from '../../../../../../plugins/visualizations/public/legacy/build_pipeline';
1 change: 1 addition & 0 deletions src/plugins/dashboard/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export { DashboardConstants, createDashboardEditUrl } from './dashboard_constant

export { DashboardStart, DashboardUrlGenerator } from './plugin';
export { DASHBOARD_APP_URL_GENERATOR } from './url_generator';
export { addEmbeddableToDashboardUrl } from './url_utils/url_helper';

export function plugin(initializerContext: PluginInitializerContext) {
return new DashboardPlugin(initializerContext);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/telemetry_management_section/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/

export { OptInExampleFlyout } from './components';
import { TelemetryManagementSectionPlugin } from './plugin';

export function plugin() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@

export { useVisualizeAppState } from './visualize_app_state';
export { makeStateful } from './make_stateful';
export { addEmbeddableToDashboardUrl } from '../../../../../dashboard/public/url_utils/url_helper';
export { addEmbeddableToDashboardUrl } from '../../../../../dashboard/public/';
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/maps/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ export const plugin = () => {
return new MapsPlugin();
};

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export {
RenderTooltipContentParams,
ITooltipProperty,
} from '../../../../plugins/maps/public/classes/tooltips/tooltip_property';
} from '../../../../plugins/maps/public/classes/tooltips/tooltip_property'; // eslint-disable-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { MapEmbeddable, MapEmbeddableInput } from '../../../../plugins/maps/public/embeddable';
2 changes: 2 additions & 0 deletions x-pack/legacy/plugins/xpack_main/public/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { LicenseStatus } from '../../../../../plugins/license_management/public/application/sections/license_dashboard/license_status/license_status';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { AddLicense } from '../../../../../plugins/license_management/public/application/sections/license_dashboard/add_license/add_license';

/*
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/case/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { UserRT } from '../user';
import { CommentResponseRt } from './comment';
import { CasesStatusResponseRt } from './status';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ActionTypeExecutorResult } from '../../../../actions/server/types';

const StatusRt = rt.union([rt.literal('open'), rt.literal('closed')]);
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/index_management/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export {
UseRequestConfig,
sendRequest,
useRequest,
} from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
} from '../../../../src/plugins/es_ui_shared/public/';

export {
FormSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

export { getFlattenedObject } from '../../../../../../../src/core/utils';
export { getFlattenedObject } from '../../../../../../../src/core/public';

export {
agentConfigRouteService,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/ingest_pipelines/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export {
UseRequestConfig,
sendRequest,
useRequest,
} from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
} from '../../../../src/plugins/es_ui_shared/public/';

export {
FormSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { TelemetryPluginSetup } from '../../../../../../src/plugins/telemetry/public';

export { OptInExampleFlyout } from '../../../../../../src/plugins/telemetry_management_section/public/components';
export { OptInExampleFlyout } from '../../../../../../src/plugins/telemetry_management_section/public/';
export { PRIVACY_STATEMENT_URL } from '../../../../../../src/plugins/telemetry/common/constants';
export { TelemetryPluginSetup, shouldShowTelemetryOptIn };

Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lists/common/siem_common_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { getPaths, foldLeftRight } from '../../siem/server/utils/build_validation/__mocks__/utils';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { exactCheck } from '../../siem/server/utils/build_validation/exact_check';
13 changes: 12 additions & 1 deletion x-pack/plugins/lists/server/siem_server_deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@
export {
transformError,
buildSiemResponse,
} from '../../siem/server/lib/detection_engine/routes/utils';
} from '../../siem/server/lib/detection_engine/routes/utils'; // eslint-disable-line @kbn/eslint/no-restricted-paths
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { deleteTemplate } from '../../siem/server/lib/detection_engine/index/delete_template';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { deletePolicy } from '../../siem/server/lib/detection_engine/index/delete_policy';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { deleteAllIndex } from '../../siem/server/lib/detection_engine/index/delete_all_index';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { setPolicy } from '../../siem/server/lib/detection_engine/index/set_policy';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { setTemplate } from '../../siem/server/lib/detection_engine/index/set_template';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { getTemplateExists } from '../../siem/server/lib/detection_engine/index/get_template_exists';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { getPolicyExists } from '../../siem/server/lib/detection_engine/index/get_policy_exists';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { createBootstrapIndex } from '../../siem/server/lib/detection_engine/index/create_bootstrap_index';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { getIndexExists } from '../../siem/server/lib/detection_engine/index/get_index_exists';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { buildRouteValidation } from '../../siem/server/utils/build_validation/route_validation';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { validate } from '../../siem/server/lib/detection_engine/routes/rules/validate';
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PluginInitializerContext, CoreStart } from 'kibana/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../src/plugins/navigation/public';
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { MonitoringConfig } from '../server';

export interface MonitoringPluginDependencies {
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/reporting/common/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* you may not use this file except in compliance with the Elastic License.
*/

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ConfigType } from '../server/config';
5 changes: 1 addition & 4 deletions x-pack/plugins/transform/public/shared_imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ export {
XJsonMode,
collapseLiteralStrings,
expandLiteralStrings,
} from '../../../../src/plugins/es_ui_shared/public';

export {
UseRequestConfig,
useRequest,
} from '../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
} from '../../../../src/plugins/es_ui_shared/public';

export {
getErrorMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export {
UseRequestConfig,
sendRequest,
useRequest,
} from '../../../../../src/plugins/es_ui_shared/public/request/np_ready_request';
} from '../../../../../src/plugins/es_ui_shared/public/';

export { useXJsonMode } from '../../../../../src/plugins/es_ui_shared/static/ace_x_json/hooks';

0 comments on commit 084275f

Please sign in to comment.