mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-22 00:02:17 +00:00
Make extend_function_names
an Option
type (#4434)
This commit is contained in:
parent
b9e387013f
commit
dcff515ad8
2 changed files with 17 additions and 10 deletions
|
@ -22,10 +22,9 @@ pub struct Options {
|
||||||
value_type = "list[str]",
|
value_type = "list[str]",
|
||||||
example = r#"extend-function-names = ["ugettetxt"]"#
|
example = r#"extend-function-names = ["ugettetxt"]"#
|
||||||
)]
|
)]
|
||||||
#[serde(default)]
|
|
||||||
/// Additional function names to consider as internationalization calls, in addition to those
|
/// Additional function names to consider as internationalization calls, in addition to those
|
||||||
/// included in `function-names`.
|
/// included in `function-names`.
|
||||||
pub extend_function_names: Vec<String>,
|
pub extend_function_names: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, CacheKey)]
|
#[derive(Debug, CacheKey)]
|
||||||
|
@ -34,10 +33,11 @@ pub struct Settings {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_func_names() -> Vec<String> {
|
fn default_func_names() -> Vec<String> {
|
||||||
["_", "gettext", "ngettext"]
|
vec![
|
||||||
.iter()
|
"_".to_string(),
|
||||||
.map(std::string::ToString::to_string)
|
"gettext".to_string(),
|
||||||
.collect()
|
"ngettext".to_string(),
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
|
@ -55,7 +55,12 @@ impl From<Options> for Settings {
|
||||||
.function_names
|
.function_names
|
||||||
.unwrap_or_else(default_func_names)
|
.unwrap_or_else(default_func_names)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(options.extend_function_names)
|
.chain(
|
||||||
|
options
|
||||||
|
.extend_function_names
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter(),
|
||||||
|
)
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,7 +70,7 @@ impl From<Settings> for Options {
|
||||||
fn from(settings: Settings) -> Self {
|
fn from(settings: Settings) -> Self {
|
||||||
Self {
|
Self {
|
||||||
function_names: Some(settings.functions_names),
|
function_names: Some(settings.functions_names),
|
||||||
extend_function_names: vec![],
|
extend_function_names: Some(Vec::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
ruff.schema.json
generated
6
ruff.schema.json
generated
|
@ -712,8 +712,10 @@
|
||||||
"properties": {
|
"properties": {
|
||||||
"extend-function-names": {
|
"extend-function-names": {
|
||||||
"description": "Additional function names to consider as internationalization calls, in addition to those included in `function-names`.",
|
"description": "Additional function names to consider as internationalization calls, in addition to those included in `function-names`.",
|
||||||
"default": [],
|
"type": [
|
||||||
"type": "array",
|
"array",
|
||||||
|
"null"
|
||||||
|
],
|
||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue