Ruby: address comments

This commit is contained in:
Arthur Baars
2023-01-31 10:22:12 +01:00
parent 907ebb723e
commit d944c2bd79
2 changed files with 11 additions and 17 deletions

View File

@@ -36,7 +36,7 @@ pub struct Visibility {
pub telemetry: bool,
}
#[derive(Serialize, Clone)]
#[derive(Serialize, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct Location {
#[serde(skip_serializing_if = "Option::is_none")]
@@ -205,13 +205,7 @@ impl DiagnosticLoggers {
})
}
}
static EMPTY_LOCATION: Location = Location {
file: None,
start_line: None,
start_column: None,
end_line: None,
end_column: None,
};
impl DiagnosticMessage {
pub fn full_error_message(&self) -> String {
match &self.location {
@@ -270,7 +264,7 @@ impl DiagnosticMessage {
end_line: usize,
end_column: usize,
) -> &'a mut Self {
let loc = self.location.get_or_insert(EMPTY_LOCATION.to_owned());
let loc = self.location.get_or_insert(Default::default());
loc.file = Some(path.to_owned());
loc.start_line = Some(start_line);
loc.start_column = Some(start_column);

View File

@@ -67,12 +67,12 @@ fn main() -> std::io::Result<()> {
)
.init();
let diagnostics = diagnostics::DiagnosticLoggers::new("ruby");
let logger = &mut diagnostics.logger();
let main_thread_logger = &mut diagnostics.logger();
let num_threads = match num_codeql_threads() {
Ok(num) => num,
Err(e) => {
logger.write(
&logger
main_thread_logger.write(
&main_thread_logger
.message("configuration-error", "Configuration error")
.text(&format!("{}; defaulting to 1 thread.", e))
.status_page()
@@ -93,8 +93,8 @@ fn main() -> std::io::Result<()> {
let trap_compression = match trap::Compression::from_env("CODEQL_RUBY_TRAP_COMPRESSION") {
Ok(x) => x,
Err(e) => {
logger.write(
&logger
main_thread_logger.write(
&main_thread_logger
.message("configuration-error", "Configuration error")
.text(&format!("{}; using gzip.", e))
.status_page()
@@ -103,7 +103,7 @@ fn main() -> std::io::Result<()> {
trap::Compression::Gzip
}
};
drop(main_thread_logger);
rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build_global()
@@ -198,7 +198,7 @@ fn main() -> std::io::Result<()> {
Err(msg) => {
needs_conversion = false;
diagnostics_writer.write(
&logger
&diagnostics_writer
.message(
"character-encoding-error",
"Character encoding error",
@@ -217,7 +217,7 @@ fn main() -> std::io::Result<()> {
}
} else {
diagnostics_writer.write(
&logger
&diagnostics_writer
.message("character-encoding-error", "Character encoding error")
.text(&format!(
"{}: unknown character encoding: '{}'",