mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Include entire prefix when reporting rule selector errors (#3375)
This commit is contained in:
parent
c0ad875339
commit
fea1af5a63
2 changed files with 14 additions and 2 deletions
|
@ -51,7 +51,7 @@ impl FromStr for RuleSelector {
|
||||||
|
|
||||||
Ok(Self::Prefix {
|
Ok(Self::Prefix {
|
||||||
prefix: RuleCodePrefix::parse(&linter, code)
|
prefix: RuleCodePrefix::parse(&linter, code)
|
||||||
.map_err(|_| ParseError::Unknown(code.to_string()))?,
|
.map_err(|_| ParseError::Unknown(s.to_string()))?,
|
||||||
redirected_from,
|
redirected_from,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ impl FromStr for RuleSelector {
|
||||||
|
|
||||||
#[derive(Debug, thiserror::Error)]
|
#[derive(Debug, thiserror::Error)]
|
||||||
pub enum ParseError {
|
pub enum ParseError {
|
||||||
#[error("Unknown rule selector `{0}`")]
|
#[error("Unknown rule selector: `{0}`")]
|
||||||
// TODO(martin): tell the user how to discover rule codes via the CLI once such a command is
|
// TODO(martin): tell the user how to discover rule codes via the CLI once such a command is
|
||||||
// implemented (but that should of course be done only in ruff_cli and not here)
|
// implemented (but that should of course be done only in ruff_cli and not here)
|
||||||
Unknown(String),
|
Unknown(String),
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#![allow(dead_code)]
|
#![allow(dead_code)]
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use clap::{command, Parser};
|
use clap::{command, Parser};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
@ -112,6 +113,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide_possible_values = true
|
hide_possible_values = true
|
||||||
)]
|
)]
|
||||||
|
@ -121,6 +123,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide_possible_values = true
|
hide_possible_values = true
|
||||||
)]
|
)]
|
||||||
|
@ -131,6 +134,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide_possible_values = true
|
hide_possible_values = true
|
||||||
)]
|
)]
|
||||||
|
@ -140,6 +144,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide = true
|
hide = true
|
||||||
)]
|
)]
|
||||||
|
@ -170,6 +175,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide_possible_values = true
|
hide_possible_values = true
|
||||||
)]
|
)]
|
||||||
|
@ -180,6 +186,7 @@ pub struct CheckArgs {
|
||||||
long,
|
long,
|
||||||
value_delimiter = ',',
|
value_delimiter = ',',
|
||||||
value_name = "RULE_CODE",
|
value_name = "RULE_CODE",
|
||||||
|
value_parser = parse_rule_selector,
|
||||||
help_heading = "Rule selection",
|
help_heading = "Rule selection",
|
||||||
hide_possible_values = true
|
hide_possible_values = true
|
||||||
)]
|
)]
|
||||||
|
@ -403,6 +410,11 @@ impl CheckArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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> {
|
fn resolve_bool_arg(yes: bool, no: bool) -> Option<bool> {
|
||||||
match (yes, no) {
|
match (yes, no) {
|
||||||
(true, false) => Some(true),
|
(true, false) => Some(true),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue