-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Lev Chelyadinov <[email protected]>
- Loading branch information
Showing
8 changed files
with
127 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@feature-sliced/steiger-plugin': minor | ||
'steiger': minor | ||
--- | ||
|
||
Add no-ui-in-app rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# `no-ui-in-app` | ||
|
||
Forbid having <code>ui</code> segment in <code>app</code> layer. | ||
|
||
Examples of project structures that pass this rule: | ||
|
||
``` | ||
📂 shared | ||
📂 ui | ||
📄 index.ts | ||
📂 pages | ||
📂 home | ||
📂 ui | ||
📄 index.ts | ||
📂 app | ||
📂 providers | ||
📄 index.ts | ||
``` | ||
|
||
Examples of project structures that fail this rule: | ||
|
||
``` | ||
📂 shared | ||
📂 ui | ||
📄 index.ts | ||
📂 pages | ||
📂 home | ||
📂 ui | ||
📄 index.ts | ||
📂 app | ||
📂 providers | ||
📄 index.ts | ||
📂 ui // ❌ | ||
📄 index.ts | ||
``` | ||
|
||
## Rationale | ||
|
||
It's uncommon to define the `ui` segment on the App layer. The App layer is typically used to combine the application into a single entry point. The UI of your application should already be created on the layers below to avoid mixing up responsibilities. Therefore, the `ui` segment on the App layer is typically a mistake. | ||
|
||
For example, context providers are components, but they are not UI. Global styles are technically UI, but they aren't scoped to that segment, so the name `ui` might be a misdirection. | ||
|
||
As one possible exception, the `ui` segment can be used on the App layer if the entire application consists of only one page and there is no reason to define the Pages layer. |
46 changes: 46 additions & 0 deletions
46
packages/steiger-plugin-fsd/src/no-ui-in-app/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { expect, it } from 'vitest' | ||
|
||
import noUiInApp from './index.js' | ||
import { joinFromRoot, parseIntoFsdRoot } from '../_lib/prepare-test.js' | ||
|
||
it('reports no errors on a project without the "ui" segment on the "app" layer', () => { | ||
const root = parseIntoFsdRoot(` | ||
📂 shared | ||
📂 ui | ||
📄 index.ts | ||
📂 pages | ||
📂 home | ||
📂 ui | ||
📄 index.ts | ||
📂 app | ||
📂 providers | ||
📄 index.ts | ||
`) | ||
|
||
expect(noUiInApp.check(root)).toEqual({ diagnostics: [] }) | ||
}) | ||
|
||
it('reports errors on a project with the "ui" segment on the "app" layer', () => { | ||
const root = parseIntoFsdRoot(` | ||
📂 shared | ||
📂 ui | ||
📄 index.ts | ||
📂 pages | ||
📂 home | ||
📂 ui | ||
📄 index.ts | ||
📂 app | ||
📂 providers | ||
📄 index.ts | ||
📂 ui | ||
📄 index.ts | ||
`) | ||
|
||
const diagnostics = noUiInApp.check(root).diagnostics | ||
expect(diagnostics).toEqual([ | ||
{ | ||
message: 'Layer "app" should not have "ui" segment.', | ||
location: { path: joinFromRoot('app', 'ui') }, | ||
}, | ||
]) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type { Diagnostic, Rule } from '@steiger/types' | ||
import { NAMESPACE } from '../constants.js' | ||
import { getLayers, getSegments } from '@feature-sliced/filesystem' | ||
|
||
const noUiInApp = { | ||
name: `${NAMESPACE}/no-ui-in-app`, | ||
check(root) { | ||
const diagnostics: Array<Diagnostic> = [] | ||
|
||
const layers = getLayers(root) | ||
|
||
if (layers.app !== undefined) { | ||
const segments = getSegments(layers.app) | ||
|
||
if (segments.ui !== undefined) { | ||
diagnostics.push({ | ||
message: 'Layer "app" should not have "ui" segment.', | ||
location: { path: segments.ui.path }, | ||
}) | ||
} | ||
} | ||
|
||
return { diagnostics } | ||
}, | ||
} satisfies Rule | ||
|
||
export default noUiInApp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters