feature-sliced / steiger

Universal file structure and project architecture linter
https://www.npmjs.com/package/steiger
MIT License
18 stars 0 forks source link

Question: Public API in shared layer #45

Open EliseyMartynov opened 1 week ago

EliseyMartynov commented 1 week ago

Как мы знаем shared слой состоит не из слайсов, а из сегментов. Требование Public API для сегментов shared слоя не кажется избыточным? Может вы не учли исключение shared слоя при написании этого правила?

image

Sandbox: https://codesandbox.io/p/devbox/steiger-test-g4f4wp

==================================================

Из этого вытекает вторая проблема: если в shared слое т.к. он состоит из сегментов убирать Public API - в линтере нужна настройка разрешенной глубины импортов для конкретного слоя, чтобы это не выглядело нарушением Public API, e.g.:

import from 'shared/ui/card'

Воспроизвести в сэндбоксе быстро не получилось.

illright commented 1 week ago

That's currently how the public API rule is formulated:

Every slice (and segment on layers that don't have slices) must contain a public API definition.

The case with shared/ui is something to discuss, because some people don't want a single index file to keep bundles lightweight. So to me, this is more the case of support several indexes if needed

EliseyMartynov commented 1 week ago

shared/ui can be a really large dir. Several indexes will degrade DX in that case.

illright commented 1 week ago

How would they degrade DX? And also what solution would you prefer?

EliseyMartynov commented 1 week ago

How it would degrade - I would have to go and configure every folder in shared/ui as my multi-index entries, isnt it?

As I said in my Russian comment - configure depth may be could solve it?

illright commented 1 week ago

I would have to go and configure every folder in shared/ui as my multi-index entries

Yes, if you want every folder in shared/ui to be an index, which I don't think is a great idea, because it kind of defeats the purpose of Public API

configure depth may be could solve it?

This rule is concerned with the presence of public API, so I would want any modifications to this rule to be modifications to the rules of public API. Currently, the public API is required on every slice and on every segment in Shared. If this requirement doesn't work well for your project, then we can discuss how we can change the definition of what a public API is

vdanchenkov commented 1 week ago

I have another issue, but it's closely related to this discussion.

✘ Forbidden sidestep of public API when importing "shared/ui/form/index.tsx" from "features/my-feature/ui/Component.tsx". // no-public-api-sidestep

As you can see I have segment shared/ui with public API and shared/ui/form with public API. I see that nested segments looks strange, but looks like some people use it that way.

shared/ui/form contains several controls specific to usage inside forms.

So, is it a bug, should we allow usage of deep index.ts?

Or I have to flatten segments to have shared/ui and shared/form?