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

Enable nightly features #51

Merged
merged 2 commits into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion src/linter/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct Clippy {
verbose: bool,
no_default_features: bool,
all_features: bool,
preview: bool,
}

impl Linter for Clippy {
Expand All @@ -22,6 +23,7 @@ impl Clippy {
verbose: false,
no_default_features: false,
all_features: false,
preview: false,
}
}

Expand All @@ -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");
}
Expand Down Expand Up @@ -70,6 +88,7 @@ impl Clippy {
.envs(self.get_envs())
.output()
.expect("failed to run clippy pedantic");

if self.verbose {
println!(
"{}",
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down Expand Up @@ -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
Expand Down