Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an exception to the insignificant-slice rule when the only usage site is the App layer #154

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading