Skip to content

Commit

Permalink
Add an exception to the insignificant-slice rule when the only usag…
Browse files Browse the repository at this point in the history
…e site is the App layer
  • Loading branch information
illright committed Dec 22, 2024
1 parent 58c325a commit 63eba55
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/ten-weeks-drive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@feature-sliced/steiger-plugin': patch
---

Add an exception to the `insignificant-slice` rule when the only usage site is the App layer
20 changes: 20 additions & 0 deletions packages/steiger-plugin-fsd/src/insignificant-slice/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ vi.mock('node:fs', async (importOriginal) => {
'/features/comments/ui/CommentCard.tsx': '',
'/features/comments/index.ts': '',

'/widgets/sidebar/ui/Sidebar.tsx': '',
'/widgets/sidebar/index.ts': '',

'/pages/editor/ui/EditorPage.tsx':
'import { Button } from "@/shared/ui"; import { Editor } from "./Editor"; import { CommentCard } from "@/features/comments"; import { UserAvatar } from "@/entities/user"',
'/pages/editor/ui/Editor.tsx':
Expand All @@ -43,6 +46,8 @@ vi.mock('node:fs', async (importOriginal) => {
'/pages/settings/index.ts': '',
'/pages/home/index.ts': '',
'/pages/category/index.ts': '',

'/app/layouts/BaseLayout.tsx': 'import { Sidebar } from "@/widgets/sidebar"',
},
originalFs,
)
Expand Down Expand Up @@ -95,6 +100,21 @@ it('reports no errors on a project with no insignificant slices', async () => {
expect((await insignificantSlice.check(root)).diagnostics).toEqual([])
})

it('reports no errors when the only usage of a slice is on the App layer', async () => {
const root = parseIntoFsdRoot(`
📂 widgets
📂 sidebar
📂 ui
📄 Sidebar.tsx
📄 index.ts
📂 app
📂 layouts
📄 BaseLayout.tsx
`)

expect((await insignificantSlice.check(root)).diagnostics).toEqual([])
})

it('reports errors on a project with insignificant slices', async () => {
const root = parseIntoFsdRoot(`
📂 shared
Expand Down
10 changes: 6 additions & 4 deletions packages/steiger-plugin-fsd/src/insignificant-slice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ const insignificantSlice = {
if (targetLocationKeys.size === 1) {
const referenceLocationKey = [...targetLocationKeys][0]
if (unslicedLayers.includes(referenceLocationKey)) {
diagnostics.push({
message: `This slice has only one reference on layer "${referenceLocationKey}". Consider moving this code to "${referenceLocationKey}".`,
location: { path: join(root.path, sourceLocationKey) },
})
if (referenceLocationKey !== 'app') {
diagnostics.push({
message: `This slice has only one reference on layer "${referenceLocationKey}". Consider moving this code to "${referenceLocationKey}".`,
location: { path: join(root.path, sourceLocationKey) },
})
}
} else {
diagnostics.push({
message: `This slice has only one reference in slice "${referenceLocationKey}". Consider merging them.`,
Expand Down

0 comments on commit 63eba55

Please sign in to comment.