Skip to content

Commit 542c888

Browse files
committed
fix(no-orphaned-files): enhance reporting for flat structure violations by tracking reported subdirectories
1 parent a65e98a commit 542c888

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/rules/no-orphaned-files.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import path from 'node:path'
55
import { minimatch } from 'minimatch'
66
import { isTestFile } from '../utils/import-boundaries.js'
7+
import { createCheckedDirsGetter } from '../utils/global-state.js'
78

89
// Default configuration based on Vue project modules blueprint
910
const defaultOptions = {
@@ -358,6 +359,9 @@ export default {
358359
...(context.options[0] || {}),
359360
}
360361

362+
// Initialize global state to track reported subdirectories
363+
const getReportedSubdirs = createCheckedDirsGetter('no-orphaned-files-subdirs')
364+
361365
const filename = context.filename || context.getFilename()
362366

363367
// Skip files outside of src
@@ -394,6 +398,20 @@ export default {
394398
const orphanError = checkOrphanedFile(fileInfo, options.allowedDirectories, options.allowedRootFiles)
395399

396400
if (orphanError) {
401+
// For flat structure violations, only report once per subdirectory
402+
if (orphanError.message.includes('should have a flat structure')) {
403+
const subdirKey = `${fileInfo.category}/${fileInfo.subcategory}`
404+
const reportedSubdirs = getReportedSubdirs()
405+
406+
if (reportedSubdirs.has(subdirKey)) {
407+
// Already reported this subdirectory, skip
408+
return
409+
}
410+
411+
// Mark this subdirectory as reported
412+
reportedSubdirs.add(subdirKey)
413+
}
414+
397415
// Report main error
398416
context.report({
399417
loc: { line: 1, column: 0 },

0 commit comments

Comments
 (0)