Lint for cross-system imports only happening to root of systems #33444
Labels
Feature:New Platform
Meta
non-issue
Indicates to automation that a pull request should not appear in the release notes
Team:Core
Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Problem
Client and side parts of the core and plugins should expose their contracts explicitly via
index.js
files.Direct imports from
core/server/foo/...
,core/public/foo/...
,src/plugins/bar/public/...
,src/plugins/bar/server/...
should be restricted by linter.Considered options
I decided to go with the former option as providing better DX.
Requirements
Linter should block attempts to import from module internals. This way we force a module to declare public interface explicitly.
Linter should check only product code, because quite often in tests and dev-utils we want to manipulate module internals, mock a part of a module, for example.
eslint
PR #33697
import/no-restricted-paths uses a similar approach with zones.
Restrict import from sibling folders
Now
src/plugins/foo/foo.js
can import fromsrc/plugins/bar/bar.js
. Such restriction is not supported byimport/no-restricted-paths
, will be implemented as a separate plugin.tslint
PR: #34688
PR on hold, waits migration from tslint to eslint #33562I start with tslint setup. There is import-blacklist rule, which implemented in the last version.
The problem with it this approach that restrictions are applied for the whole project, we cannot exclude or override settings for specific path and this feature won't be implemented palantir/tslint#3447
Also, because it's simple string check without file path resolution, we cannot limit access when import expression doesn't contain the full path(say one plugin import internals of another from sibling folder
import * from '../sibling_folder/server/types.ts
.I decided to go with https://github.com/vladimiry/tslint-rules-bunch as this rule provides granular setup for a specific path with glob syntax and uses file path resolution mechanism internally.
Related issues
Export types from root of systems
#33963
The text was updated successfully, but these errors were encountered: