From ded8bd3c409912e9412432f25a40a7cdd67b62ac Mon Sep 17 00:00:00 2001 From: Lev Chelyadinov Date: Thu, 13 Jun 2024 20:33:39 +0200 Subject: [PATCH] Stop demanding public API from the App layer --- .../src/public-api/README.md | 2 +- .../src/public-api/index.spec.ts | 28 +++++++++++++++++++ .../src/public-api/index.ts | 4 +++ packages/steiger/steiger.config.ts | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/steiger-plugin-fsd/src/public-api/README.md b/packages/steiger-plugin-fsd/src/public-api/README.md index fa0659b..18a65ea 100644 --- a/packages/steiger-plugin-fsd/src/public-api/README.md +++ b/packages/steiger-plugin-fsd/src/public-api/README.md @@ -1,6 +1,6 @@ # `public-api` -Require slices (and segments on sliceless layers like Shared) to have a public API definition. +Require slices (and segments on Shared) to have a public API definition. According to the _public API rule on slices_: diff --git a/packages/steiger-plugin-fsd/src/public-api/index.spec.ts b/packages/steiger-plugin-fsd/src/public-api/index.spec.ts index e4e7448..c1ce49e 100644 --- a/packages/steiger-plugin-fsd/src/public-api/index.spec.ts +++ b/packages/steiger-plugin-fsd/src/public-api/index.spec.ts @@ -130,3 +130,31 @@ it('reports errors on segments that are missing a public API', () => { }, ]) }) + +it('reports no errors when the App layer is missing a public API', () => { + const root = parseIntoFsdRoot(` + 📂 shared + 📂 ui + 📄 index.ts + 📂 entities + 📂 users + 📂 ui + 📄 index.ts + 📂 posts + 📂 ui + 📄 index.ts + 📂 features + 📂 comments + 📂 ui + 📄 index.ts + 📂 pages + 📂 editor + 📂 ui + 📄 index.ts + 📂 app + 📂 providers + 📂 styles + `) + + expect(publicApi.check(root, { sourceFileExtension: 'ts' })).toEqual({ diagnostics: [] }) +}) diff --git a/packages/steiger-plugin-fsd/src/public-api/index.ts b/packages/steiger-plugin-fsd/src/public-api/index.ts index b9645d0..e9043f3 100644 --- a/packages/steiger-plugin-fsd/src/public-api/index.ts +++ b/packages/steiger-plugin-fsd/src/public-api/index.ts @@ -11,6 +11,10 @@ const publicApi = { for (const [layerName, layer] of Object.entries(getLayers(root))) { if (!isSliced(layer)) { + if (layerName === 'app') { + // The app layer is the top-level layer, there's no need for public API. + continue + } for (const [segmentName, segment] of Object.entries(getSegments(layer))) { if (getIndex(segment) === undefined) { diagnostics.push({ diff --git a/packages/steiger/steiger.config.ts b/packages/steiger/steiger.config.ts index d5662bb..2f0dd2f 100644 --- a/packages/steiger/steiger.config.ts +++ b/packages/steiger/steiger.config.ts @@ -1,5 +1,5 @@ export default { rules: { - 'public-api': 'off', + // 'public-api': 'off', }, }