-
-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathconfig-schema.ts
More file actions
85 lines (70 loc) · 4.96 KB
/
config-schema.ts
File metadata and controls
85 lines (70 loc) · 4.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import { z } from "zod"
export const SeveritySchema = z.enum(["error", "warning", "info", "hint"])
export const SeverityConfigSchema = z.union([
SeveritySchema,
z.object({ editor: SeveritySchema, cli: SeveritySchema }).strict()
])
export const FilesConfigSchema = z.object({
include: z.array(z.string()).optional().describe("Additional glob patterns to include beyond defaults (e.g., ['**/*.xml.erb', 'custom/**/*.html'])"),
exclude: z.array(z.string()).optional().describe("Glob patterns to exclude (e.g., ['node_modules/**/*', 'vendor/**/*', '**/*.html.erb'])"),
}).strict().optional()
const RuleConfigBaseSchema = z.object({
enabled: z.boolean().optional().describe("Whether the rule is enabled"),
severity: SeverityConfigSchema.optional().describe("Severity level for the rule"),
include: z.array(z.string()).optional().describe("Additional glob patterns to include for this rule (additive, ignored when 'only' is present)"),
only: z.array(z.string()).optional().describe("Only apply this rule to files matching these glob patterns (overrides all 'include' patterns)"),
exclude: z.array(z.string()).optional().describe("Don't apply this rule to files matching these glob patterns"),
})
export const RuleConfigSchema = RuleConfigBaseSchema.optional()
export const LinterConfigSchema = z.object({
enabled: z.boolean().optional().describe("Whether the linter is enabled"),
failLevel: SeveritySchema.optional().describe("Exit with error code when diagnostics of this severity or higher are present (e.g., 'warning' will fail on warnings and errors)"),
include: z.array(z.string()).optional().describe("Additional glob patterns to include beyond defaults (e.g., ['**/*.xml.erb', 'custom/**/*.html'])"),
exclude: z.array(z.string()).optional().describe("Glob patterns to exclude from linting"),
rules: z.record(z.string(), RuleConfigBaseSchema).optional().describe("Per-rule configuration"),
}).strict().optional()
const RewriterConfigSchema = z.object({
pre: z.array(z.string()).optional().describe("Pre-format rewriters to run (in order) before formatting the AST"),
post: z.array(z.string()).optional().describe("Post-format rewriters to run (in order) after formatting the document"),
}).strict().optional()
export const FormatterConfigSchema = z.object({
enabled: z.boolean().optional().describe("Whether the formatter is enabled"),
include: z.array(z.string()).optional().describe("Additional glob patterns to include beyond defaults (e.g., ['**/*.xml.erb', 'custom/**/*.html'])"),
exclude: z.array(z.string()).optional().describe("Glob patterns to exclude from formatting"),
indentWidth: z.number().int().positive().optional().describe("Number of spaces per indentation level"),
maxLineLength: z.number().int().positive().optional().describe("Maximum line length before wrapping"),
rewriter: RewriterConfigSchema.describe("Rewriter configuration for pre and post-format transformations"),
}).strict().optional()
export const ValidatorsConfigSchema = z.object({
security: z.boolean().optional().describe("Enable or disable the security validator (default: true)"),
nesting: z.boolean().optional().describe("Enable or disable the nesting validator (default: true)"),
accessibility: z.boolean().optional().describe("Enable or disable the accessibility validator (default: true)"),
}).strict().optional()
export const FrameworkSchema = z.enum(["ruby", "actionview", "hanami", "sinatra"]).optional()
.describe("Framework context (default: 'ruby')")
export const TemplateEngineSchema = z.enum(["erubi", "erb", "herb"]).optional()
.describe("Template engine used for compilation (default: 'erubi')")
export const ParserOptionsSchema = z.object({
strict: z.boolean().optional().describe("Enable strict parsing mode (default: true)"),
render_nodes: z.boolean().optional().describe("Enable render node detection"),
strict_locals: z.boolean().optional().describe("Enable strict locals detection"),
}).strict().optional()
export const EngineConfigSchema = z.object({
optimize: z.boolean().optional().describe("Enable compile-time optimizations (default: false)"),
debug: z.boolean().optional().describe("Enable debug mode (default: false)"),
parser_options: ParserOptionsSchema.describe("Parser options passed through to Herb.parse"),
validators: ValidatorsConfigSchema.describe("Per-validator enable/disable configuration"),
}).strict().optional()
export const HerbConfigSchema = z.object({
version: z.string().describe("Configuration file version"),
framework: FrameworkSchema,
template_engine: TemplateEngineSchema,
files: FilesConfigSchema.describe("Top-level file configuration"),
engine: EngineConfigSchema.describe("Engine configuration"),
linter: LinterConfigSchema,
formatter: FormatterConfigSchema,
}).strict()
export type HerbConfigSchemaType = z.infer<typeof HerbConfigSchema>
export type RuleConfigSchemaType = z.infer<typeof RuleConfigSchema>
export type FilesConfigSchemaType = z.infer<typeof FilesConfigSchema>
export type SeveritySchemaType = z.infer<typeof SeveritySchema>