Integrating Rust's compiler and linter (clippy) output into SonarCloud

  • Using GitHub for SCM
  • Jenkins ver. 2.226
  • Repositories in Rust language

AFAIK both Rust and Elixir (a different story for next weeks) are not (yet) supported in SonarQube nor in SonarCloud, but it seems that we might get at least rust’s compiler and linter (clippy) output as an input for Sonar analysis.

If that’s actually possible, has one achieved it yet? If not, could anyone please point in the right direction for us to achieve such a goal?

2 Likes

Hello,

Did you try to load your results by converting them into the Generic Issue Data format?

Alex

2 Likes

Thanks Alexandre, it’s a good approach but needs both a parser from the output we have and a converter into the required format, which don’t seem to available at all, so I guess we might have to build it, but time is crucial these COVID-19 days (war-like scenario) I doubt if we could spare some time for such, unfortunately. :frowning:

If this is in the context of COVID-19, things are differents, I may help on that field.

Can you share a link to the format generated by clippy and an example of an actual output so I can play with it?

Alexandre, I meant how COVID has changed our company, our performance, and our projects. Unfortunately, this is not related to any studies regarding the virus or alike.

Nevertheless, I’m still sharing a sample Clippy output:

warning: module has the same name as its containing module
 --> src/strategies/legacy_live_view/mod.rs:1:1
  |
1 | pub mod legacy_live_view;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(clippy::module_inception)]` on by default
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception

warning: module has the same name as its containing module
 --> src/strategies/data_source_live_view/mod.rs:1:1
  |
1 | pub mod data_source_live_view;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception

warning: module has the same name as its containing module
 --> src/strategies/business_events/mod.rs:1:1
  |
1 | pub mod business_events;
  | ^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#module_inception

warning: writing `&String` instead of `&str` involves a new object where a slice will do.
  --> src/rts_service_strategy.rs:25:37
   |
25 |     fn get_ids(&self, client_token: &String) -> Result<Vec<String>, Error>;
   |                                     ^^^^^^^ help: change this to: `&str`
   |
   = note: `#[warn(clippy::ptr_arg)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&String` instead of `&str` involves a new object where a slice will do.
  --> src/rts_service_strategy.rs:27:34
   |
27 |     fn get_id_summary(&self, id: &String) -> Result<IdSummary, Error>;
   |                                  ^^^^^^^ help: change this to: `&str`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
  --> src/rts_service_strategy.rs:29:36
   |
29 |     fn get_ids_summary(&self, ids: &Vec<String>) -> Result<Vec<IdSummary>, Error>;
   |                                    ^^^^^^^^^^^^ help: change this to: `&[String]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: using `clone` on a `Copy` type
  --> src/strategies/legacy_live_view/legacy_live_view.rs:48:9
   |
48 |         self.timeout.clone()
   |         ^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.timeout`
   |
   = note: `#[warn(clippy::clone_on_copy)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: single-character string constant used as pattern
  --> src/strategies/legacy_live_view/legacy_live_view.rs:73:34
   |
73 |         let id_values = id.split("_").collect::<Vec<&str>>();
   |                                  ^^^ help: try using a `char` instead: `'_'`
   |
   = note: `#[warn(clippy::single_char_pattern)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: single-character string constant used as pattern
   --> src/strategies/legacy_live_view/legacy_live_view.rs:107:22
    |
107 |             id.split("_").collect::<Vec<&str>>()
    |                      ^^^ help: try using a `char` instead: `'_'`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:102:41
    |
102 | ...                   start_time: start_time.clone() as usize,
    |                                   ^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:103:40
    |
103 | ...                   last_time: end_time.clone() as usize,
    |                                  ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:104:40
    |
104 | ...                   trip_time: duration.clone() as usize,
    |                                  ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*duration`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:106:38
    |
106 | ...                   lat: start_lat.clone(),
    |                            ^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:107:38
    |
107 | ...                   lon: start_lng.clone()
    |                            ^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:110:38
    |
110 | ...                   lat: end_lat.clone(),
    |                            ^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:111:38
    |
111 | ...                   lon: end_lng.clone()
    |                            ^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:113:44
    |
113 | ...                   trip_distance: distance.clone(),
    |                                      ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*distance`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:120:41
    |
120 | ...                   start_time: start_time.clone() as usize,
    |                                   ^^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:121:40
    |
121 | ...                   last_time: end_time.clone() as usize,
    |                                  ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:122:40
    |
122 | ...                   trip_time: duration.clone() as usize,
    |                                  ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*duration`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:124:38
    |
124 | ...                   lat: start_lat.clone(),
    |                            ^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:125:38
    |
125 | ...                   lon: start_lng.clone()
    |                            ^^^^^^^^^^^^^^^^^ help: try dereferencing it: `*start_lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:128:38
    |
128 | ...                   lat: end_lat.clone(),
    |                            ^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:129:38
    |
129 | ...                   lon: end_lng.clone()
    |                            ^^^^^^^^^^^^^^^ help: try dereferencing it: `*end_lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:131:44
    |
131 | ...                   trip_distance: distance.clone(),
    |                                      ^^^^^^^^^^^^^^^^ help: try dereferencing it: `*distance`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:148:52
    |
148 | ...                   time: Some(data_point.time.clone() as usize),
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `data_point.time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:150:50
    |
150 | ...                   lat: lat.clone(),
    |                            ^^^^^^^^^^^ help: try dereferencing it: `*lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:151:50
    |
151 | ...                   lon: lng.clone()
    |                            ^^^^^^^^^^^ help: try dereferencing it: `*lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:153:53
    |
153 | ...                   speed: Some(speed.clone() as usize),
    |                                   ^^^^^^^^^^^^^ help: try dereferencing it: `*speed`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:154:53
    |
154 | ...                   h_dop: Some(h_dop.clone() as usize),
    |                                   ^^^^^^^^^^^^^ help: try dereferencing it: `*h_dop`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:155:55
    |
155 | ...                   sat_num: Some(sat_num.clone() as usize)
    |                                     ^^^^^^^^^^^^^^^ help: try dereferencing it: `*sat_num`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:163:52
    |
163 | ...                   time: Some(data_point.time.clone() as usize),
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `data_point.time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:165:53
    |
165 | ...                   speed: Some(speed.clone() as usize),
    |                                   ^^^^^^^^^^^^^ help: try dereferencing it: `*speed`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:175:52
    |
175 | ...                   time: Some(data_point.time.clone() as usize),
    |                                  ^^^^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `data_point.time`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:177:50
    |
177 | ...                   lat: lat.clone(),
    |                            ^^^^^^^^^^^ help: try dereferencing it: `*lat`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:178:50
    |
178 | ...                   lon: lng.clone()
    |                            ^^^^^^^^^^^ help: try dereferencing it: `*lng`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:181:53
    |
181 | ...                   h_dop: Some(h_dop.clone() as usize),
    |                                   ^^^^^^^^^^^^^ help: try dereferencing it: `*h_dop`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: using `clone` on a `Copy` type
   --> src/strategies/legacy_live_view/data_summary.rs:182:55
    |
182 | ...                   sat_num: Some(sat_num.clone() as usize)
    |                                     ^^^^^^^^^^^^^^^ help: try dereferencing it: `*sat_num`
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: useless use of `format!`
   --> src/strategies/legacy_live_view/data_summary.rs:193:38
    |
193 |                 Err(failure::err_msg(format!("Error converting to legacy data package")))
    |                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `.to_string()`: `"Error converting to legacy data package".to_string()`
    |
    = note: `#[warn(clippy::useless_format)]` on by default
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_format

warning: using `clone` on a `Copy` type
  --> src/strategies/data_source_live_view/data_source_live_view.rs:46:9
   |
46 |         self.timeout.clone()
   |         ^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.timeout`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: single-character string constant used as pattern
  --> src/strategies/data_source_live_view/data_source_live_view.rs:71:34
   |
71 |         let id_values = id.split("_").collect::<Vec<&str>>();
   |                                  ^^^ help: try using a `char` instead: `'_'`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: single-character string constant used as pattern
  --> src/strategies/data_source_live_view/data_source_live_view.rs:97:22
   |
97 |             id.split("_").collect::<Vec<&str>>()
   |                      ^^^ help: try using a `char` instead: `'_'`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern

warning: using `clone` on a `Copy` type
  --> src/strategies/business_events/business_events.rs:38:9
   |
38 |         self.timeout.clone()
   |         ^^^^^^^^^^^^^^^^^^^^ help: try removing the `clone` call: `self.timeout`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#clone_on_copy

warning: redundant clone
  --> src/strategies/business_events/business_events.rs:92:43
   |
92 |             events: vec![notification.data.clone()]
   |                                           ^^^^^^^^ help: remove this
   |
   = note: `#[warn(clippy::redundant_clone)]` on by default
note: this value is dropped without further use
  --> src/strategies/business_events/business_events.rs:92:26
   |
92 |             events: vec![notification.data.clone()]
   |                          ^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

warning: writing `&String` instead of `&str` involves a new object where a slice will do.
  --> src/rts_service.rs:28:41
   |
28 |     pub fn get_ids(&self, client_token: &String) -> Result<Vec<String>, Error>{
   |                                         ^^^^^^^ help: change this to: `&str`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&String` instead of `&str` involves a new object where a slice will do.
  --> src/rts_service.rs:32:38
   |
32 |     pub fn get_id_summary(&self, id: &String) -> Result<IdSummary, Error>{
   |                                      ^^^^^^^ help: change this to: `&str`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

warning: writing `&Vec<_>` instead of `&[_]` involves one more reference and cannot be used with non-Vec-based slices.
  --> src/rts_service.rs:36:40
   |
36 |     pub fn get_ids_summary(&self, ids: &Vec<String>) -> Result<Vec<IdSummary>, Error>{
   |                                        ^^^^^^^^^^^^ help: change this to: `&[String]`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg

    Finished dev [unoptimized + debuginfo] target(s) in 0.17s

Hello,

Your last message confirm what I found myself: rust-clippy only generates its results in the console and there is no option to ask rust-clippy to generate a JSON file.

I won’t personally engage myself into a project to parse the raw output of rust-clippy that may change without notice but the best would be to ask the guys of rust-clippy to support output formats such:

Alex

Thanks @Alexandre_Gigleux I’ll check your suggestions

Clippy has option --message-format json that maybe could help.

1 Like

@Alexandre_Gigleux, could the JSON format, that @PaberGraham talk about, help to integrate Clippy lints in SonarCloud? I’m interested on it also.

Hello,

I’ve got a doubt it will be possible to integrate Clippy data into SonarCloud today, mainly because SonarCloud doesn’t know the language Rust at all, so I don’t know how it would look like (no syntax highlighting for example). All in all, I believe we should work together to collect your needs as Rust developers and at some point move forward and really support the language in SonarCloud. For that, don’t hesitate to express your needs such as rules (bugs? code smells? security?), coverage tool, IDE you would expect us to support as entries in https://community.sonarsource.com/c/suggestions/12

Alex