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

Split the crates into a bin and a lib, within the cargo-scout wor… #61

Merged
merged 5 commits into from
Dec 21, 2019

Conversation

o0Ignition0o
Copy link
Owner

No description provided.

@o0Ignition0o
Copy link
Owner Author

o0Ignition0o commented Dec 20, 2019

Isht there's a lot going on here, but it should be a good step towards #56 and #59

@o0Ignition0o
Copy link
Owner Author

@ebroto | @daubaris it's a pretty huge one, but the split starts looking ok. Plus they allow me to figure out exactly what to expose, and start writing docs.
I'm probably going to merge it tomorrow or on monday, let me know if you have ideas / comments :)

@o0Ignition0o o0Ignition0o changed the title Split the crates into a bin and s lib, within the cargo-scout workspace. Split the crates into a bin and a lib, within the cargo-scout workspace. Dec 20, 2019
@o0Ignition0o
Copy link
Owner Author

Here's what the documentation looks like so far:

image

@ebroto
Copy link
Contributor

ebroto commented Dec 21, 2019

Looking good! If it's OK I'll take a look later in the day when I have some free time :)

@o0Ignition0o
Copy link
Owner Author

Sure no problem, take your time :)

Copy link
Contributor

@ebroto ebroto left a 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.

}

impl CargoConfig {
/// This function will instanciate a Config from a Cargo.toml path.
Copy link
Contributor

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"

use crate::config::Config;
use serde::Deserialize;

#[derive(Deserialize, PartialEq, Debug, Clone)]
Copy link
Contributor

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> {
Copy link
Contributor

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).

Copy link
Owner Author

@o0Ignition0o o0Ignition0o Dec 21, 2019

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 !

Copy link
Contributor

@ebroto ebroto Dec 22, 2019

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

Copy link
Owner Author

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 !

/// }
/// }
/// ```
fn get_members(&self) -> Vec<String>;
Copy link
Contributor

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.

Copy link
Owner Author

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);
Copy link
Contributor

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.

Copy link
Owner Author

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

pub struct LintCode {
pub code: String,
pub explanation: String,
struct LintCode {
Copy link
Contributor

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.

Copy link
Owner Author

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 ! :)

@@ -12,21 +13,16 @@ pub struct Clippy {

impl Linter for Clippy {
fn get_lints(&self, working_dir: PathBuf) -> Result<Vec<Lint>, crate::error::Error> {
Copy link
Contributor

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"
Copy link
Contributor

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 ?

Copy link
Owner Author

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 ?

Copy link
Contributor

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)]
Copy link
Contributor

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]

Copy link
Owner Author

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

@o0Ignition0o o0Ignition0o changed the title Split the crates into a bin and a lib, within the cargo-scout workspace. Split the crates into a bin and a lib, within the cargo-scout wor… Dec 21, 2019
@o0Ignition0o o0Ignition0o merged commit e95867b into master Dec 21, 2019
@o0Ignition0o o0Ignition0o deleted the lib_bin_split branch December 21, 2019 22:35
@o0Ignition0o o0Ignition0o mentioned this pull request Dec 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants