Skip to content

Commit

Permalink
Add app layer to exceptions of no-layer-public-api rule (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniilsapa authored Jul 17, 2024
1 parent 5e7fa93 commit b1866e8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/honest-dryers-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@feature-sliced/steiger-plugin': patch
---

Add an exception for app layer to no-layer-public-api rule
2 changes: 2 additions & 0 deletions packages/steiger-plugin-fsd/src/no-layer-public-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ According to the _public API rule on slices_:
A corollary to this rule is that the layer itself should not have an index file.

**Exception:** index files are allowed on `app` layer because some people prefer to have that as their app's entrypoint.

Examples of project structures that pass this rule:

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ it('reports errors on a project with index files on layer level', () => {
📂 ui
📄 index.ts
📄 index.ts
📂 app
📂 ui
📄 index.ts
📄 index.ts
`)

const diagnostics = noLayerPublicApi.check(root).diagnostics
Expand Down
7 changes: 6 additions & 1 deletion packages/steiger-plugin-fsd/src/no-layer-public-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { getIndex, getLayers } from '@feature-sliced/filesystem'
import type { Diagnostic, Rule } from '@steiger/types'

/** Layers that are allowed to have an index file. */
const exceptionLayers = ['app']

/** Forbid index files on layer level. */
const noLayerPublicApi = {
name: 'no-layer-public-api',
Expand All @@ -9,7 +12,9 @@ const noLayerPublicApi = {

for (const [layerName, layer] of Object.entries(getLayers(root))) {
const index = getIndex(layer)
if (index !== undefined) {
const notAmongExceptions = !exceptionLayers.includes(layerName)

if (notAmongExceptions && index !== undefined) {
diagnostics.push({
message: `Layer "${layerName}" should not have an index file`,
location: { path: index.path },
Expand Down

0 comments on commit b1866e8

Please sign in to comment.