-
Notifications
You must be signed in to change notification settings - Fork 10
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
Split the crates into a bin and a lib, within the cargo-scout wor… #61
Conversation
d63027f
to
4283b7f
Compare
4283b7f
to
4349641
Compare
d6aadc8
to
b494b19
Compare
b494b19
to
63a1470
Compare
63a1470
to
42ccd2c
Compare
42ccd2c
to
90fa141
Compare
Looking good! If it's OK I'll take a look later in the day when I have some free time :) |
Sure no problem, take your time :) |
90fa141
to
ce571d1
Compare
ce571d1
to
4bd8327
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! I think this is a great improvement regarding separation of concerns. The code grew a bit in complexity, but I think it's worth it to accomodate the possibility of being more general than just running clippy on rust files. Also, having documentation now makes the code more accessible 👍
One last remark, the src/
directory in the root should be removed.
cargo-scout-lib/src/config/rust.rs
Outdated
} | ||
|
||
impl CargoConfig { | ||
/// This function will instanciate a Config from a Cargo.toml path. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should be "instantiate"
cargo-scout-lib/src/config/rust.rs
Outdated
use crate::config::Config; | ||
use serde::Deserialize; | ||
|
||
#[derive(Deserialize, PartialEq, Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deserialize
, PartialEq
and Clone
seem unused. Maybe it's done for forward compatibility?
/// assert_eq!(vec!["cargo-scout".to_string(), "cargo-scout-lib".to_string()], config.get_members()); | ||
/// # Ok::<(), cargo_scout_lib::error::Error>(()) | ||
/// ``` | ||
pub fn from_manifest_path(p: impl AsRef<std::path::Path>) -> Result<Self, crate::error::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not importing Path
? Same for Manifest
. For the error, I think cargo_scout_lib::Error
would be more idiomatic (like std does for io::Error
within io
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As explained in this pretty cool blog post AsRef allows the function to accept anything that allows a Path to be borrowed from it. So it allows us to automagically get a Path from a String, which I think is pretty cool !
pub use error::Error; is a great idea !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cool indeed!
I meant why don't we do
use std::path::Path;
... AsRef<Path>
Instead of using the fully qualified path. Just for consistency with other cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry I didn’t understand that’s what you meant!
Since it’s fairly easy to accomplish, and it’s not that critical, let’s mark it as a good first pull request, so someone new to rust and open source might be able to grab it !
cargo-scout-lib/src/config/mod.rs
Outdated
/// } | ||
/// } | ||
/// ``` | ||
fn get_members(&self) -> Vec<String>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the API guidelines, the get_
prefix should be avoided.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch, TIL ! <3
where | ||
P: AsRef<Path>, | ||
{ | ||
println!("[VCS] - Getting diff with target {}", &self.target_branch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not write logs from the lib, at least not unconditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right, I put it there until we can work on #47 and have a better solution alltogether
cargo-scout-lib/src/linter/mod.rs
Outdated
pub struct LintCode { | ||
pub code: String, | ||
pub explanation: String, | ||
struct LintCode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LintCode
and LintSpan
seem unused if I'm not mistaken.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that was a leftover, nice catch ! :)
cargo-scout-lib/src/linter/clippy.rs
Outdated
@@ -12,21 +13,16 @@ pub struct Clippy { | |||
|
|||
impl Linter for Clippy { | |||
fn get_lints(&self, working_dir: PathBuf) -> Result<Vec<Lint>, crate::error::Error> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark as for the get_members
method in the Config
trait.
@@ -0,0 +1,25 @@ | |||
[package] | |||
name = "cargo-scout-lib" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's personal opinion, but I find cargo_scout_lib
to be too long and a bit redundant when used in the binary. What do you think about naming the lib scout
, and the binary cargo-scout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to do it as well, but it turns out there's already a fuzzer out there that goes by the name scout, and I'm not really sure renaming the lib scout-lib wouldn't confuse people more :/
https://crates.io/search?q=scout
Maybe we can find an other name ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, OK then, finding a name is not easy task so let's go with this for now :)
/// The line where the lint should be reported | ||
/// | ||
/// GitHub provides a line_start and a line_end. | ||
/// We should use the line_start in case of multi-line lints. | ||
/// (Why?) | ||
pub line_start: usize, | ||
line_start: usize, | ||
} | ||
|
||
#[derive(Deserialize, PartialEq, Debug, Clone)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the latest stable, we can mark all pub structs with pub fields #[non_exhaustive]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm that's interesting. In the readme I claimed the MSRV was 1.37 but I suppose we can bump it to 1.40 and do it in a subsequent PR.
It would also allow us to slap non_exhaustive to our error enum, just in case :D
No description provided.