Make extend_function_names an Option type (#4434)

This commit is contained in:
Charlie Marsh 2023-05-14 22:15:02 -04:00 committed by GitHub
parent b9e387013f
commit dcff515ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View file

@ -22,10 +22,9 @@ pub struct Options {
value_type = "list[str]",
example = r#"extend-function-names = ["ugettetxt"]"#
)]
#[serde(default)]
/// Additional function names to consider as internationalization calls, in addition to those
/// included in `function-names`.
pub extend_function_names: Vec<String>,
pub extend_function_names: Option<Vec<String>>,
}
#[derive(Debug, CacheKey)]
@ -34,10 +33,11 @@ pub struct Settings {
}
fn default_func_names() -> Vec<String> {
["_", "gettext", "ngettext"]
.iter()
.map(std::string::ToString::to_string)
.collect()
vec![
"_".to_string(),
"gettext".to_string(),
"ngettext".to_string(),
]
}
impl Default for Settings {
@ -55,7 +55,12 @@ impl From<Options> for Settings {
.function_names
.unwrap_or_else(default_func_names)
.into_iter()
.chain(options.extend_function_names)
.chain(
options
.extend_function_names
.unwrap_or_default()
.into_iter(),
)
.collect(),
}
}
@ -65,7 +70,7 @@ impl From<Settings> for Options {
fn from(settings: Settings) -> Self {
Self {
function_names: Some(settings.functions_names),
extend_function_names: vec![],
extend_function_names: Some(Vec::new()),
}
}
}

6
ruff.schema.json generated
View file

@ -712,8 +712,10 @@
"properties": {
"extend-function-names": {
"description": "Additional function names to consider as internationalization calls, in addition to those included in `function-names`.",
"default": [],
"type": "array",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}