Skip to content

Commit d944c2b

Browse files
committed
Ruby: address comments
1 parent 907ebb7 commit d944c2b

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

ruby/extractor/src/diagnostics.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct Visibility {
3636
pub telemetry: bool,
3737
}
3838

39-
#[derive(Serialize, Clone)]
39+
#[derive(Serialize, Clone, Default)]
4040
#[serde(rename_all = "camelCase")]
4141
pub struct Location {
4242
#[serde(skip_serializing_if = "Option::is_none")]
@@ -205,13 +205,7 @@ impl DiagnosticLoggers {
205205
})
206206
}
207207
}
208-
static EMPTY_LOCATION: Location = Location {
209-
file: None,
210-
start_line: None,
211-
start_column: None,
212-
end_line: None,
213-
end_column: None,
214-
};
208+
215209
impl DiagnosticMessage {
216210
pub fn full_error_message(&self) -> String {
217211
match &self.location {
@@ -270,7 +264,7 @@ impl DiagnosticMessage {
270264
end_line: usize,
271265
end_column: usize,
272266
) -> &'a mut Self {
273-
let loc = self.location.get_or_insert(EMPTY_LOCATION.to_owned());
267+
let loc = self.location.get_or_insert(Default::default());
274268
loc.file = Some(path.to_owned());
275269
loc.start_line = Some(start_line);
276270
loc.start_column = Some(start_column);

ruby/extractor/src/main.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ fn main() -> std::io::Result<()> {
6767
)
6868
.init();
6969
let diagnostics = diagnostics::DiagnosticLoggers::new("ruby");
70-
let logger = &mut diagnostics.logger();
70+
let main_thread_logger = &mut diagnostics.logger();
7171
let num_threads = match num_codeql_threads() {
7272
Ok(num) => num,
7373
Err(e) => {
74-
logger.write(
75-
&logger
74+
main_thread_logger.write(
75+
&main_thread_logger
7676
.message("configuration-error", "Configuration error")
7777
.text(&format!("{}; defaulting to 1 thread.", e))
7878
.status_page()
@@ -93,8 +93,8 @@ fn main() -> std::io::Result<()> {
9393
let trap_compression = match trap::Compression::from_env("CODEQL_RUBY_TRAP_COMPRESSION") {
9494
Ok(x) => x,
9595
Err(e) => {
96-
logger.write(
97-
&logger
96+
main_thread_logger.write(
97+
&main_thread_logger
9898
.message("configuration-error", "Configuration error")
9999
.text(&format!("{}; using gzip.", e))
100100
.status_page()
@@ -103,7 +103,7 @@ fn main() -> std::io::Result<()> {
103103
trap::Compression::Gzip
104104
}
105105
};
106-
106+
drop(main_thread_logger);
107107
rayon::ThreadPoolBuilder::new()
108108
.num_threads(num_threads)
109109
.build_global()
@@ -198,7 +198,7 @@ fn main() -> std::io::Result<()> {
198198
Err(msg) => {
199199
needs_conversion = false;
200200
diagnostics_writer.write(
201-
&logger
201+
&diagnostics_writer
202202
.message(
203203
"character-encoding-error",
204204
"Character encoding error",
@@ -217,7 +217,7 @@ fn main() -> std::io::Result<()> {
217217
}
218218
} else {
219219
diagnostics_writer.write(
220-
&logger
220+
&diagnostics_writer
221221
.message("character-encoding-error", "Character encoding error")
222222
.text(&format!(
223223
"{}: unknown character encoding: '{}'",

0 commit comments

Comments
 (0)