feat(eslint): add no_sync_import_from_plugin rule (closes #171080)#266636
feat(eslint): add no_sync_import_from_plugin rule (closes #171080)#266636
Conversation
- Add @kbn/eslint/no_sync_import_from_plugin for plugin server/index.ts - Register rule; wire @kbn/eslint-config override (off until migrations merge) - Document pattern and rule in AGENTS.md Closes #171080 Made-with: Cursor
Enforce the rule on plugin server/index.ts so CI reports violations; counts should drop as lazy-load migrations merge. Update AGENTS.md. Made-with: Cursor
|
@elasticmachine merge upstream |
There was a problem hiding this comment.
Nice rule — handles the import type / await import() distinction cleanly and tests cover the main invalid shapes (value import, mixed type+value, side-effect import, named re-export, export *, require()). One small scoping observation about the override globs left inline.
Other things I checked and found fine:
- Default and namespace imports (
import Foo from './plugin',import * as p from './plugin') fall through tocontext.reportcorrectly via thespec.type === 'ImportSpecifier'check, so they're caught even though they aren't in the test fixtures. excludedFiles: ['**/test/**']correctly skips test-fixture plugins undersrc/platform/test/**/plugins/**andx-pack/platform/test/**/plugins/**.- The rule message is actionable and points at the migration PR.
| 'src/platform/plugins/**/server/index.ts', | ||
| 'x-pack/platform/plugins/**/server/index.ts', | ||
| 'x-pack/solutions/**/plugins/**/server/index.ts', | ||
| 'examples/**/server/index.ts', |
There was a problem hiding this comment.
The examples/**/server/index.ts glob only matches the repo-root examples/ tree, so the 5 plugin entries under x-pack/examples/ (e.g. alerting_example, screenshotting_example, triggers_actions_ui_example, gen_ai_streaming_response_example, third_party_vis_lens_example) are not enforced. If example plugins are intended to follow the same pattern, consider also covering x-pack/examples/.
| 'examples/**/server/index.ts', | |
| 'examples/**/server/index.ts', | |
| 'x-pack/examples/**/server/index.ts', |
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]
History
cc @afharo |
|
Starting backport for target branches: 9.4 https://github.com/elastic/kibana/actions/runs/25387219855 |
💔 All backports failed
Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
1 similar comment
|
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Summary
Implements the ESLint rule requested in #171080 to support the plugin server entry pattern from #170856:
server/index.tsshould not synchronously load./plugin(value imports, re-exports, side-effectimport './plugin', orrequire('./plugin'));import type/export typeand dynamicimport()are allowed.@kbn/eslint/no_sync_import_from_pluginin@kbn/eslint-plugin-eslintwith Jest tests.@kbn/eslint-configoverride for pluginserver/index.tspaths: rule iserrorso CI enforces the pattern; the number of violations should decrease as lazy-loadserver/index.tsmigrations land.AGENTS.md: document the pattern and the rule.Closes #171080
Review disclaimer
This PR was drafted with AI assistance (Cursor / Composer). Please give it a thorough review—especially rule edge cases and interaction with in-flight migration PRs.
Made with Cursor