Skip to content

Commit fdaa41b

Browse files
authored
Filter out uncountable nouns in inconsistent-naming (#195)
1 parent b84ebb5 commit fdaa41b

File tree

8 files changed

+55
-16
lines changed

8 files changed

+55
-16
lines changed

.changeset/clever-ways-rescue.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@feature-sliced/steiger-plugin': patch
3+
---
4+
5+
Filter out uncountable nouns in `inconsistent-naming`

integration-tests/tests/__snapshots__/smoke-stderr-posix.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
55
└ fsd/forbidden-imports: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/forbidden-imports
66

7-
┌ src/entities
8-
✘ Inconsistent pluralization of slice names. Prefer all plural names
9-
✔ Auto-fixable
7+
┌ src/entities/user
8+
✘ Avoid having both "user" and "users" entities.
109
1110
└ fsd/inconsistent-naming: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/inconsistent-naming
1211

@@ -40,6 +39,6 @@
4039
4140
└ fsd/no-processes: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-processes
4241

43-
────────────────────────────────────────────────────────
44-
Found 8 errors (1 can be fixed automatically with --fix)
45-
42+
────────────────────────────────────────────────
43+
Found 8 errors (none can be fixed automatically)
44+

integration-tests/tests/__snapshots__/smoke-stderr-windows.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
55
└ fsd/forbidden-imports: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/forbidden-imports
66

7-
┌ src\entities
8-
× Inconsistent pluralization of slice names. Prefer all plural names
9-
√ Auto-fixable
7+
┌ src\entities\user
8+
× Avoid having both "user" and "users" entities.
109
1110
└ fsd/inconsistent-naming: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/inconsistent-naming
1211

@@ -40,6 +39,6 @@
4039
4140
└ fsd/no-processes: https://github.com/feature-sliced/steiger/tree/master/packages/steiger-plugin-fsd/src/no-processes
4241

43-
────────────────────────────────────────────────────────
44-
Found 8 errors (1 can be fixed automatically with --fix)
45-
42+
────────────────────────────────────────────────
43+
Found 8 errors (none can be fixed automatically)
44+

packages/pretty-reporter/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"eslint": "^9.18.0",
3838
"prettier": "^3.4.2",
3939
"tsx": "^4.19.2",
40-
"typescript": "^5.7.3"
40+
"typescript": "^5.7.3",
41+
"vitest": "^3.0.2"
4142
},
4243
"dependencies": {
4344
"figures": "^6.1.0",

packages/steiger-plugin-fsd/src/inconsistent-naming/README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,13 @@
22

33
This rule ensures that all entities are named consistently in terms of pluralization.
44

5-
> [!WARNING]
6-
> This rule is in early development. It currently assumes that the slice name is a single English word. In the future it will be able to understand more complex names like `images-of-cats`.
5+
For names that consist of multiple words, the pluralization of the main subject is considered. For example:
6+
7+
- in `a book with pages`, the main subject is `book`, singular
8+
- in `admin-users`, the main subject is `users`, plural
9+
- in `receiptsByOrder`, the main subject is `receipts`, plural
10+
11+
Uncountable nouns like "firmware" are not counted as either singular or plural.
712

813
Example of a project structure that passes this rule:
914

packages/steiger-plugin-fsd/src/inconsistent-naming/index.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,3 +157,24 @@ it('allows inconsistency between different slice groups', () => {
157157
const diagnostics = inconsistentNaming.check(root).diagnostics
158158
expect(diagnostics).toEqual([])
159159
})
160+
161+
it('does not consider uncountable words as plural', () => {
162+
const root = parseIntoFsdRoot(
163+
`
164+
📂 entities
165+
📂 user
166+
📂 ui
167+
📄 index.ts
168+
📂 firmware
169+
📂 ui
170+
📄 index.ts
171+
📂 hardware
172+
📂 ui
173+
📄 index.ts
174+
`,
175+
joinFromRoot('users', 'user', 'project', 'src'),
176+
)
177+
178+
const diagnostics = inconsistentNaming.check(root).diagnostics
179+
expect(diagnostics).toEqual([])
180+
})

packages/steiger-plugin-fsd/src/inconsistent-naming/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ const inconsistentNaming = {
2424
const sliceNames = groupSlices(Object.keys(slices))
2525
for (const [groupPrefix, group] of Object.entries(sliceNames)) {
2626
const [pluralNames, singularNames] = partition(
27-
group.map((name) => [name, getMainSubject(name)] as const),
27+
group
28+
.map((name) => [name, getMainSubject(name)] as const)
29+
.filter(([, mainSubject]) => !isUncountable(mainSubject)),
2830
([, mainSubject]) => isPlural(mainSubject),
2931
)
3032

@@ -81,4 +83,8 @@ const inconsistentNaming = {
8183
},
8284
} satisfies Rule
8385

86+
function isUncountable(word: string) {
87+
return singular(word) === plural(word)
88+
}
89+
8490
export default inconsistentNaming

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)