Skip to content
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
15 changes: 14 additions & 1 deletion src/commands/lint/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@ pub struct LintArgs {
#[arg(long = "yes", default_value_t = false)]
pub confirm_prompts: bool,

/// Show version information
#[arg(long = "version", default_value_t = false)]
pub version: bool,
/// Automatically fix lint warnings reported by bevy_lint.
#[arg(long = "fix", default_value_t = false)]
pub fix: bool,

/// Arguments to forward to `cargo check`.
#[clap(flatten)]
pub cargo_args: CargoCheckArgs,

/// Arguments to forward to `bevy_lint`
///
/// Specified after `--`.
#[clap(last = true, name = "ARGS", global = true)]
pub forward_args: Vec<String>,
}

impl LintArgs {
Expand Down Expand Up @@ -60,7 +73,7 @@ impl LintArgs {
self.cargo_args.compilation_args.target(self.is_web())
}

/// Generate arguments to forward to `cargo build`.
/// Generate arguments to forward to `cargo check`.
pub(crate) fn cargo_args_builder(&self) -> ArgBuilder {
self.cargo_args.args_builder(self.is_web())
}
Expand Down
74 changes: 55 additions & 19 deletions src/commands/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use crate::{
bin_target::select_run_binary,
commands::lint::install::list,
config::CliConfig,
external_cli::cargo::{
self,
install::{AutoInstall, is_installed},
external_cli::{
CommandExt,
cargo::{
self,
install::{AutoInstall, is_installed},
},
},
};

Expand All @@ -24,12 +27,18 @@ pub fn lint(args: &mut LintArgs) -> anyhow::Result<()> {
const PROGRAM: &str = "bevy_lint";
use anyhow::ensure;

if let Some(LintSubcommands::List) = args.subcommand {
if let Some(LintSubcommands::List) = args.subcommand
&& !args.version
&& !args.fix
Comment on lines +31 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of having to check for these args specifically for every single subcommand, since it's "one more thing to remember" when adding a new subcommand. On the other hand, I'm not sure how many more subcommands we're going to add here, so I'm not blocking on it :)

{
return list();
}

#[cfg(feature = "rustup")]
if let Some(LintSubcommands::Install(install_args)) = &args.subcommand {
if let Some(LintSubcommands::Install(install_args)) = &args.subcommand
&& !args.version
&& !args.fix
{
return install_linter(install_args, args.auto_install());
}

Expand All @@ -41,6 +50,45 @@ pub fn lint(args: &mut LintArgs) -> anyhow::Result<()> {
return Ok(());
}

let status = build_lint_cmd(args)?
// We do not want to automatically install a `bevy_lint` version.
// The reason is that to pass the `Package`, we would need to look up the latest release on
// GitHub since there is no easy way of specify "latest".
.ensure_status(AutoInstall::Never)?;

ensure!(
status.success(),
"`bevy_lint` exited with a non-zero exit code."
);

Ok(())
}

fn build_lint_cmd(args: &mut LintArgs) -> anyhow::Result<CommandExt> {
let mut cmd = crate::external_cli::CommandExt::new("bevy_lint");

// only append `--version`
if args.version {
cmd.arg("--version");
return Ok(cmd);
}

// All additional first party `bevy_lint` arguments need to be the first arguments so
// the `forward_args` apply to them.
if args.fix {
cmd.arg("--fix");
}

// Append all forward args. These should come before the
// cargo check args since the forward args would target `bevy_lint` and
// `bevy_lint` appends all additional arguments that are not recognized
// to `cargo check`.
// The forward args are used to support `bevy_lint` arguments that do not yet have first party
// support in the cli.
if !args.forward_args.is_empty() {
cmd.args(args.forward_args.iter());
}

let metadata = cargo::metadata::metadata()?;

let mut bin_target = select_run_binary(
Expand All @@ -65,6 +113,7 @@ pub fn lint(args: &mut LintArgs) -> anyhow::Result<()> {
config.append_cargo_config_rustflags(args.target(), &cargo_config)?;

args.apply_config(&config);

// Update the artifact directory based on the config, e.g. in case the `target` changed
bin_target.update_artifact_directory(
&metadata.target_directory,
Expand All @@ -86,21 +135,8 @@ pub fn lint(args: &mut LintArgs) -> anyhow::Result<()> {

let cargo_args = args.cargo_args_builder();

let mut cmd = crate::external_cli::CommandExt::new("bevy_lint");

cmd.args(cargo_args)
.env("RUSTFLAGS", args.cargo_args.common_args.rustflags.clone());

let status = crate::external_cli::CommandExt::new("bevy_lint")
// We do not want to automatically install a `bevy_lint` version.
// The reason is that to pass the `Package`, we would need to look up the latest release on
// GitHub since there is no easy way of specify "latest".
.ensure_status(AutoInstall::Never)?;

ensure!(
status.success(),
"`bevy_lint` exited with a non-zero exit code."
);

Ok(())
Ok(cmd)
}
Loading