MCPcopy
hub / github.com/google-labs-code/design.md / lint

Function lint

packages/cli/src/linter/lint.ts:56–111  ·  view source on GitHub ↗
(content: string, options?: LintOptions)

Source from the content-addressed store, hash-verified

54 * @throws If parsing or model resolution fails unrecoverably
55 */
56export function lint(content: string, options?: LintOptions): LintReport {
57 const parser = new ParserHandler();
58 const model = new ModelHandler();
59 const tailwind = new TailwindEmitterHandler();
60
61 const parseResult = parser.execute({ content });
62
63 // Handle parse failures gracefully
64 if (!parseResult.success) {
65 // For recoverable errors (e.g. no YAML found), return a report
66 // with an empty design system and a finding instead of throwing.
67 if (parseResult.error.recoverable) {
68 const emptyParsed: ParsedDesignSystem = { sourceMap: new Map() };
69 const { designSystem } = model.execute(emptyParsed);
70
71 // Still extract sections from the raw content even without YAML
72 const sections = extractSectionsFromContent(content);
73
74 return {
75 designSystem,
76 findings: [{
77 severity: 'warning',
78 message: parseResult.error.message,
79 }],
80 summary: { errors: 0, warnings: 1, infos: 0 },
81 tailwindConfig: tailwind.execute(designSystem),
82 sections: sections.map(s => s.heading).filter(Boolean),
83 documentSections: sections,
84 };
85 }
86
87 // Non-recoverable errors are still fatal
88 throw new Error(`Parse failed: ${parseResult.error.message}`);
89 }
90
91 const { designSystem, findings: modelFindings } = model.execute(parseResult.data);
92 const lintResult = runLinter(designSystem, options?.rules);
93 const tailwindConfig = tailwind.execute(designSystem);
94
95 const findings = [...modelFindings, ...lintResult.findings];
96 const summary = {
97 errors: modelFindings.filter((d) => d.severity === 'error').length + lintResult.summary.errors,
98 warnings: modelFindings.filter((d) => d.severity === 'warning').length + lintResult.summary.warnings,
99 infos: modelFindings.filter((d) => d.severity === 'info').length + lintResult.summary.infos,
100 };
101
102 return {
103 designSystem,
104 findings,
105 summary,
106 tailwindConfig,
107 sections: parseResult.data.sections ?? [],
108 documentSections: parseResult.data.documentSections ?? [],
109 };
110
111}
112
113/**

Callers 8

index.test.tsFile · 0.85
fixture.test.tsFile · 0.85
fixture.test.tsFile · 0.85
runFunction · 0.85
runFunction · 0.85
runFunction · 0.85
diff.test.tsFile · 0.85

Calls 5

executeMethod · 0.95
executeMethod · 0.95
executeMethod · 0.95
runLinterFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…