From ab43b01a716d439bb2845753b53fdaee1a685b2e Mon Sep 17 00:00:00 2001 From: Lev Chelyadinov Date: Thu, 13 Jun 2024 19:53:26 +0200 Subject: [PATCH] Fix `repetitive-naming` complaining about one slice --- .../src/repetitive-naming/index.spec.ts | 33 +++++++++++++++++++ .../src/repetitive-naming/index.ts | 6 +++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/packages/steiger-plugin-fsd/src/repetitive-naming/index.spec.ts b/packages/steiger-plugin-fsd/src/repetitive-naming/index.spec.ts index e48f9f3..f8f0e63 100644 --- a/packages/steiger-plugin-fsd/src/repetitive-naming/index.spec.ts +++ b/packages/steiger-plugin-fsd/src/repetitive-naming/index.spec.ts @@ -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: [] }) +}) diff --git a/packages/steiger-plugin-fsd/src/repetitive-naming/index.ts b/packages/steiger-plugin-fsd/src/repetitive-naming/index.ts index 69dc2fc..c2f9491 100644 --- a/packages/steiger-plugin-fsd/src/repetitive-naming/index.ts +++ b/packages/steiger-plugin-fsd/src/repetitive-naming/index.ts @@ -35,7 +35,11 @@ const repetitiveNaming = { }, new Map()) 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}"` }) } }