Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): preserve comments in the static analysis configuration file - IDE-2599 #472

Merged
merged 23 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6b96cb9
feat(config): preserve comments on modification and better formattting
robertohuertasm Jul 28, 2024
2efcdb3
fixed some tests
robertohuertasm Jul 28, 2024
ffecc0f
support for multiline comments
robertohuertasm Jul 28, 2024
f53b98e
tests passing - not complete
robertohuertasm Jul 28, 2024
c14708b
fixed issue with inline comments
robertohuertasm Jul 28, 2024
c5d1ee9
fixed issue with inline comments, prettify and tests
robertohuertasm Jul 28, 2024
8af29a9
added separated tests and removed lifetime
robertohuertasm Jul 29, 2024
5bceb07
warnings from clippy
robertohuertasm Jul 29, 2024
2932721
avoid passing the previous node
robertohuertasm Jul 29, 2024
1c5d537
comments and more tests
robertohuertasm Jul 29, 2024
4613d95
specification for inline comments
robertohuertasm Jul 29, 2024
21e0c76
fixed case for inline
robertohuertasm Jul 29, 2024
5d0b5f3
change name of test
robertohuertasm Jul 29, 2024
f3f9b94
new test case supported
robertohuertasm Jul 29, 2024
256d30a
another case covered and better docs
robertohuertasm Jul 29, 2024
50e11bb
improve comment detection
robertohuertasm Jul 29, 2024
56d503b
returning the serialized yaml even if formatting and reconciliation f…
robertohuertasm Jul 30, 2024
bca9165
better messaging
robertohuertasm Jul 30, 2024
174109e
remove null only from maps
robertohuertasm Jul 30, 2024
edb99ff
fixed some lint issues
robertohuertasm Jul 30, 2024
e077650
added dependency to 3rd party manifest
robertohuertasm Jul 31, 2024
b61e46c
avoid contains + insert
robertohuertasm Jul 31, 2024
23ecab2
Update LICENSE-3rdparty.csv
robertohuertasm Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default-members = [
"crates/cli",
"crates/static-analysis-kernel",
"crates/static-analysis-server",
"crates/secrets"
"crates/secrets",
]
resolver = "2"

Expand Down Expand Up @@ -39,3 +39,4 @@ sha2 = "0.10.7"
num_cpus = "1.15.0"
tracing = "0.1.40"
uuid = { version = "1.6.1", features = ["v4"] }
tree-sitter = "0.22.6"
1 change: 1 addition & 0 deletions LICENSE-3rdparty.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ num_cpus,https://github.com/seanmonstar/num_cpus,MIT, Copyright (c) 2015 Sean Mc
percent-encoding,https://github.com/servo/rust-url/,MIT, Copyright (c) 2013-2022 The rust-url developers
prettytable-rs,https://github.com/phsym/prettytable-rs/,BSD-3-Clause,Copyright (c) 2022 Pierre-Henri Symoneaux
rayon,https://crates.io/crates/rayon,MIT,Copyright (c) 2010 The Rust Project Developers
pretty_yaml,https://github.com/g-plane/pretty_yaml,MIT,Copyright (c) 2024-present Pig Fang
rocket,https://github.com/SergioBenitez/Rocket,Apache-2.0,Copyright 2016 Sergio Benitez
tree-sitter,https://github.com/tree-sitter/tree-sitter,MIT,2014 Max Brunsfeld
sarif-rs,https://github.com/psastras/sarif-rs,MIT,Copyright (c) 2021 Paul Sastrasinh
Expand Down
5 changes: 4 additions & 1 deletion crates/bins/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ serde_json = { workspace = true }
tracing = { workspace = true }
uuid = { workspace = true }
indexmap = { workspace = true }
num_cpus = { workspace = true}
num_cpus = { workspace = true }
serde = { workspace = true }
serde_yaml = { workspace = true }
tree-sitter = { workspace = true }

# other
terminal-emoji = "0.4.1"
getopts = "0.2.21"
Expand All @@ -59,6 +61,7 @@ rayon = "1.7.0"
rocket = { version = "=0.5.0", features = ["json"] }
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter"] }
thiserror = "1"
pretty_yaml = "0.4"
robertohuertasm marked this conversation as resolved.
Show resolved Hide resolved


