From 067634e0c83ae3f12caa3ec99d85741cf5fd2ab3 Mon Sep 17 00:00:00 2001 From: Daniil Sapa Date: Sat, 13 Jul 2024 18:44:48 +0300 Subject: [PATCH] Connect no-segments-on-sliced-layers rule to the app, add documents for the new rule --- README.md | 1 + packages/steiger-plugin-fsd/src/index.ts | 2 + .../no-segments-on-sliced-layers/README.md | 47 +++++++++++++++++++ packages/steiger/README.md | 1 + packages/steiger/src/models/config.ts | 1 + 5 files changed, 52 insertions(+) create mode 100644 packages/steiger-plugin-fsd/src/no-segments-on-sliced-layers/README.md diff --git a/README.md b/README.md index aa2be9a..28e71af 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ Currently, Steiger is not extendable with more rules, though that will change in no-public-api-sidestep Forbid going around the public API of a slice to import directly from an internal module in a slice. no-reserved-folder-names Forbid subfolders in segments that have the same name as other conventional segments. no-segmentless-slices Forbid slices that don't have any segments. + no-segments-on-sliced-layers Forbid segments (like ui, lib, api ...) that appear directly in sliced layer folders (entities, features, ...) public-api Require slices (and segments on sliceless layers like Shared) to have a public API definition. repetitive-naming Ensure that all entities are named consistently in terms of pluralization. segments-by-purpose Discourage the use of segment names that group code by its essence, and instead encourage grouping by purpose diff --git a/packages/steiger-plugin-fsd/src/index.ts b/packages/steiger-plugin-fsd/src/index.ts index 6e63f8b..8382722 100644 --- a/packages/steiger-plugin-fsd/src/index.ts +++ b/packages/steiger-plugin-fsd/src/index.ts @@ -7,6 +7,7 @@ import noLayerPublicApi from './no-layer-public-api/index.js' import noPublicApiSidestep from './no-public-api-sidestep/index.js' import noReservedFolderNames from './no-reserved-folder-names/index.js' import noSegmentlessSlices from './no-segmentless-slices/index.js' +import noSegmentsOnSlicedLayers from './no-segments-on-sliced-layers/index.js' import publicApi from './public-api/index.js' import repetitiveNaming from './repetitive-naming/index.js' import segmentsByPurpose from './segments-by-purpose/index.js' @@ -23,6 +24,7 @@ export default [ noPublicApiSidestep, noReservedFolderNames, noSegmentlessSlices, + noSegmentsOnSlicedLayers, publicApi, repetitiveNaming, segmentsByPurpose, diff --git a/packages/steiger-plugin-fsd/src/no-segments-on-sliced-layers/README.md b/packages/steiger-plugin-fsd/src/no-segments-on-sliced-layers/README.md new file mode 100644 index 0000000..df6463c --- /dev/null +++ b/packages/steiger-plugin-fsd/src/no-segments-on-sliced-layers/README.md @@ -0,0 +1,47 @@ +# `no-segmentless-slices` + +Forbid segments that appear in direct children of sliced layers. + +Examples of project structures that pass this rule: + +``` +📂 shared + 📂 ui + 📄 index.ts + 📂 lib + 📄 index.ts +📂 entities + 📂 user + 📂 ui + 📂 model + 📄 index.ts +📂 pages + 📂 home + 📂 ui + 📄 index.ts +``` + +Examples of project structures that fail this rule: + +``` +📂 shared + 📂 ui + 📄 index.ts + 📂 lib + 📄 index.ts +📂 entities + 📂 user + 📂 ui + 📂 model + 📄 index.ts + 📂 api // ❌ + 📄 index.ts +📂 pages + 📂 home + 📂 ui + 📄 index.ts +``` + +## Rationale + +Slices exist to partition code by business domain and entities. You can freely create and name them (e.g. `pages` home, profile and `entities` user, product, ...) based on your needs, application logic, company glossary, etc. Slices contain code of different type/purposes (segments) to implement their part of functionality. Segments (`ui`, `lib`, `api`) are simply a division of code by purpose, thus "ownerless" segments in sliced layers are not allowed since they need to be attached to some part of the business domain inside these layers. diff --git a/packages/steiger/README.md b/packages/steiger/README.md index aa2be9a..28e71af 100644 --- a/packages/steiger/README.md +++ b/packages/steiger/README.md @@ -66,6 +66,7 @@ Currently, Steiger is not extendable with more rules, though that will change in no-public-api-sidestep Forbid going around the public API of a slice to import directly from an internal module in a slice. no-reserved-folder-names Forbid subfolders in segments that have the same name as other conventional segments. no-segmentless-slices Forbid slices that don't have any segments. + no-segments-on-sliced-layers Forbid segments (like ui, lib, api ...) that appear directly in sliced layer folders (entities, features, ...) public-api Require slices (and segments on sliceless layers like Shared) to have a public API definition. repetitive-naming Ensure that all entities are named consistently in terms of pluralization. segments-by-purpose Discourage the use of segment names that group code by its essence, and instead encourage grouping by purpose diff --git a/packages/steiger/src/models/config.ts b/packages/steiger/src/models/config.ts index c9aee7b..8241e07 100644 --- a/packages/steiger/src/models/config.ts +++ b/packages/steiger/src/models/config.ts @@ -14,6 +14,7 @@ export const schema = z.object({ 'no-public-api-sidestep', 'no-reserved-folder-names', 'no-segmentless-slices', + 'no-segments-on-sliced-layers', 'public-api', 'repetitive-naming', 'segments-by-purpose',