diff --git a/.changeset/ten-weeks-drive.md b/.changeset/ten-weeks-drive.md new file mode 100644 index 0000000..892563f --- /dev/null +++ b/.changeset/ten-weeks-drive.md @@ -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 diff --git a/packages/steiger-plugin-fsd/src/insignificant-slice/index.spec.ts b/packages/steiger-plugin-fsd/src/insignificant-slice/index.spec.ts index 3350db7..1c52423 100644 --- a/packages/steiger-plugin-fsd/src/insignificant-slice/index.spec.ts +++ b/packages/steiger-plugin-fsd/src/insignificant-slice/index.spec.ts @@ -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': @@ -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, ) @@ -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 diff --git a/packages/steiger-plugin-fsd/src/insignificant-slice/index.ts b/packages/steiger-plugin-fsd/src/insignificant-slice/index.ts index 88c013f..71aba9f 100644 --- a/packages/steiger-plugin-fsd/src/insignificant-slice/index.ts +++ b/packages/steiger-plugin-fsd/src/insignificant-slice/index.ts @@ -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.`,