Skip to content

Commit

Permalink
Implement no-processes
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Jun 18, 2024
1 parent b329a08 commit d0e37ba
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Currently, Steiger is not extendable with more rules, though that will change in
<tr> <td><a href="./packages/steiger-plugin-fsd/src/repetitive-naming/README.md"><code>repetitive-naming</code></a></td> <td>Ensure that all entities are named consistently in terms of pluralization.</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/segments-by-purpose/README.md"><code>segments-by-purpose</code></a></td> <td>Discourage the use of segment names that group code by its essence, and instead encourage grouping by purpose</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/shared-lib-grouping/README.md"><code>shared-lib-grouping</code></a></td> <td>Forbid having too many ungrouped modules in <code>shared/lib</code>.</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/no-processes/README.md"><code>no-processes</code></a></td> <td>Discourage the use of the deprecated Processes layer.</td> </tr>
</tbody>
</table>

Expand Down
2 changes: 2 additions & 0 deletions packages/steiger-plugin-fsd/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import publicApi from './public-api/index.js'
import repetitiveNaming from './repetitive-naming/index.js'
import segmentsByPurpose from './segments-by-purpose/index.js'
import sharedLibGrouping from './shared-lib-grouping/index.js'
import noProcesses from './no-processes/index.js'

export default [
ambiguousSliceNames,
Expand All @@ -26,6 +27,7 @@ export default [
repetitiveNaming,
segmentsByPurpose,
sharedLibGrouping,
noProcesses,
]

export type { Diagnostic, Context, Fix, Rule, RuleResult } from './types.js'
49 changes: 49 additions & 0 deletions packages/steiger-plugin-fsd/src/no-processes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# `no-processes`

Discourage the use of the deprecated Processes layer.

Examples of project structures that pass this rule:

```
📂 shared
📂 ui
📄 index.ts
📂 lib
📄 index.ts
📂 entities
📂 user
📂 ui
📂 model
📄 index.ts
📂 pages
📂 home
📂 ui
📄 index.ts
```

Examples of project structures that fail this rule:

```
📂 shared
📂 ui
📄 index.ts
📂 lib
📄 index.ts
📂 entities
📂 user
📂 ui
📂 model
📄 index.ts
📂 pages
📂 home
📂 ui
📄 index.ts
📂 processes // ❌
📂 cart
```

## Rationale

The Processes layer was deprecated because there weren't enough use cases to justify its exitsence.

If your project has this layer, consider moving the code from this layer into App or Features.
51 changes: 51 additions & 0 deletions packages/steiger-plugin-fsd/src/no-processes/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect, it } from 'vitest'

import noProcesses from './index.js'
import { parseIntoFsdRoot } from '../_lib/prepare-test.js'

it('reports no errors on a project without the Processes layer', () => {
const root = parseIntoFsdRoot(`
📂 shared
📂 ui
📄 index.ts
📂 lib
📄 index.ts
📂 entities
📂 user
📂 ui
📂 model
📄 index.ts
📂 pages
📂 home
📂 ui
📄 index.ts
`)

expect(noProcesses.check(root)).toEqual({ diagnostics: [] })
})

it('reports errors on a project with the Processes layer', () => {
const root = parseIntoFsdRoot(`
📂 shared
📂 ui
📄 index.ts
📂 lib
📄 index.ts
📂 entities
📂 user
📂 ui
📂 model
📄 index.ts
📂 pages
📂 home
📂 ui
📄 index.ts
📂 processes
📂 cart
📂 ui
📄 index.ts
`)

const diagnostics = noProcesses.check(root).diagnostics
expect(diagnostics).toEqual([{ message: 'Layer "processes" is deprecated, avoid using it' }])
})
23 changes: 23 additions & 0 deletions packages/steiger-plugin-fsd/src/no-processes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { basename } from 'node:path'
import type { Diagnostic, Rule } from '../types.js'

const noProcesses = {
name: 'no-processes',
check(root) {
const diagnostics: Array<Diagnostic> = []

const processesLayer = root.children.find(
(child) => child.type === 'folder' && basename(child.path) === 'processes',
)

if (processesLayer !== undefined) {
diagnostics.push({
message: 'Layer "processes" is deprecated, avoid using it',
})
}

return { diagnostics }
},
} satisfies Rule

export default noProcesses
1 change: 1 addition & 0 deletions packages/steiger/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Currently, Steiger is not extendable with more rules, though that will change in
<tr> <td><a href="./packages/steiger-plugin-fsd/src/repetitive-naming/README.md"><code>repetitive-naming</code></a></td> <td>Ensure that all entities are named consistently in terms of pluralization.</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/segments-by-purpose/README.md"><code>segments-by-purpose</code></a></td> <td>Discourage the use of segment names that group code by its essence, and instead encourage grouping by purpose</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/shared-lib-grouping/README.md"><code>shared-lib-grouping</code></a></td> <td>Forbid having too many ungrouped modules in <code>shared/lib</code>.</td> </tr>
<tr> <td><a href="./packages/steiger-plugin-fsd/src/no-processes/README.md"><code>no-processes</code></a></td> <td>Discourage the use of the deprecated Processes layer.</td> </tr>
</tbody>
</table>

Expand Down

0 comments on commit d0e37ba

Please sign in to comment.