Skip to content

Commit ec2134d

Browse files
authored
Add lint rule to prevent server code being imported into client (#52447)
1 parent 6c1f248 commit ec2134d

File tree

115 files changed

+639
-86
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+639
-86
lines changed

.eslintrc.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ module.exports = {
297297
'src/legacy/**/*',
298298
'x-pack/**/*',
299299
'!x-pack/**/*.test.*',
300-
'src/plugins/**/(public|server)/**/*',
300+
'!x-pack/test/**/*',
301+
'(src|x-pack)/plugins/**/(public|server)/**/*',
301302
'src/core/(public|server)/**/*',
302303
],
303304
from: [
@@ -317,13 +318,32 @@ module.exports = {
317318
'!src/core/server/types',
318319
'!src/core/server/*.test.mocks.ts',
319320

320-
'src/plugins/**/public/**/*',
321-
'!src/plugins/**/public/index.{js,ts,tsx}',
322-
323-
'src/plugins/**/server/**/*',
324-
'!src/plugins/**/server/index.{js,ts,tsx}',
321+
'(src|x-pack)/plugins/**/(public|server)/**/*',
322+
'!(src|x-pack)/plugins/**/(public|server)/(index|mocks).{js,ts,tsx}',
325323
],
326324
allowSameFolder: true,
325+
errorMessage: 'Plugins may only import from top-level public and server modules.',
326+
},
327+
{
328+
target: [
329+
'(src|x-pack)/plugins/**/*',
330+
'!(src|x-pack)/plugins/*/server/**/*',
331+
332+
'src/legacy/core_plugins/**/*',
333+
'!src/legacy/core_plugins/*/server/**/*',
334+
'!src/legacy/core_plugins/*/index.{js,ts,tsx}',
335+
336+
'x-pack/legacy/plugins/**/*',
337+
'!x-pack/legacy/plugins/*/server/**/*',
338+
'!x-pack/legacy/plugins/*/index.{js,ts,tsx}',
339+
],
340+
from: [
341+
'src/core/server',
342+
'src/core/server/**/*',
343+
'(src|x-pack)/plugins/*/server/**/*',
344+
],
345+
errorMessage:
346+
'Server modules cannot be imported into client modules or shared modules.',
327347
},
328348
{
329349
target: ['src/**/*'],
@@ -340,6 +360,11 @@ module.exports = {
340360
],
341361
errorMessage: 'The core cannot depend on any plugins.',
342362
},
363+
{
364+
target: ['(src|x-pack)/plugins/*/public/**/*'],
365+
from: ['ui/**/*', 'uiExports/**/*'],
366+
errorMessage: 'Plugins cannot import legacy UI code.',
367+
},
343368
{
344369
from: ['src/legacy/ui/**/*', 'ui/**/*'],
345370
target: [

docs/development/core/public/kibana-plugin-public.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ The plugin integrates with the core system via lifecycle events: `setup`<!-- -->
8989
| [SavedObjectsCreateOptions](./kibana-plugin-public.savedobjectscreateoptions.md) | |
9090
| [SavedObjectsFindOptions](./kibana-plugin-public.savedobjectsfindoptions.md) | |
9191
| [SavedObjectsFindResponsePublic](./kibana-plugin-public.savedobjectsfindresponsepublic.md) | Return type of the Saved Objects <code>find()</code> method.<!-- -->\*Note\*: this type is different between the Public and Server Saved Objects clients. |
92+
| [SavedObjectsImportConflictError](./kibana-plugin-public.savedobjectsimportconflicterror.md) | Represents a failure to import due to a conflict. |
93+
| [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md) | Represents a failure to import. |
94+
| [SavedObjectsImportMissingReferencesError](./kibana-plugin-public.savedobjectsimportmissingreferenceserror.md) | Represents a failure to import due to missing references. |
95+
| [SavedObjectsImportResponse](./kibana-plugin-public.savedobjectsimportresponse.md) | The response describing the result of an import. |
96+
| [SavedObjectsImportRetry](./kibana-plugin-public.savedobjectsimportretry.md) | Describes a retry operation for importing a saved object. |
97+
| [SavedObjectsImportUnknownError](./kibana-plugin-public.savedobjectsimportunknownerror.md) | Represents a failure to import due to an unknown reason. |
98+
| [SavedObjectsImportUnsupportedTypeError](./kibana-plugin-public.savedobjectsimportunsupportedtypeerror.md) | Represents a failure to import due to having an unsupported saved object type. |
9299
| [SavedObjectsMigrationVersion](./kibana-plugin-public.savedobjectsmigrationversion.md) | Information about the migrations that have been applied to this SavedObject. When Kibana starts up, KibanaMigrator detects outdated documents and migrates them based on this value. For each migration that has been applied, the plugin's name is used as a key and the latest migration version as the value. |
93100
| [SavedObjectsStart](./kibana-plugin-public.savedobjectsstart.md) | |
94101
| [SavedObjectsUpdateOptions](./kibana-plugin-public.savedobjectsupdateoptions.md) | |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportConflictError](./kibana-plugin-public.savedobjectsimportconflicterror.md)
4+
5+
## SavedObjectsImportConflictError interface
6+
7+
Represents a failure to import due to a conflict.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export interface SavedObjectsImportConflictError
13+
```
14+
15+
## Properties
16+
17+
| Property | Type | Description |
18+
| --- | --- | --- |
19+
| [type](./kibana-plugin-public.savedobjectsimportconflicterror.type.md) | <code>'conflict'</code> | |
20+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportConflictError](./kibana-plugin-public.savedobjectsimportconflicterror.md) &gt; [type](./kibana-plugin-public.savedobjectsimportconflicterror.type.md)
4+
5+
## SavedObjectsImportConflictError.type property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
type: 'conflict';
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md) &gt; [error](./kibana-plugin-public.savedobjectsimporterror.error.md)
4+
5+
## SavedObjectsImportError.error property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
error: SavedObjectsImportConflictError | SavedObjectsImportUnsupportedTypeError | SavedObjectsImportMissingReferencesError | SavedObjectsImportUnknownError;
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md) &gt; [id](./kibana-plugin-public.savedobjectsimporterror.id.md)
4+
5+
## SavedObjectsImportError.id property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
id: string;
11+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md)
4+
5+
## SavedObjectsImportError interface
6+
7+
Represents a failure to import.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
export interface SavedObjectsImportError
13+
```
14+
15+
## Properties
16+
17+
| Property | Type | Description |
18+
| --- | --- | --- |
19+
| [error](./kibana-plugin-public.savedobjectsimporterror.error.md) | <code>SavedObjectsImportConflictError &#124; SavedObjectsImportUnsupportedTypeError &#124; SavedObjectsImportMissingReferencesError &#124; SavedObjectsImportUnknownError</code> | |
20+
| [id](./kibana-plugin-public.savedobjectsimporterror.id.md) | <code>string</code> | |
21+
| [title](./kibana-plugin-public.savedobjectsimporterror.title.md) | <code>string</code> | |
22+
| [type](./kibana-plugin-public.savedobjectsimporterror.type.md) | <code>string</code> | |
23+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md) &gt; [title](./kibana-plugin-public.savedobjectsimporterror.title.md)
4+
5+
## SavedObjectsImportError.title property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
title?: string;
11+
```
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportError](./kibana-plugin-public.savedobjectsimporterror.md) &gt; [type](./kibana-plugin-public.savedobjectsimporterror.type.md)
4+
5+
## SavedObjectsImportError.type property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
type: string;
11+
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [SavedObjectsImportMissingReferencesError](./kibana-plugin-public.savedobjectsimportmissingreferenceserror.md) &gt; [blocking](./kibana-plugin-public.savedobjectsimportmissingreferenceserror.blocking.md)
4+
5+
## SavedObjectsImportMissingReferencesError.blocking property
6+
7+
<b>Signature:</b>
8+
9+
```typescript
10+
blocking: Array<{
11+
type: string;
12+
id: string;
13+
}>;
14+
```

0 commit comments

Comments
 (0)