Deprecate util/dev in favor of cargo alias
If you've been using `./util/dev` before, this now becomes `cargo dev`. The key part of this change is found in `.cargo/config`. This means one less shell script and a bit more cross-platform support for contributors.
This commit is contained in:
parent
f69835bab7
commit
4d1a11d354
@ -1,5 +1,6 @@
|
|||||||
[alias]
|
[alias]
|
||||||
uitest = "test --test compile-test"
|
uitest = "test --test compile-test"
|
||||||
|
dev = "run --package clippy_dev --bin clippy_dev --manifest-path clippy_dev/Cargo.toml --"
|
||||||
|
|
||||||
[build]
|
[build]
|
||||||
rustflags = ["-Zunstable-options"]
|
rustflags = ["-Zunstable-options"]
|
||||||
|
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
4
.github/PULL_REQUEST_TEMPLATE.md
vendored
@ -15,9 +15,9 @@ checked during review or continuous integration.
|
|||||||
- [ ] Followed [lint naming conventions][lint_naming]
|
- [ ] Followed [lint naming conventions][lint_naming]
|
||||||
- [ ] Added passing UI tests (including committed `.stderr` file)
|
- [ ] Added passing UI tests (including committed `.stderr` file)
|
||||||
- [ ] `cargo test` passes locally
|
- [ ] `cargo test` passes locally
|
||||||
- [ ] Executed `./util/dev update_lints`
|
- [ ] Executed `cargo dev update_lints`
|
||||||
- [ ] Added lint documentation
|
- [ ] Added lint documentation
|
||||||
- [ ] Run `./util/dev fmt`
|
- [ ] Run `cargo dev fmt`
|
||||||
|
|
||||||
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
|
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ pub fn register_plugins(reg: &mut rustc_driver::plugin::Registry) {
|
|||||||
|
|
||||||
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
|
The [`plugin::PluginRegistry`][plugin_registry] provides two methods to register lints: [register_early_lint_pass][reg_early_lint_pass] and [register_late_lint_pass][reg_late_lint_pass].
|
||||||
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
|
Both take an object that implements an [`EarlyLintPass`][early_lint_pass] or [`LateLintPass`][late_lint_pass] respectively. This is done in every single lint.
|
||||||
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `util/dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
|
It's worth noting that the majority of `clippy_lints/src/lib.rs` is autogenerated by `cargo dev update_lints` and you don't have to add anything by hand. When you are writing your own lint, you can use that script to save you some time.
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// ./clippy_lints/src/else_if_without_else.rs
|
// ./clippy_lints/src/else_if_without_else.rs
|
||||||
|
@ -22,8 +22,8 @@ cargo test --features deny-warnings
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Perform various checks for lint registration
|
# Perform various checks for lint registration
|
||||||
./util/dev update_lints --check
|
cargo dev update_lints --check
|
||||||
./util/dev --limit-stderr-length
|
cargo dev --limit-stderr-length
|
||||||
|
|
||||||
# Check running clippy-driver without cargo
|
# Check running clippy-driver without cargo
|
||||||
(
|
(
|
||||||
|
@ -88,7 +88,7 @@ pub fn run(check: bool, verbose: bool) {
|
|||||||
Ok(false) => {
|
Ok(false) => {
|
||||||
eprintln!();
|
eprintln!();
|
||||||
eprintln!("Formatting check failed.");
|
eprintln!("Formatting check failed.");
|
||||||
eprintln!("Run `./util/dev fmt` to update formatting.");
|
eprintln!("Run `cargo dev fmt` to update formatting.");
|
||||||
1
|
1
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
@ -7,6 +7,7 @@ use std::collections::HashMap;
|
|||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
@ -205,7 +206,8 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item = Lint> {
|
|||||||
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
|
fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
|
||||||
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
|
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
|
||||||
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
|
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
|
||||||
WalkDir::new("../clippy_lints/src")
|
let path = clippy_project_dir().join("clippy_lints/src");
|
||||||
|
WalkDir::new(path)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(std::result::Result::ok)
|
.filter_map(std::result::Result::ok)
|
||||||
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
|
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
|
||||||
@ -225,7 +227,7 @@ pub struct FileChange {
|
|||||||
/// See `replace_region_in_text` for documentation of the other options.
|
/// See `replace_region_in_text` for documentation of the other options.
|
||||||
#[allow(clippy::expect_fun_call)]
|
#[allow(clippy::expect_fun_call)]
|
||||||
pub fn replace_region_in_file<F>(
|
pub fn replace_region_in_file<F>(
|
||||||
path: &str,
|
path: &Path,
|
||||||
start: &str,
|
start: &str,
|
||||||
end: &str,
|
end: &str,
|
||||||
replace_start: bool,
|
replace_start: bool,
|
||||||
@ -235,14 +237,15 @@ pub fn replace_region_in_file<F>(
|
|||||||
where
|
where
|
||||||
F: Fn() -> Vec<String>,
|
F: Fn() -> Vec<String>,
|
||||||
{
|
{
|
||||||
let mut f = fs::File::open(path).expect(&format!("File not found: {}", path));
|
let path = clippy_project_dir().join(path);
|
||||||
|
let mut f = fs::File::open(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
|
||||||
let mut contents = String::new();
|
let mut contents = String::new();
|
||||||
f.read_to_string(&mut contents)
|
f.read_to_string(&mut contents)
|
||||||
.expect("Something went wrong reading the file");
|
.expect("Something went wrong reading the file");
|
||||||
let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
|
let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
|
||||||
|
|
||||||
if write_back {
|
if write_back {
|
||||||
let mut f = fs::File::create(path).expect(&format!("File not found: {}", path));
|
let mut f = fs::File::create(&path).expect(&format!("File not found: {}", path.to_string_lossy()));
|
||||||
f.write_all(file_change.new_lines.as_bytes())
|
f.write_all(file_change.new_lines.as_bytes())
|
||||||
.expect("Unable to write file");
|
.expect("Unable to write file");
|
||||||
// Ensure we write the changes with a trailing newline so that
|
// Ensure we write the changes with a trailing newline so that
|
||||||
@ -318,6 +321,12 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the path to the Clippy project directory
|
||||||
|
fn clippy_project_dir() -> PathBuf {
|
||||||
|
let clippy_dev_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
|
||||||
|
clippy_dev_dir.parent().unwrap().to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_parse_contents() {
|
fn test_parse_contents() {
|
||||||
let result: Vec<Lint> = parse_contents(
|
let result: Vec<Lint> = parse_contents(
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use clippy_dev::*;
|
use clippy_dev::*;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
mod fmt;
|
mod fmt;
|
||||||
mod new_lint;
|
mod new_lint;
|
||||||
@ -49,12 +50,12 @@ fn main() {
|
|||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("check")
|
Arg::with_name("check")
|
||||||
.long("check")
|
.long("check")
|
||||||
.help("Checks that util/dev update_lints has been run. Used on CI."),
|
.help("Checks that `cargo dev update_lints` has been run. Used on CI."),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("new_lint")
|
SubCommand::with_name("new_lint")
|
||||||
.about("Create new lint and run util/dev update_lints")
|
.about("Create new lint and run `cargo dev update_lints`")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("pass")
|
Arg::with_name("pass")
|
||||||
.short("p")
|
.short("p")
|
||||||
@ -170,7 +171,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
|
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
|
||||||
|
|
||||||
let mut file_change = replace_region_in_file(
|
let mut file_change = replace_region_in_file(
|
||||||
"../src/lintlist/mod.rs",
|
Path::new("src/lintlist/mod.rs"),
|
||||||
"begin lint list",
|
"begin lint list",
|
||||||
"end lint list",
|
"end lint list",
|
||||||
false,
|
false,
|
||||||
@ -189,7 +190,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
.changed;
|
.changed;
|
||||||
|
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../README.md",
|
Path::new("README.md"),
|
||||||
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
|
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
|
||||||
"",
|
"",
|
||||||
true,
|
true,
|
||||||
@ -202,7 +203,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
).changed;
|
).changed;
|
||||||
|
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../CHANGELOG.md",
|
Path::new("CHANGELOG.md"),
|
||||||
"<!-- begin autogenerated links to lint list -->",
|
"<!-- begin autogenerated links to lint list -->",
|
||||||
"<!-- end autogenerated links to lint list -->",
|
"<!-- end autogenerated links to lint list -->",
|
||||||
false,
|
false,
|
||||||
@ -212,7 +213,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
.changed;
|
.changed;
|
||||||
|
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../clippy_lints/src/lib.rs",
|
Path::new("clippy_lints/src/lib.rs"),
|
||||||
"begin deprecated lints",
|
"begin deprecated lints",
|
||||||
"end deprecated lints",
|
"end deprecated lints",
|
||||||
false,
|
false,
|
||||||
@ -222,7 +223,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
.changed;
|
.changed;
|
||||||
|
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../clippy_lints/src/lib.rs",
|
Path::new("clippy_lints/src/lib.rs"),
|
||||||
"begin register lints",
|
"begin register lints",
|
||||||
"end register lints",
|
"end register lints",
|
||||||
false,
|
false,
|
||||||
@ -232,7 +233,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
.changed;
|
.changed;
|
||||||
|
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../clippy_lints/src/lib.rs",
|
Path::new("clippy_lints/src/lib.rs"),
|
||||||
"begin lints modules",
|
"begin lints modules",
|
||||||
"end lints modules",
|
"end lints modules",
|
||||||
false,
|
false,
|
||||||
@ -243,7 +244,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
|
|
||||||
// Generate lists of lints in the clippy::all lint group
|
// Generate lists of lints in the clippy::all lint group
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../clippy_lints/src/lib.rs",
|
Path::new("clippy_lints/src/lib.rs"),
|
||||||
r#"store.register_group\(true, "clippy::all""#,
|
r#"store.register_group\(true, "clippy::all""#,
|
||||||
r#"\]\);"#,
|
r#"\]\);"#,
|
||||||
false,
|
false,
|
||||||
@ -266,7 +267,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
// Generate the list of lints for all other lint groups
|
// Generate the list of lints for all other lint groups
|
||||||
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
|
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
|
||||||
file_change |= replace_region_in_file(
|
file_change |= replace_region_in_file(
|
||||||
"../clippy_lints/src/lib.rs",
|
Path::new("clippy_lints/src/lib.rs"),
|
||||||
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
|
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
|
||||||
r#"\]\);"#,
|
r#"\]\);"#,
|
||||||
false,
|
false,
|
||||||
@ -279,7 +280,7 @@ fn update_lints(update_mode: &UpdateMode) {
|
|||||||
if update_mode == &UpdateMode::Check && file_change {
|
if update_mode == &UpdateMode::Check && file_change {
|
||||||
println!(
|
println!(
|
||||||
"Not all lints defined properly. \
|
"Not all lints defined properly. \
|
||||||
Please run `util/dev update_lints` to make sure all lints are defined properly."
|
Please run `cargo dev update_lints` to make sure all lints are defined properly."
|
||||||
);
|
);
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
@ -39,10 +39,10 @@ lint. Fortunately, you can use the clippy dev tools to handle this for you. We
|
|||||||
are naming our new lint `foo_functions` (lints are generally written in snake
|
are naming our new lint `foo_functions` (lints are generally written in snake
|
||||||
case), and we don't need type information so it will have an early pass type
|
case), and we don't need type information so it will have an early pass type
|
||||||
(more on this later on). To get started on this lint you can run
|
(more on this later on). To get started on this lint you can run
|
||||||
`./util/dev new_lint --name=foo_functions --pass=early --category=pedantic`
|
`cargo dev new_lint --name=foo_functions --pass=early --category=pedantic`
|
||||||
(category will default to nursery if not provided). This command will create
|
(category will default to nursery if not provided). This command will create
|
||||||
two files: `tests/ui/foo_functions.rs` and `clippy_lints/src/foo_functions.rs`,
|
two files: `tests/ui/foo_functions.rs` and `clippy_lints/src/foo_functions.rs`,
|
||||||
as well as run `./util/dev update_lints` to register the new lint. Next, we'll
|
as well as run `cargo dev update_lints` to register the new lint. Next, we'll
|
||||||
open up these files and add our lint!
|
open up these files and add our lint!
|
||||||
|
|
||||||
### Testing
|
### Testing
|
||||||
@ -386,7 +386,7 @@ It can be installed via `rustup`:
|
|||||||
rustup component add rustfmt --toolchain=nightly
|
rustup component add rustfmt --toolchain=nightly
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `./util/dev fmt` to format the whole codebase. Make sure that `rustfmt` is
|
Use `cargo dev fmt` to format the whole codebase. Make sure that `rustfmt` is
|
||||||
installed for the nightly toolchain.
|
installed for the nightly toolchain.
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
@ -404,9 +404,9 @@ Before submitting your PR make sure you followed all of the basic requirements:
|
|||||||
- [ ] Followed [lint naming conventions][lint_naming]
|
- [ ] Followed [lint naming conventions][lint_naming]
|
||||||
- [ ] Added passing UI tests (including committed `.stderr` file)
|
- [ ] Added passing UI tests (including committed `.stderr` file)
|
||||||
- [ ] `cargo test` passes locally
|
- [ ] `cargo test` passes locally
|
||||||
- [ ] Executed `./util/dev update_lints`
|
- [ ] Executed `cargo dev update_lints`
|
||||||
- [ ] Added lint documentation
|
- [ ] Added lint documentation
|
||||||
- [ ] Run `./util/dev fmt`
|
- [ ] Run `cargo dev fmt`
|
||||||
|
|
||||||
### Cheatsheet
|
### Cheatsheet
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//! This file is managed by `util/dev update_lints`. Do not edit.
|
//! This file is managed by `cargo dev update_lints`. Do not edit.
|
||||||
|
|
||||||
pub mod lint;
|
pub mod lint;
|
||||||
pub use lint::Level;
|
pub use lint::Level;
|
||||||
|
@ -34,6 +34,6 @@ fn fmt() {
|
|||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
output.status.success(),
|
output.status.success(),
|
||||||
"Formatting check failed. Run `./util/dev fmt` to update formatting."
|
"Formatting check failed. Run `cargo dev fmt` to update formatting."
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
2
util/dev
2
util/dev
@ -2,4 +2,6 @@
|
|||||||
CARGO_TARGET_DIR=$(pwd)/target/
|
CARGO_TARGET_DIR=$(pwd)/target/
|
||||||
export CARGO_TARGET_DIR
|
export CARGO_TARGET_DIR
|
||||||
|
|
||||||
|
echo 'Deprecated! `util/dev` usage is deprecated, please use `cargo dev` instead.'
|
||||||
|
|
||||||
cd clippy_dev && cargo run -- "$@"
|
cd clippy_dev && cargo run -- "$@"
|
||||||
|
Loading…
Reference in New Issue
Block a user