mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:47 +00:00
Show rule codes in shell tab completion (#7375)
## Summary I noticed that we have a custom parser for rule selectors, but it wasn't actually being used? This PR adds it back to our Clap setup and changes the parser to only show full categories and individual rules when tab-completing: <img width="1792" alt="Screen Shot 2023-09-13 at 9 13 38 PM" src="028b18d2
-8c92-49c1-b781-f24c9ae310f7"> <img width="1792" alt="Screen Shot 2023-09-13 at 9 13 40 PM" src="fd598da5
-78fb-412d-a69e-2a0963d479cd"> <img width="1792" alt="Screen Shot 2023-09-13 at 9 13 58 PM" src="7c482b90
-6e54-425c-ae23-fb50496a177a"> The previous implementation showed all codes, which I found too noisy: <img width="1792" alt="Screen Shot 2023-09-13 at 8 57 09 PM" src="db370a0e
-2a9f-4acd-b1e3-224a1f8e9ce5">
This commit is contained in:
parent
6856d0b44b
commit
f9e3ea23ba
5 changed files with 60 additions and 44 deletions
|
@ -1,17 +1,16 @@
|
|||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
|
||||
use clap::{command, Parser};
|
||||
use regex::Regex;
|
||||
use ruff::line_width::LineLength;
|
||||
use rustc_hash::FxHashMap;
|
||||
|
||||
use ruff::line_width::LineLength;
|
||||
use ruff::logging::LogLevel;
|
||||
use ruff::registry::Rule;
|
||||
use ruff::settings::types::{
|
||||
FilePattern, PatternPrefixPair, PerFileIgnore, PreviewMode, PythonVersion, SerializationFormat,
|
||||
};
|
||||
use ruff::RuleSelector;
|
||||
use ruff::{RuleSelector, RuleSelectorParser};
|
||||
use ruff_workspace::configuration::{Configuration, RuleSelection};
|
||||
use ruff_workspace::resolver::ConfigProcessor;
|
||||
|
||||
|
@ -129,7 +128,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -139,7 +138,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -149,7 +148,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -159,7 +158,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide = true
|
||||
)]
|
||||
|
@ -191,7 +190,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -201,7 +200,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -211,7 +210,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide_possible_values = true
|
||||
)]
|
||||
|
@ -221,7 +220,7 @@ pub struct CheckCommand {
|
|||
long,
|
||||
value_delimiter = ',',
|
||||
value_name = "RULE_CODE",
|
||||
value_parser = parse_rule_selector,
|
||||
value_parser = RuleSelectorParser,
|
||||
help_heading = "Rule selection",
|
||||
hide = true
|
||||
)]
|
||||
|
@ -511,11 +510,6 @@ impl FormatCommand {
|
|||
}
|
||||
}
|
||||
|
||||
fn parse_rule_selector(env: &str) -> Result<RuleSelector, std::io::Error> {
|
||||
RuleSelector::from_str(env)
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))
|
||||
}
|
||||
|
||||
fn resolve_bool_arg(yes: bool, no: bool) -> Option<bool> {
|
||||
match (yes, no) {
|
||||
(true, false) => Some(true),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue