@avelonjs/bailiff 0.8.2 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/paths.ts +8 -10
- package/src/rules.ts +7 -2
- package/src/suppress.ts +1 -1
package/package.json
CHANGED
package/src/paths.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
-
import { dirname, join,
|
|
2
|
+
import { dirname, join, relative, sep } from 'node:path'
|
|
3
3
|
|
|
4
4
|
/** Layer a source file belongs to, used by architecture rules. */
|
|
5
5
|
export type FileLayer =
|
|
@@ -21,12 +21,7 @@ export type FileLayer =
|
|
|
21
21
|
| 'request'
|
|
22
22
|
| 'other'
|
|
23
23
|
|
|
24
|
-
const GENERATED_MARKERS = [
|
|
25
|
-
'/app/(web)/',
|
|
26
|
-
'/app/(api)/',
|
|
27
|
-
'/framework/routing/',
|
|
28
|
-
'/database/types.ts',
|
|
29
|
-
]
|
|
24
|
+
const GENERATED_MARKERS = ['/app/(web)/', '/app/(api)/']
|
|
30
25
|
|
|
31
26
|
const VENDOR_PACKAGES = [
|
|
32
27
|
'@supabase/supabase-js',
|
|
@@ -46,14 +41,17 @@ const VENDOR_PACKAGES = [
|
|
|
46
41
|
|
|
47
42
|
/** Normalizes a file path to posix so fixtures and Windows paths classify the same way. */
|
|
48
43
|
export function posixPath(filePath: string): string {
|
|
49
|
-
return filePath.
|
|
44
|
+
return filePath.replaceAll('\\', '/')
|
|
50
45
|
}
|
|
51
46
|
|
|
52
47
|
/** Returns true when `filePath` is framework-generated and must not be hand-edited. */
|
|
53
48
|
export function isGeneratedPath(filePath: string): boolean {
|
|
54
49
|
const normalized = posixPath(filePath)
|
|
55
50
|
if (GENERATED_MARKERS.some((marker) => normalized.includes(marker))) return true
|
|
56
|
-
return
|
|
51
|
+
return (
|
|
52
|
+
/\/framework\/routing\/[^/]+\.generated\.ts$/.test(normalized) ||
|
|
53
|
+
normalized.endsWith('/database/types.ts')
|
|
54
|
+
)
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
/** Returns true when the specifier is a known vendor SDK. */
|
|
@@ -61,7 +59,7 @@ export function isVendorSpecifier(specifier: string): boolean {
|
|
|
61
59
|
if (specifier.startsWith('@supabase/')) return true
|
|
62
60
|
if (specifier.startsWith('@aws-sdk/')) return true
|
|
63
61
|
if (specifier.startsWith('@neondatabase/')) return true
|
|
64
|
-
return VENDOR_PACKAGES.
|
|
62
|
+
return VENDOR_PACKAGES.some((name) => specifier === name || specifier.startsWith(`${name}/`))
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
/** Classifies a source file into the architecture layer Bailiff enforces. */
|
package/src/rules.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { posix } from 'node:path'
|
|
1
2
|
import type { Rule } from 'eslint'
|
|
2
3
|
|
|
3
4
|
interface Node {
|
|
@@ -18,6 +19,7 @@ import {
|
|
|
18
19
|
classifyFile,
|
|
19
20
|
isGeneratedPath,
|
|
20
21
|
isVendorSpecifier,
|
|
22
|
+
posixPath,
|
|
21
23
|
schemaColumns,
|
|
22
24
|
wardExists,
|
|
23
25
|
type FileLayer,
|
|
@@ -172,7 +174,7 @@ function ruleModule(
|
|
|
172
174
|
}
|
|
173
175
|
|
|
174
176
|
const noVendorImport = ruleModule('no-vendor-import', (context, layer) => ({
|
|
175
|
-
ImportDeclaration(node) {
|
|
177
|
+
'ImportDeclaration, ExportNamedDeclaration, ExportAllDeclaration, ImportExpression'(node: Node) {
|
|
176
178
|
const specifier = specifierOf(node as ImportLike)
|
|
177
179
|
if (specifier === undefined || !isVendorSpecifier(specifier) || allowsVendor(layer)) return
|
|
178
180
|
report(
|
|
@@ -186,7 +188,10 @@ const noVendorImport = ruleModule('no-vendor-import', (context, layer) => ({
|
|
|
186
188
|
|
|
187
189
|
const noCrossLayer = ruleModule('no-cross-layer', (context, layer) => ({
|
|
188
190
|
ImportDeclaration(node) {
|
|
189
|
-
const
|
|
191
|
+
const source = specifierOf(node as ImportLike) ?? ''
|
|
192
|
+
const specifier = source.startsWith('.')
|
|
193
|
+
? posix.resolve(posix.dirname(posixPath(context.filename)), source)
|
|
194
|
+
: source
|
|
190
195
|
if (layer === 'view' && specifier.includes('/Models/')) {
|
|
191
196
|
report(
|
|
192
197
|
context,
|
package/src/suppress.ts
CHANGED
|
@@ -39,7 +39,7 @@ export function isSuppressed(
|
|
|
39
39
|
const line = node.loc?.start.line
|
|
40
40
|
if (line === undefined) return false
|
|
41
41
|
return disableComments(context).some((comment) => {
|
|
42
|
-
if (comment.line !== line - 1
|
|
42
|
+
if (comment.line !== line - 1) return false
|
|
43
43
|
if (comment.reason === undefined) return false
|
|
44
44
|
return comment.rule === undefined || comment.rule === rule
|
|
45
45
|
})
|