Skip to content

Commit

Permalink
Permit specifying a non-default edition when linting file
Browse files Browse the repository at this point in the history
`cargo dev lint /tmp/file.rs -- --edition 2021` will select edition
2021.
  • Loading branch information
samueltardieu committed Feb 6, 2025
1 parent 8a9d550 commit 0e42ba9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clippy_dev/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::utils::{cargo_clippy_path, exit_if_err};
use std::process::{self, Command};
use std::{env, fs};

pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
pub fn run<'a>(path: &str, edition: &str, args: impl Iterator<Item = &'a String>) {
let is_file = match fs::metadata(path) {
Ok(metadata) => metadata.is_file(),
Err(e) => {
Expand All @@ -17,7 +17,7 @@ pub fn run<'a>(path: &str, args: impl Iterator<Item = &'a String>) {
.args(["run", "--bin", "clippy-driver", "--"])
.args(["-L", "./target/debug"])
.args(["-Z", "no-codegen"])
.args(["--edition", "2024"])
.args(["--edition", edition])
.arg(path)
.args(args)
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.
Expand Down
5 changes: 4 additions & 1 deletion clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() {
RemoveSubcommand::VscodeTasks => setup::vscode::remove_tasks(),
},
DevCommand::Serve { port, lint } => serve::run(port, lint),
DevCommand::Lint { path, args } => lint::run(&path, args.iter()),
DevCommand::Lint { path, edition, args } => lint::run(&path, &edition, args.iter()),
DevCommand::RenameLint {
old_name,
new_name,
Expand Down Expand Up @@ -206,6 +206,9 @@ enum DevCommand {
/// cargo dev lint file.rs -- -W clippy::pedantic {n}
/// cargo dev lint ~/my-project -- -- -W clippy::pedantic
Lint {
/// The Rust edition to use
#[arg(long, default_value = "2024")]
edition: String,
/// The path to a file or package directory to lint
path: String,
/// Pass extra arguments to cargo/clippy-driver
Expand Down

0 comments on commit 0e42ba9

Please sign in to comment.