Repository: o0Ignition0o/cargo-scout (language: rust)

Issue:
quick win: enable clippy-preview unstable features behind a flag ?
As explained in #36 and in this [neqo comment](https://github.com/mozilla/neqo/issues/150#issuecomment-564772044), an unstable feature available on nightly only actually allows us to pass --no-default-features as expected, and to get relevant lints even if a build has already been done.

We might want to add a --preview flag that would allow us to run a nightly version and make the tool much more useful while the features we need are being stabilized.

The correct command we can already run on nightly `cargo +nightly clippy-preview -Z unstable-options --no-default-features -- -W clippy::pedantic` behaves exactly the way we wish ! 🎉 


Discussion / hints:
I can take this one on
Sure, thank you for doing that !

Fix patch:
diff --git a/src/linter/clippy.rs b/src/linter/clippy.rs
index 1911926..504b031 100644
--- a/src/linter/clippy.rs
+++ b/src/linter/clippy.rs
@@ -7,6 +7,7 @@ pub struct Clippy {
     verbose: bool,
     no_default_features: bool,
     all_features: bool,
+    preview: bool,
 }
 
 impl Linter for Clippy {
@@ -22,6 +23,7 @@ impl Clippy {
             verbose: false,
             no_default_features: false,
             all_features: false,
+            preview: false,
         }
     }
 
@@ -40,8 +42,24 @@ impl Clippy {
         self
     }
 
+    pub fn set_preview(&mut self, preview: bool) -> &mut Self {
+        self.preview = preview;
+        self
+    }
+
     fn get_command_parameters(&self) -> Vec<&str> {
-        let mut params = vec!["clippy", "--message-format", "json"];
+        let mut params = if self.preview {
+            vec![
+                "+nightly",
+                "clippy-preview",
+                "-Z",
+                "unstable-options",
+                "--message-format",
+                "json",
+            ]
+        } else {
+            vec!["clippy", "--message-format", "json"]
+        };
         if self.verbose {
             params.push("--verbose");
         }
@@ -70,6 +88,7 @@ impl Clippy {
             .envs(self.get_envs())
             .output()
             .expect("failed to run clippy pedantic");
+
         if self.verbose {
             println!(
                 "{}",
@@ -203,6 +222,81 @@ mod tests {
             all_features_command_parameters,
             all_features_linter.get_command_parameters()
         );
+
+        let mut nightly_linter = Clippy::new();
+        let nightly_linter = nightly_linter.set_preview(true);
+        let expected_command_parameters = vec![
+            "+nightly",
+            "clippy-preview",
+            "-Z",
+            "unstable-options",
+            "--message-format",
+            "json",
+            "--",
+            "-W",
+            "clippy::pedantic",
+        ];
+        assert_eq!(
+            expected_command_parameters,
+            nightly_linter.get_command_parameters()
+        );
+
+        let nightly_verbose_linter = nightly_linter.set_verbose(true);
+        let verbose_expected_command_nightly_parameters = vec![
+            "+nightly",
+            "clippy-preview",
+            "-Z",
+            "unstable-options",
+            "--message-format",
+            "json",
+            "--verbose",
+            "--",
+            "-W",
+            "clippy::pedantic",
+        ];
+        assert_eq!(
+            verbose_expected_command_nightly_parameters,
+            nightly_verbose_linter.get_command_parameters()
+        );
+
+        let nightly_all_features_linter = nightly_linter.set_verbose(false).set_all_features(true);
+        let all_features_command_nightly_parameters = vec![
+            "+nightly",
+            "clippy-preview",
+            "-Z",
+            "unstable-options",
+            "--message-format",
+            "json",
+            "--all-features",
+            "--",
+            "-W",
+            "clippy::pedantic",
+        ];
+        assert_eq!(
+            all_features_command_nightly_parameters,
+            nightly_all_features_linter.get_command_parameters()
+        );
+
+        let nightly_no_default_features_linter = nightly_linter
+            .set_verbose(false)
+            .set_all_features(false)
+            .set_no_default_features(true);
+        let no_default_features_command_nightly_parameters = vec![
+            "+nightly",
+            "clippy-preview",
+            "-Z",
+            "unstable-options",
+            "--message-format",
+            "json",
+            "--no-default-features",
+            "--",
+            "-W",
+            "clippy::pedantic",
+        ];
+        assert_eq!(
+            no_default_features_command_nightly_parameters,
+            nightly_no_default_features_linter.get_command_parameters()
+        );
     }
     #[test]
     fn test_lints() {
diff --git a/src/main.rs b/src/main.rs
index 09a202b..ddbc789 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -40,6 +40,9 @@ struct Options {
     #[structopt(short = "w", long = "without-error")]
     /// Set to display the warnings without actually returning an error
     without_error: bool,
+    #[structopt(short = "p", long = "preview")]
+    /// Enable nightly features (e.g. get lints even after the build has already been done.)
+    preview: bool,
 }
 
 fn display_warnings(warnings: &[Lint]) {
@@ -68,7 +71,8 @@ fn main() -> Result<(), error::Error> {
     clippy_linter
         .set_verbose(opts.verbose)
         .set_no_default_features(opts.no_default_features)
-        .set_all_features(opts.all_features);
+        .set_all_features(opts.all_features)
+        .set_preview(opts.preview);
 
     let mut scout_builder = scout::Builder::new();
     scout_builder


Test patch: