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
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,21 @@ module.exports = {
],
allowSameFolder: true,
},
{
from: ['src/legacy/ui/**/*', 'ui/**/*'],
target: [
'src/legacy/core_plugins/**/public/np_ready/**/*',
'src/legacy/core_plugins/**/server/np_ready/**/*',
'x-pack/legacy/plugins/**/public/np_ready/**/*',
'x-pack/legacy/plugins/**/server/np_ready/**/*',
],
allowSameFolder: true,
errorMessage:
'NP-ready code should not import from /src/legacy/ui/** folder. ' +
'Instead of importing from /src/legacy/ui/** deeply within a np_ready folder, ' +
'import those things once at the top level of your plugin and pass those down, just ' +
'like you pass down `core` and `plugins` objects.',
},
],
},
],
Expand Down
19 changes: 15 additions & 4 deletions packages/kbn-eslint-plugin-eslint/rules/no_restricted_paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,20 @@ module.exports = {
}

function checkForRestrictedImportPath(importPath, node) {
const absoluteImportPath = resolve(importPath, context);
if (!absoluteImportPath) return;
let absoluteImportPath;
const [one, two, ...rest] = importPath.split('/');
if (one === 'ui') {
absoluteImportPath = path.join(
basePath,
`src/legacy/${one}/public/${two}${rest.length ? `/${rest.join('/')}` : ''}`
);
} else {
absoluteImportPath = resolve(importPath, context);
if (!absoluteImportPath) return;
}

const currentFilename = context.getFilename();
for (const { target, from, allowSameFolder } of zones) {
for (const { target, from, allowSameFolder, errorMessage = '' } of zones) {
const srcFilePath = resolve(currentFilename, context);

const relativeSrcFile = path.relative(basePath, srcFilePath);
Expand All @@ -116,7 +125,9 @@ module.exports = {

context.report({
node,
message: `Unexpected path "${importPath}" imported in restricted zone.`,
message: `Unexpected path "${importPath}" imported in restricted zone.${
errorMessage ? ' ' + errorMessage : ''
}`,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

import { embeddablePlugin } from '../../../embeddable_api/public';
import { Plugin } from './plugin';
Expand Down