fixup! Add warning for using R and S as selectors

This commit is contained in:
Gary Yendell 2025-09-06 17:43:53 +01:00
parent 1c71776659
commit e31f9286f2
2 changed files with 16 additions and 9 deletions

View File

@ -1,14 +1,30 @@
use std::collections::HashMap; use std::collections::HashMap;
use std::sync::LazyLock; use std::sync::LazyLock;
use crate::warn_user_once;
const DEPRECATED_SELECTORS: [&str; 3] = ["R", "U", "IC"];
fn check_for_deprecation(code: &str) {
if DEPRECATED_SELECTORS.contains(&code) {
warn_user_once!(
"Using `{code}` as a selector is deprecated and will be removed in a future version."
);
}
}
/// Returns the redirect target for the given code. /// Returns the redirect target for the given code.
pub(crate) fn get_redirect_target(code: &str) -> Option<&'static str> { pub(crate) fn get_redirect_target(code: &str) -> Option<&'static str> {
check_for_deprecation(code);
REDIRECTS.get(code).copied() REDIRECTS.get(code).copied()
} }
/// Returns the code and the redirect target if the given code is a redirect. /// Returns the code and the redirect target if the given code is a redirect.
/// (The same code is returned to obtain it with a static lifetime). /// (The same code is returned to obtain it with a static lifetime).
pub(crate) fn get_redirect(code: &str) -> Option<(&'static str, &'static str)> { pub(crate) fn get_redirect(code: &str) -> Option<(&'static str, &'static str)> {
check_for_deprecation(code);
REDIRECTS.get_key_value(code).map(|(k, v)| (*k, *v)) REDIRECTS.get_key_value(code).map(|(k, v)| (*k, *v))
} }

View File

@ -10,9 +10,6 @@ use crate::codes::{RuleCodePrefix, RuleGroup};
use crate::registry::{Linter, Rule, RuleNamespace}; use crate::registry::{Linter, Rule, RuleNamespace};
use crate::rule_redirects::get_redirect; use crate::rule_redirects::get_redirect;
use crate::settings::types::PreviewMode; use crate::settings::types::PreviewMode;
use crate::warn_user_once;
const DEPRECATED_SELECTORS: [&str; 2] = ["R", "U"];
#[derive(Debug, Clone, PartialEq, Eq, Hash)] #[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum RuleSelector { pub enum RuleSelector {
@ -68,12 +65,6 @@ impl FromStr for RuleSelector {
"C" => Ok(Self::C), "C" => Ok(Self::C),
"T" => Ok(Self::T), "T" => Ok(Self::T),
_ => { _ => {
if DEPRECATED_SELECTORS.contains(&s) {
warn_user_once!(
"Using `{s}` as a selector is deprecated and will be removed in a future version."
);
}
let (s, redirected_from) = match get_redirect(s) { let (s, redirected_from) = match get_redirect(s) {
Some((from, target)) => (target, Some(from)), Some((from, target)) => (target, Some(from)),
None => (s, None), None => (s, None),