# For linux and macos, we need the vendored ssl
Expand Down
2 changes: 1 addition & 1 deletion crates/bins/src/bin/datadog-static-analyzer-server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ mod datadog_static_analyzer_server;

#[rocket::main]
async fn main() {
datadog_static_analyzer_server::start().await
datadog_static_analyzer_server::start().await;
}
2 changes: 1 addition & 1 deletion crates/bins/src/bin/datadog-static-analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ fn main() -> Result<()> {
"Analyzing {}, {} files detected",
language,
files_for_language.len()
)
);
}

// take the relative path for the analysis
Expand Down
6 changes: 3 additions & 3 deletions crates/bins/src/bin/datadog_static_analyzer_server/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{env, process, thread};
use super::state::ServerState;
use super::utils::get_current_timestamp_ms;

fn print_usage(program: &str, opts: Options) {
fn print_usage(program: &str, opts: &Options) {
let brief = format!("Usage: {} [options]", program);
print!("{}", opts.usage(&brief));
}
Expand Down Expand Up @@ -61,7 +61,7 @@ pub fn prepare_rocket() -> (Rocket<Build>, ServerState, Sender<Shutdown>) {
}

if matches.opt_present("h") {
print_usage(&program, opts);
print_usage(&program, &opts);
process::exit(0);
}

Expand Down Expand Up @@ -122,7 +122,7 @@ pub fn prepare_rocket() -> (Rocket<Build>, ServerState, Sender<Shutdown>) {

if latest_timestamp > 0 && current_timestamp > latest_timestamp + timeout_ms {
eprintln!("exiting because of timeout, trying to exit gracefully");
shutdown_handle.clone().notify();
shutdown_handle.notify();
// we give 10 seconds for the process to terminate
// if it does not, we abort
thread::sleep(Duration::from_secs(10));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ async fn serve_static(

/// Catches all OPTION requests in order to get the CORS related Fairing triggered.
#[rocket::options("/<_..>")]
fn get_options() -> String {
const fn get_options() -> String {
/* Intentionally left empty */
"".to_string()
String::new()
}

/// Simple ping method that will return "pong" as response.
Expand Down
11 changes: 5 additions & 6 deletions crates/bins/src/bin/datadog_static_analyzer_server/fairings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ impl Fairing for KeepAlive {
}
}

/// Provides functionality to associate a UUIDv4 per request.
/// Provides functionality to associate a `UUIDv4` per request.
///
/// Rocket 0.5.0 does not generate per-request IDs (see: https://github.com/rwf2/Rocket/issues/21)
/// Rocket 0.5.0 does not generate per-request IDs (see: [#21](https://github.com/rwf2/Rocket/issues/21))
/// Until upstream natively supports this, we use a custom [Fairing] to generate one.
pub struct TracingFairing;

Expand All @@ -122,10 +122,10 @@ impl TraceSpan {
}
}

/// A newtype Option representing a [Span] that is used to conform to the [Request::local_cache] API
/// A newtype Option representing a [Span] that is used to conform to the [`Request::local_cache`] API
struct FairingTraceSpan(Option<Span>);

/// A newtype Option representing a [String] request ID that is used to conform to the [Request::local_cache] API
/// A newtype Option representing a [String] request ID that is used to conform to the [`Request::local_cache`] API
struct FairingRequestId(Option<String>);

#[rocket::async_trait]
Expand All @@ -141,8 +141,7 @@ impl Fairing for TracingFairing {
let request_id = req
.headers()
.get_one("X-Request-Id")
.map(String::from)
.unwrap_or_else(|| Uuid::new_v4().to_string());
.map_or_else(|| Uuid::new_v4().to_string(), String::from);

let request_span = tracing::info_span!(
"http_request",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod models;
mod reconciler;
pub use reconciler::{prettify_yaml, reconcile_comments, ReconcileError};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#[derive(Debug, Clone, Default)]
pub struct Line {
pub row: usize,
pub content: String,
}

impl Line {
pub const fn new(row: usize, content: String) -> Self {
Self { row, content }
}
}

#[derive(Debug, Clone)]
pub enum Comment {
Inline {
line: Line,
original_content: String,
},
Block {
line: Line,
above_line: Option<Line>,
below_line: Option<Line>,
},
}
Loading
Loading