-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add architectural lint rules #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlbertSmit
wants to merge
5
commits into
main
Choose a base branch
from
feature/architecture-rules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a27f60d
feat: add architectural lint rules (no-restricted-layer-import, no-ne…
AlbertSmit 42aecf1
fix: include shared root modules in default layer allow-lists
AlbertSmit 4f27a21
feat: add transitive universal nesting detection via esbuild metafile
AlbertSmit fa1335f
test: comprehensive import graph tests + fix JSXMemberExpression check
AlbertSmit 74104b3
refactor: extract layer helpers into machinery/filename.js
AlbertSmit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ node_modules/ | |
| .yarn-integrity | ||
| .DS_Store | ||
| .pnpm-store/ | ||
| .test-fixtures/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| const { readFileSync, existsSync } = require('node:fs') | ||
| const { join } = require('node:path') | ||
|
|
||
| module.exports = { getImportGraph, _resetCache } | ||
|
|
||
| let cached = null | ||
| let cachedRoot = null | ||
|
|
||
| /** | ||
| * Read the import graph from @kaliber/build's esbuild metafile. | ||
| * | ||
| * The metafile is written to `.kaliber-build/server-metafile.json` during | ||
| * build and (with a small @kaliber/build change) during watch mode. | ||
| * | ||
| * Returns null if no metafile exists yet (build hasn't run). | ||
| * | ||
| * @param {string} projectRoot | ||
| * @returns {{ transitiveDeps: (filePath: string) => Set<string>, findChain: (source: string, target: string) => string[] | null } | null} | ||
| */ | ||
| function getImportGraph(projectRoot) { | ||
| if (cached && cachedRoot === projectRoot) return cached | ||
|
|
||
| const metafilePath = join(projectRoot, '.kaliber-build', 'server-metafile.json') | ||
| if (!existsSync(metafilePath)) return null | ||
|
|
||
| try { | ||
| const metafile = JSON.parse(readFileSync(metafilePath, 'utf-8')) | ||
| cached = parseMetafile(metafile) | ||
| cachedRoot = projectRoot | ||
| return cached | ||
| } catch { | ||
| return null | ||
| } | ||
| } | ||
|
|
||
| /** @param {object} metafile — esbuild metafile with `inputs` */ | ||
| function parseMetafile(metafile) { | ||
| /** @type {Map<string, Set<string>>} filePath → direct dependencies */ | ||
| const graph = new Map() | ||
|
|
||
| for (const [filePath, info] of Object.entries(metafile.inputs || {})) { | ||
| const deps = new Set() | ||
| for (const imp of info.imports || []) { | ||
| if (imp.path && !imp.external) deps.add(imp.path) | ||
| } | ||
| graph.set(filePath, deps) | ||
| } | ||
|
|
||
| return { transitiveDeps, findChain } | ||
|
|
||
| /** Get ALL transitive dependencies of a file (BFS) */ | ||
| function transitiveDeps(filePath) { | ||
| const visited = new Set() | ||
| const queue = [filePath] | ||
|
|
||
| while (queue.length) { | ||
| const current = queue.pop() | ||
| if (visited.has(current)) continue | ||
| visited.add(current) | ||
| for (const dep of (graph.get(current) || [])) queue.push(dep) | ||
| } | ||
|
|
||
| visited.delete(filePath) | ||
| return visited | ||
| } | ||
|
|
||
| /** Find the shortest import chain from source to target (BFS) */ | ||
| function findChain(source, target) { | ||
| const queue = [[source]] | ||
| const visited = new Set([source]) | ||
|
|
||
| while (queue.length) { | ||
| const path = queue.shift() | ||
| const current = path[path.length - 1] | ||
|
|
||
| for (const dep of (graph.get(current) || [])) { | ||
| if (dep === target) return [...path, dep] | ||
| if (!visited.has(dep)) { | ||
| visited.add(dep) | ||
| queue.push([...path, dep]) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return null | ||
| } | ||
| } | ||
|
|
||
| /** Reset the module-level cache — used in tests */ | ||
| function _resetCache() { | ||
| cached = null | ||
| cachedRoot = null | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Module-level cache is never invalidated when the metafile changes.
The docstring states the metafile is rewritten during watch mode, but the cache is keyed only on
projectRootand persists for the lifetime of the process. In a long-lived ESLint session (editor/LSP or--watch), a rebuild that updatesserver-metafile.jsonwill not be picked up, so transitive-nesting results inno-universal-in-universalcan go stale until the process restarts.Consider invalidating on file mtime.
♻️ Possible approach using mtime
📝 Committable suggestion
🤖 Prompt for AI Agents