mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:53 +00:00
Improve discoverability of dev commands (#621)
This commit is contained in:
parent
82eff641fb
commit
1ede377402
4 changed files with 13 additions and 6 deletions
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
[alias]
|
||||||
|
dev = "run --package ruff_dev --bin ruff_dev"
|
|
@ -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
|
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
|
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,
|
lint-rule violations as it goes. If you need to inspect the AST, you can run `cargo dev print-ast`
|
||||||
similar rules are implemented.
|
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`
|
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
|
you defined earlier (e.g., `E402.py`). This file should contain a variety of violations and
|
||||||
|
|
|
@ -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.
|
The 🛠 emoji indicates that a rule is automatically fixable by the `--fix` command-line option.
|
||||||
|
|
||||||
<!-- Sections automatically generated by examples/generate_rules_table.rs. -->
|
<!-- Sections automatically generated by `cargo dev generate-rules-table`. -->
|
||||||
<!-- Begin auto-generated sections. -->
|
<!-- Begin auto-generated sections. -->
|
||||||
|
|
||||||
### Pyflakes
|
### Pyflakes
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::Args;
|
use clap::Args;
|
||||||
use ruff::checks::{CheckCategory, CheckCode};
|
use ruff::checks::{CheckCategory, CheckCode};
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
|
|
||||||
const FILE: &str = "../README.md";
|
|
||||||
const BEGIN_PRAGMA: &str = "<!-- Begin auto-generated sections. -->";
|
const BEGIN_PRAGMA: &str = "<!-- Begin auto-generated sections. -->";
|
||||||
const END_PRAGMA: &str = "<!-- End auto-generated sections. -->";
|
const END_PRAGMA: &str = "<!-- End auto-generated sections. -->";
|
||||||
|
|
||||||
|
@ -64,7 +64,11 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
print!("{}", output);
|
print!("{}", output);
|
||||||
} else {
|
} else {
|
||||||
// Read the existing file.
|
// 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.
|
// Extract the prefix.
|
||||||
let index = existing
|
let index = existing
|
||||||
|
@ -79,7 +83,7 @@ pub fn main(cli: &Cli) -> Result<()> {
|
||||||
let suffix = &existing[index..];
|
let suffix = &existing[index..];
|
||||||
|
|
||||||
// Write the prefix, new contents, and suffix.
|
// 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, "{}\n\n", prefix)?;
|
||||||
write!(f, "{}", output)?;
|
write!(f, "{}", output)?;
|
||||||
write!(f, "{}", suffix)?;
|
write!(f, "{}", suffix)?;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue