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

Add rust-clippy bear for rust support #50

Open
sils opened this issue Feb 21, 2016 · 14 comments
Open

Add rust-clippy bear for rust support #50

sils opened this issue Feb 21, 2016 · 14 comments

Comments

@sils
Copy link
Member

sils commented Feb 21, 2016

From @sudheesh001 on February 8, 2016 19:19

Rust clippy is one of the linters for rustc the Rust programming language.
https://github.com/Manishearth/rust-clippy#usage

It gives the linter warning in the following format

src/main.rs:8:5: 11:6 warning: you seem to be trying to use match for destructuring a single type. Consider using `if let`, #[warn(single_match)] on by default
src/main.rs:8     match x {
src/main.rs:9         Some(y) => println!("{:?}", y),
src/main.rs:10         _ => ()
src/main.rs:11     }
src/main.rs:8:5: 11:6 help: Try
if let Some(y) = x { println!("{:?}", y) }

Copied from original issue: coala/coala#1324

@sils
Copy link
Member Author

sils commented Feb 21, 2016

@sudheesh001 does it support another output

@sils
Copy link
Member Author

sils commented Feb 21, 2016

From @AbdealiJK on February 9, 2016 1:44

You may want to try rustc and cargo as Atom and Sublime already made that plugin and it'd be much easier to implement (as we have the regex) - https://github.com/AtomLinter/linter-rust and https://github.com/oschwald/SublimeLinter-contrib-rustc

http://atomlinter.github.io/ is a list of all available atom linters

@sils
Copy link
Member Author

sils commented Feb 21, 2016

From @sudheesh001 on February 13, 2016 8:16

I think this can be parked for some time, rust-clippy works only on the nightly builds of rustc, Do we really want to download the binaries / compile rustc as a part of our build procedure to run this ? I've asked Manish, the repo owner for rust-clippy for a workaround to this.

@sils
Copy link
Member Author

sils commented Feb 21, 2016

@sudheesh001 can you give a link to the upstream bug?

@sils
Copy link
Member Author

sils commented Feb 21, 2016

From @sudheesh001 on February 13, 2016 13:2

@sils1297 Its not a bug, its in their documentation itself https://github.com/Manishearth/rust-clippy#usage for the nightly only support

@rubdos
Copy link

rubdos commented Feb 26, 2017

Hi people,
Does coala still want this? I know I do.

From @sudheesh001 on February 13, 2016 8:16

I think this can be parked for some time, rust-clippy works only on the nightly builds of rustc, Do we really want to download the binaries / compile rustc as a part of our build procedure to run this ? I've asked Manish, the repo owner for rust-clippy for a workaround to this.

Does this still count? I'd suppose it does. If so, would it be better to have an external Bear for this? (Is that already possible?) In any case, in the end, I would love to have it in the official Docker image (gitlab ci)... Which would of course enlarge the Docker image by a huge amount.

@rubdos
Copy link

rubdos commented Feb 26, 2017

Also: am I the best link between Rust and coala atm? Because I think that that link is very weak :D

@rubdos
Copy link

rubdos commented Feb 27, 2017

@sils:

@sudheesh001 does it support another output

It does:

% cargo clippy --quiet --color never -- -Z unstable-options --error-format json                     :(
{"message":"function is never used: `testssss`","code":null,"level":"warning","spans":[{"file_name":"src/lib.rs","byte_start":0,"byte_end":17,"line_start":1,"line_end":2,"column_start":1,"column_end":2,"is_primary":true,"text":[{"text":"fn testssss() {","highlight_start":1,"highlight_end":16},{"text":"}","highlight_start":1,"highlight_end":2}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"#[warn(dead_code)] on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":null}

The json:

Short example (unused function)
{
   "message":"function is never used: `testssss`",
   "code":null,
   "level":"warning",
   "spans":[
      {
         "file_name":"src/lib.rs",
         "byte_start":0,
         "byte_end":17,
         "line_start":1,
         "line_end":2,
         "column_start":1,
         "column_end":2,
         "is_primary":true,
         "text":[
            {
               "text":"fn testssss() {",
               "highlight_start":1,
               "highlight_end":16
            },
            {
               "text":"}",
               "highlight_start":1,
               "highlight_end":2
            }
         ],
         "label":null,
         "suggested_replacement":null,
         "expansion":null
      }
   ],
   "children":[
      {
         "message":"#[warn(dead_code)] on by default",
         "code":null,
         "level":"note",
         "spans":[

         ],
         "children":[

         ],
         "rendered":null
      }
   ],
   "rendered":null
}
Longer example (Rust specific, with suggestion)
{
   "message":"you seem to be trying to use match for destructuring a single pattern. Consider using `if let`",
   "code":null,
   "level":"warning",
   "spans":[
      {
         "file_name":"src/lib.rs",
         "byte_start":110,
         "byte_end":193,
         "line_start":8,
         "line_end":11,
         "column_start":9,
         "column_end":10,
         "is_primary":true,
         "text":[
            {
               "text":"        match x {",
               "highlight_start":9,
               "highlight_end":18
            },
            {
               "text":"            Some(y) => println!(\"{:?}\", y),",
               "highlight_start":1,
               "highlight_end":44
            },
            {
               "text":"            _ => ()",
               "highlight_start":1,
               "highlight_end":20
            },
            {
               "text":"        }",
               "highlight_start":1,
               "highlight_end":10
            }
         ],
         "label":null,
         "suggested_replacement":null,
         "expansion":null
      }
   ],
   "children":[
      {
         "message":"#[warn(single_match)] on by default",
         "code":null,
         "level":"note",
         "spans":[

         ],
         "children":[

         ],
         "rendered":null
      },
      {
         "message":"try this",
         "code":null,
         "level":"help",
         "spans":[
            {
               "file_name":"src/lib.rs",
               "byte_start":110,
               "byte_end":193,
               "line_start":8,
               "line_end":11,
               "column_start":9,
               "column_end":10,
               "is_primary":true,
               "text":[
                  {
                     "text":"        match x {",
                     "highlight_start":9,
                     "highlight_end":18
                  },
                  {
                     "text":"            Some(y) => println!(\"{:?}\", y),",
                     "highlight_start":1,
                     "highlight_end":44
                  },
                  {
                     "text":"            _ => ()",
                     "highlight_start":1,
                     "highlight_end":20
                  },
                  {
                     "text":"        }",
                     "highlight_start":1,
                     "highlight_end":10
                  }
               ],
               "label":null,
               "suggested_replacement":"if let Some(y) = x { $ crate :: io :: _print ( format_args ! ( $ ( $ arg ) * ) ) }",
               "expansion":null
            }
         ],
         "children":[

         ],
         "rendered":"        if let Some(y) = x { $ crate :: io :: _print ( format_args ! ( $ ( $ arg ) * ) ) }"
      },
      {
         "message":"for further information visit https://github.com/Manishearth/rust-clippy/wiki#single_match",
         "code":null,
         "level":"help",
         "spans":[

         ],
         "children":[

         ],
         "rendered":null
      }
   ],
   "rendered":null
}

Please not that the suggested replacement in this case is bad code;
it contains expanded macro's. The correct replacement would be

if let Some(y) = x {
    println!("{:?}", y)
}

which is correctly set out in their README.md

The command used:

cargo clippy --quiet --color never -- -Z unstable-options --error-format json --test

breakdown:

  • cargo the build tool in rust
  • clippy the linter, compiled as a plugin for cargo, installed using cargo install linter. Needs Rust nightly because of reasons.
  • --quiet so it won't tell useless stuff like Finished dev [unoptimized + debuginfo] target(s) in 0.10 secs
  • --color never obvious
  • -Z unstable-options --error-format json apparently, --error-format is an unstable option.
  • --test includes tests in the compile process, and thus clippy lints tests. Without it, it doesn't lint tests.

Also note that the linter produces one JSON document per line of output.

@rubdos
Copy link

rubdos commented Feb 27, 2017

Useful for this issue: coala/coala#3652

@rubdos rubdos mentioned this issue Feb 27, 2017
4 tasks
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 27, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 27, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Feb 28, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Mar 1, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 20, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 21, 2017
rubdos added a commit to rubdos/coala-bears that referenced this issue Jul 22, 2017
gitmate-bot pushed a commit to rubdos/coala-bears that referenced this issue Oct 16, 2017
@Makman2
Copy link
Member

Makman2 commented Jan 22, 2018

Reassigning due to inactivity.

@Makman2
Copy link
Member

Makman2 commented Mar 17, 2018

Unassigning due to inactivity.

@nvzard
Copy link
Member

nvzard commented Mar 17, 2018

I haven't pushed the changes yet, I was testing the rust clippy linter locally with regex. Sorry I got busy with other issue and exams, didn't got much time to work on this one.

@Mixih
Copy link
Member

Mixih commented Apr 28, 2018

Assigned as a part of GSoC project "Improve Linter Bears". Do not reassign for the duration of the coding period unless the assignee releases the issue themselves.

@rubdos
Copy link

rubdos commented Apr 30, 2018

Assigned as a part of GSoC project "Improve Linter Bears". Do not reassign for the duration of the coding period unless the assignee releases the issue themselves.

Feel free to ping me on Gitter for advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

7 participants