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

[New platform] Restrict import internals of plugins & core services in ts files #33562

Closed

Conversation

mshustov
Copy link
Contributor

@mshustov mshustov commented Mar 20, 2019

Summary

Issue #33444
The full description is in the issue.
Added import-zones rule for tslint restricting import from core and plugins sub-folders.
Although, import restriction shouldn't be applied to the same folder, descendent folders, so I have to enhance import-zones with this functionality. Also we are in process of migration from tslint to eslint, until this process is done I put the PR on hold. Afterwards this plugin will be ported to eslint

Blocked by #33826

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@mshustov mshustov added Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc Feature:New Platform v7.2.0 labels Mar 20, 2019
@mshustov mshustov requested a review from a team March 20, 2019 10:38
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-platform

src/core/public/index.ts Outdated Show resolved Hide resolved
@@ -18,6 +18,7 @@
*/

import Hapi from 'hapi';
// tslint:disable-next-line:no-import-zones
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we provide server factory / builder for testing purposes?
similar test https://github.com/elastic/kibana/blob/master/x-pack/plugins/security/server/routes/api/public/roles/put.test.js

@elasticmachine

This comment has been minimized.

Copy link
Contributor

@rudolf rudolf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-import-zones seems really powerful 👍

I've made some comments about how we choose to expose types, but that's perhaps a meta issues that doesn't have to block this PR.

src/legacy/ui/public/chrome/api/theme.ts Outdated Show resolved Hide resolved
src/core/public/index.ts Outdated Show resolved Hide resolved
@mshustov mshustov added the non-issue Indicates to automation that a pull request should not appear in the release notes label Mar 20, 2019
@mshustov
Copy link
Contributor Author

mshustov commented Mar 20, 2019

I just realised that plugins still can import from sibling folders.
the current setup:

  - target: src/plugins/**/public/**/*
    from:
      - src/core/server/**/*
      - src/core/public/**/*
      - src/plugins/**/server/**/*

src/plugins/a/public/internal.ts can import from src/plugins/b/public/internal.ts 😞
What we want here - import restriction shouldn't be applied to the same folder, descendent folders
I will take a look if I can enhance tslint plugin, because I don't want to write custom one.

const { findImports, ImportKind } = require('tsutils');

function traverseToTopFolder(src, pattern) {
while(src && mm([src], pattern).length) {
Copy link
Contributor Author

@mshustov mshustov Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's okay to have a local fork of the no-import-zones rule, we can port some logic to eslint as well (if we want ofc).
the only problem that I see right now - we don't have tests and it's not in written in ts anymore.

@mshustov mshustov removed the review label Mar 21, 2019
@mshustov mshustov changed the title [New platform] Restrict import internals of plugins & core services in ts files WIP [New platform] Restrict import internals of plugins & core services in ts files Mar 21, 2019
@elasticmachine

This comment has been minimized.

@mshustov mshustov force-pushed the issue-33444-restrict-imports-tslint branch 2 times, most recently from 24eb4c7 to d939b45 Compare March 21, 2019 12:17
@mshustov mshustov changed the title WIP [New platform] Restrict import internals of plugins & core services in ts files [New platform] Restrict import internals of plugins & core services in ts files Mar 21, 2019

let newPlatformInjectedVars: InjectedMetadataStart;
let newPlatformInjectedVars: InjectedMetadata.InjectedMetadataStart;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with having domain name as a prefix for start contract, it's useful for manual search

@mshustov mshustov requested a review from rudolf March 21, 2019 12:22
InjectedMetadataParams,
InjectedMetadataStart,
} from './injected_metadata_service';
export * from './injected_metadata_service';
Copy link
Contributor Author

@mshustov mshustov Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made changes to improve "Go to definition" work. Otherwise, ts resolves this place as a definition. Potential problem: we don't see what file exports. Sometimes it can export some functionality only for testing, which is also bad imho (because it's not public interface).

@elasticmachine

This comment has been minimized.

@mshustov mshustov force-pushed the issue-33444-restrict-imports-tslint branch from d939b45 to 2fbfd00 Compare March 21, 2019 13:51
* under the License.
*/

/* @notice
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do when use software licensed under MIT? Included a note as per https://github.com/elastic/kibana/blob/master/webpackShims/childnode-remove-polyfill.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how we comply with The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software., but you should include /* eslint-disable @kbn/license-header/require-license-header */ too, since this isn't Apache 2.0 code.

Copy link
Contributor Author

@mshustov mshustov Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this isn't Apache 2.0 code.

you mean only this file is not Apache 2.0 anymore because of MIT license? or it's not needed to be licensed under Apache 2.0 at all?

Copy link
Contributor

@spalger spalger Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean only this file is not Apache 2.0 anymore because of MIT license?

correct

@elasticmachine

This comment has been minimized.

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@mshustov mshustov requested a review from a team March 21, 2019 15:38
@eliperelman eliperelman requested a review from a team March 21, 2019 16:20
@eliperelman
Copy link
Contributor

Adding @elastic/kibana-operations to evaluate tslint rule.

@mistic
Copy link
Member

mistic commented Mar 21, 2019

@restrry I'm working on this branch https://github.com/mistic/kibana/tree/migrate-from-tslint
in order to move away from tslint to eslint over all the project and it is almost done. I'm just working in the last part of solving some rules problems. Do you think it is viable to port that rule to an eslint based one and hold this PR until we move ?

@mshustov
Copy link
Contributor Author

mshustov commented Mar 21, 2019

@mistic ok, sounds good 👍
would you mind pinging me when you are ready for review and I can start porting rule to eslint?
also may I ask you sent a draft PR? I can declare explicitly that the current one is blocked by it.

@mistic
Copy link
Member

mistic commented Mar 21, 2019

@restrry awesome! I'll let you know as soon as I feel we are ready to start porting this 😃

@mshustov mshustov added release_note:skip Skip the PR/issue when compiling release notes and removed non-issue Indicates to automation that a pull request should not appear in the release notes labels Mar 26, 2019
@mshustov
Copy link
Contributor Author

I close PR. when #33826 is merged we need to check eslint lints *ts. files as well or enable such check

@mshustov mshustov closed this Mar 29, 2019
@mshustov mshustov removed review blocked release_note:skip Skip the PR/issue when compiling release notes v7.2.0 labels Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:New Platform Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants