openpencil/tools/lint/src/support/context.ts
Danila Poyarkov 9bb9478833
refactor: replace complex conditional object spreads
- Add a typed, modular custom Oxlint rule package with direct regression coverage
- Replace complex conditional object spreads with explicit construction across the repository
- Preserve all existing custom rule registrations and diagnostic behavior
2026-09-01 19:49:57 +03:00

32 lines
966 B
TypeScript

import type { TSESTree } from '@typescript-eslint/utils'
export function normalizedPath(path: string): string {
return path.replaceAll('\\', '/')
}
export interface FilenameContext {
filename?: string
physicalFilename?: string
getFilename?: () => string
}
export function normalizedFilename(context: FilenameContext): string {
return normalizedPath(
context.physicalFilename ?? context.filename ?? context.getFilename?.() ?? ''
)
}
export function staticPropertyName(
property: TSESTree.Expression | TSESTree.PrivateIdentifier
): string | null {
if (property.type === 'Identifier') return property.name
if (property.type === 'Literal' && typeof property.value === 'string') return property.value
return null
}
export function importSource(
node: TSESTree.ImportDeclaration | TSESTree.ExportAllDeclaration | TSESTree.ExportNamedDeclaration
): string | null {
return typeof node.source?.value === 'string' ? node.source.value : null
}