From 1ede377402d982f02f7cee3dbce4b0b7ea16ca25 Mon Sep 17 00:00:00 2001 From: Reiner Gerecke Date: Sun, 6 Nov 2022 20:25:59 +0100 Subject: [PATCH] Improve discoverability of dev commands (#621) --- .cargo/config.toml | 2 ++ CONTRIBUTING.md | 5 +++-- README.md | 2 +- ruff_dev/src/generate_rules_table.rs | 10 +++++++--- 4 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000000..044aeccffc --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +dev = "run --package ruff_dev --bin ruff_dev" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a08a3e2ed..2420a69004 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,8 +58,9 @@ pattern implemented therein. To trigger the rule, you'll likely want to augment the logic in `src/check_ast.rs`, which defines the Python AST visitor, responsible for iterating over the abstract syntax tree and collecting -lint-rule violations as it goes. Grep for the `Check::new` invocations to understand how other, -similar rules are implemented. +lint-rule violations as it goes. If you need to inspect the AST, you can run `cargo dev print-ast` +with a python file. Grep for the `Check::new` invocations to understand how other, similar rules +are implemented. To add a test fixture, create a file under `resources/test/fixtures`, named to match the `CheckCode` you defined earlier (e.g., `E402.py`). This file should contain a variety of violations and diff --git a/README.md b/README.md index 7c290c7061..dafe85d21b 100644 --- a/README.md +++ b/README.md @@ -300,7 +300,7 @@ By default, Ruff enables all `E` and `F` error codes, which correspond to those The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` command-line option. - + ### Pyflakes diff --git a/ruff_dev/src/generate_rules_table.rs b/ruff_dev/src/generate_rules_table.rs index af3a2baae2..0cae692f96 100644 --- a/ruff_dev/src/generate_rules_table.rs +++ b/ruff_dev/src/generate_rules_table.rs @@ -3,13 +3,13 @@ use std::fs; use std::fs::OpenOptions; use std::io::Write; +use std::path::PathBuf; use anyhow::Result; use clap::Args; use ruff::checks::{CheckCategory, CheckCode}; use strum::IntoEnumIterator; -const FILE: &str = "../README.md"; const BEGIN_PRAGMA: &str = ""; const END_PRAGMA: &str = ""; @@ -64,7 +64,11 @@ pub fn main(cli: &Cli) -> Result<()> { print!("{}", output); } else { // Read the existing file. - let existing = fs::read_to_string(FILE)?; + let file = PathBuf::from(env!("CARGO_MANIFEST_DIR")) + .parent() + .expect("Failed to find root directory") + .join("README.md"); + let existing = fs::read_to_string(&file)?; // Extract the prefix. let index = existing @@ -79,7 +83,7 @@ pub fn main(cli: &Cli) -> Result<()> { let suffix = &existing[index..]; // Write the prefix, new contents, and suffix. - let mut f = OpenOptions::new().write(true).truncate(true).open(FILE)?; + let mut f = OpenOptions::new().write(true).truncate(true).open(&file)?; write!(f, "{}\n\n", prefix)?; write!(f, "{}", output)?; write!(f, "{}", suffix)?;