Skip to content

Commit

Permalink
Fix repetitive-naming complaining about one slice
Browse files Browse the repository at this point in the history
  • Loading branch information
illright committed Jun 13, 2024
1 parent 6351a09 commit ab43b01
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions packages/steiger-plugin-fsd/src/repetitive-naming/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,36 @@ it('recognizes words in different naming conventions', () => {
const diagnostics = repetitiveNaming.check(root).diagnostics.sort(compareMessages)
expect(diagnostics).toEqual([{ message: 'Repetitive word "folder" in slice names on layer "entities"' }])
})

it('does not complain about layers with just one slice', () => {
const root = parseIntoFsdRoot(`
📂 pages
📂 create-post
📂 ui
📄 index.tsx
📄 index.ts
📂 home
📂 ui
📄 index.tsx
📄 index.ts
📂 post
📂 ui
📄 index.tsx
📄 index.ts
📂 features
📂 create-post
📂 api
📂 ui
📄 index.tsx
📄 index.ts
📂 entities
📂 post
📂 api
📂 model
📂 ui
📄 index.tsx
📄 index.ts
`)

expect(repetitiveNaming.check(root)).toEqual({ diagnostics: [] })
})
6 changes: 5 additions & 1 deletion packages/steiger-plugin-fsd/src/repetitive-naming/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ const repetitiveNaming = {
}, new Map<string, number>())

for (const [word, count] of mostCommonWords.entries()) {
if (count >= sliceNames.length && wordsInSliceNames.every((words) => words.includes(word))) {
if (
sliceNames.length > 2 &&
count >= sliceNames.length &&
wordsInSliceNames.every((words) => words.includes(word))
) {
diagnostics.push({ message: `Repetitive word "${word}" in slice names on layer "${layerName}"` })
}
}
Expand Down

0 comments on commit ab43b01

Please sign in to comment.