mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-17 13:58:37 +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]",
|
||||
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
6
ruff.schema.json
generated
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue