Skip to content

Commit 502ea28

Browse files
committed
fix: rules check
1 parent 97dd5a3 commit 502ea28

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

xtask/rules_check/src/lib.rs

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -127,34 +127,51 @@ fn assert_lint(
127127
});
128128

129129
// split and parse each statement
130-
let stmts = pglt_statement_splitter::split(code);
131-
for stmt in stmts.ranges {
132-
match pglt_query_ext::parse(&code[stmt]) {
133-
Ok(ast) => {
134-
for rule_diag in analyser.run(pglt_analyser::AnalyserContext { root: &ast }) {
135-
let diag = pglt_diagnostics::serde::Diagnostic::new(rule_diag);
136-
137-
let category = diag.category().expect("linter diagnostic has no code");
138-
let severity = settings.get_severity_from_rule_code(category).expect(
130+
match pglt_statement_splitter::split(code) {
131+
Ok(stmts) => {
132+
for stmt in stmts.ranges {
133+
match pglt_query_ext::parse(&code[stmt]) {
134+
Ok(ast) => {
135+
for rule_diag in analyser.run(pglt_analyser::AnalyserContext { root: &ast })
136+
{
137+
let diag = pglt_diagnostics::serde::Diagnostic::new(rule_diag);
138+
139+
let category = diag.category().expect("linter diagnostic has no code");
140+
let severity = settings.get_severity_from_rule_code(category).expect(
139141
"If you see this error, it means you need to run cargo codegen-configuration",
140142
);
141143

142-
let error = diag
143-
.with_severity(severity)
144-
.with_file_path(&file_path)
145-
.with_file_source_code(code);
146-
147-
write_diagnostic(code, error)?;
148-
}
144+
let error = diag
145+
.with_severity(severity)
146+
.with_file_path(&file_path)
147+
.with_file_source_code(code);
148+
149+
write_diagnostic(code, error)?;
150+
}
151+
}
152+
Err(e) => {
153+
let error = SyntaxDiagnostic::from(e)
154+
.with_file_path(&file_path)
155+
.with_file_source_code(code);
156+
write_diagnostic(code, error)?;
157+
}
158+
};
149159
}
150-
Err(e) => {
151-
let error = SyntaxDiagnostic::from(e)
152-
.with_file_path(&file_path)
153-
.with_file_source_code(code);
154-
write_diagnostic(code, error)?;
160+
}
161+
Err(errs) => {
162+
// Print all diagnostics to help the user
163+
let mut console = pglt_console::EnvConsole::default();
164+
for err in errs {
165+
console.println(
166+
pglt_console::LogLevel::Error,
167+
markup! {
168+
{PrintDiagnostic::verbose(&err)}
169+
},
170+
);
155171
}
156-
};
157-
}
172+
bail!("Analysis of '{group}/{rule}' on the following code block returned a scan diagnostic.\n\n{code}");
173+
}
174+
};
158175

159176
Ok(())
160177
}

0 commit comments

Comments
 (0)