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

chore: 🤖 forbid import from ui/** #40537

Merged
merged 15 commits into from
Jul 18, 2019
Merged

chore: 🤖 forbid import from ui/** #40537

merged 15 commits into from
Jul 18, 2019

Conversation

streamich
Copy link
Contributor

@streamich streamich commented Jul 8, 2019

Summary

  • This PR adds a linter rule that forbids NP-ready code from np_ready folder to import ui/**.
  • Fixes Core deep import restriction src/core/**, when src/** Webpack alias is used.

Checklist

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

For maintainers

@streamich streamich added the release_note:skip Skip the PR/issue when compiling release notes label Jul 8, 2019
@streamich streamich requested review from spalger and mshustov and removed request for spalger July 8, 2019 19:05
@streamich streamich added Team:AppArch Team:Operations Team label for Operations Team labels Jul 8, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-operations

@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch

@Conky5
Copy link
Contributor

Conky5 commented Jul 8, 2019

retest

@elastic elastic deleted a comment from elasticmachine Jul 8, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@lukeelmers
Copy link
Member

lukeelmers commented Jul 8, 2019

Before merging, let's make sure we finish the related discussion that was started in #39554 and #40032

This PR assumes a specific way of structuring shims that we haven't discussed previously. I'm not necessarily opposed to it, just want to be sure we have some sort of consensus before pushing something like this through.

@streamich
Copy link
Contributor Author

@lukeelmers This is a poc-* PR for tomorrow's meeting.

.eslintrc.js Outdated Show resolved Hide resolved
@lizozom
Copy link
Contributor

lizozom commented Jul 9, 2019

While getting ui/public imports out of the shims is our goal, I think that it will make migration harder and more cumbersome. It will prevent us from doing iterative work and will tie unnecessary work together:

i.e.

  • creating a visualization shim shape
  • changing the deps in that visualization
    can be done separately.

ui/public is clearly going away anyway, but I see no reason to enforce it with a lint rule.

@streamich streamich changed the title chore: 🤖 forbid importing from ui/** from within shims chore: 🤖 forbid importing from ui/** from within NP-ready code Jul 12, 2019
@streamich
Copy link
Contributor Author

streamich commented Jul 12, 2019

Agreed to use this rule in our weekly sync. Decided to use np_ready folder for NP plugin code within legacy plugins.

@streamich streamich requested review from lukeelmers and lizozom July 12, 2019 16:56
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

Tested and verified the rule works as expected.

I tend to agree with @spalger that the changes in packages/kbn-eslint-plugin-eslint/rules/no_restricted_paths.js feel out of place, but I'm also not super familiar with the existing configuration, so I'll defer to @spalger or @restrry for any further comments on that topic.

If we are worried about the implementation here, IMO it would be fine if we needed to make tweaks to what we are checking for -- the only goal for this is to make peoples' lives easier if they opt to use a np_ready directory as part of their migration strategy (and it's going away at the end of the migration anyway).

@@ -38,6 +38,7 @@ import {
EuiText,
} from '@elastic/eui';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { SavedObjectAttributes } from 'src/core/server/saved_objects';
Copy link
Contributor Author

@streamich streamich Jul 15, 2019

Choose a reason for hiding this comment

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

I think src/** imports that used Webpack alias, like

import 'src/core/server/saved_objects';

where not covered previously, now this PR fixes it. Added a test for it, too.

@elasticmachine
Copy link
Contributor

💔 Build Failed

Copy link
Contributor

@spalger spalger left a comment

Choose a reason for hiding this comment

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

LGTM

@mshustov
Copy link
Contributor

ack: have a look tonight

@streamich streamich requested a review from mshustov July 16, 2019 09:51
@streamich streamich requested review from a team as code owners July 16, 2019 10:04
@elastic elastic deleted a comment from elasticmachine Jul 16, 2019
@@ -8,6 +8,7 @@ import * as Rx from 'rxjs';
import { Server } from 'hapi';
import { Legacy } from 'kibana';
import { KibanaConfig } from 'src/legacy/server/kbn_server';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Copy link
Member

Choose a reason for hiding this comment

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

I was under the impression that this was the "correct" way to import mocks. Is there another approach we should take? Are mocks not meant to be used in this way at all?

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 guess it is still as "correct" as it was before. The difference is that before this PR @kbn/eslint/no-restricted-paths linter rule ignored Webpack aliases like src/.., now it processes them as well.


Maybe @elastic/kibana-platform could comment what is the "correct" way to import mocks/types? ^^

Copy link
Contributor

@mshustov mshustov Jul 16, 2019

Choose a reason for hiding this comment

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

yeah, unfortunately linter rule doesn't work with absolute paths yet. #36096
as a temporary solution you can change zones in .eslintrc

- '!src/core/server/mocks.ts',
+ '!src/core/server/mocks',

- '!src/core/public/mocks.ts',
+ '!src/core/public/mocks',

I guess it is still as "correct" as it was before.

right

@streamich
Copy link
Contributor Author

retest

@elastic elastic deleted a comment from elasticmachine Jul 16, 2019
@elasticmachine
Copy link
Contributor

💔 Build Failed

@@ -18,6 +18,7 @@
*/

import { PluginInitializerContext } from 'kibana/public';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { npSetup, npStart } from 'ui/new_platform';
Copy link
Contributor

Choose a reason for hiding this comment

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

should we allow importing from ui/new_platform? if yes you can add !ui/new_platform in zone declaration inside .eslintrc

@@ -6,6 +6,7 @@

import getPort from 'get-port';
import { resolve } from 'path';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Copy link
Contributor

Choose a reason for hiding this comment

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

and tests may import from anywhere. we also can exclude them from the check

Copy link
Contributor

@mshustov mshustov left a comment

Choose a reason for hiding this comment

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

thnx for help. I believe we can improve the approach later in #36096

@streamich streamich changed the title chore: 🤖 forbid importing from ui/** from within NP-ready code chore: 🤖 forbid import from ui/** Jul 16, 2019
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@streamich streamich added the Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! label Jul 18, 2019
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security

@streamich streamich merged commit 8f0de3a into elastic:master Jul 18, 2019
@streamich streamich deleted the poc-ui-import-rule branch July 18, 2019 20:52
streamich added a commit that referenced this pull request Jul 18, 2019
* chore: 🤖 forbid importing from ui/** from within shims

* chore: 🤖 allow importing platfrom in dashboard embeddable sihm

* chore: 🤖 use np_ready folder, improve rule

* chore: 🤖 update ESLint error message

* feat: 🎸 improve eslint plugin rule

* test: 💍 add tests for restricted paths linter rule

* test: 💍 add ESLint package to CI testing suite

* chore: 🤖 fix linter errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:skip Skip the PR/issue when compiling release notes review Team:Operations Team label for Operations Team Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants