Skip to content

Commit

Permalink
Use allow config
Browse files Browse the repository at this point in the history
  • Loading branch information
chriscerie committed Mar 29, 2024
1 parent 99184b0 commit db889b7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 33 deletions.
64 changes: 31 additions & 33 deletions selene-lib/src/lints/deprecated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl<'a> DeprecatedVisitor<'a> {
node: &N,
what: &str,
name_path: &[String],
parameters: &[String],
arguments: &[Argument],
) {
assert!(!name_path.is_empty());

Expand All @@ -120,7 +120,12 @@ impl<'a> DeprecatedVisitor<'a> {

let mut notes = vec![deprecated.message.to_owned()];

if let Some(replace_with) = deprecated.try_instead(parameters) {
if let Some(replace_with) = deprecated.try_instead(
&arguments
.iter()
.map(|arg| arg.display.clone())
.collect::<Vec<_>>(),
) {
notes.push(format!("try: {replace_with}"));
}

Expand All @@ -135,6 +140,28 @@ impl<'a> DeprecatedVisitor<'a> {
Vec::new(),
));
}

if let Some(Field {
field_kind: FieldKind::Function(function),
..
}) = self.standard_library.find_global(name_path)
{
for (arg, arg_std) in arguments
.iter()
.zip(&function.arguments)
.filter(|(arg, _)| arg.display != "nil")
{
if let Some(deprecated) = &arg_std.deprecated {
self.diagnostics.push(Diagnostic::new_complete(
"deprecated",
"this parameter is deprecated".to_string(),
Label::new(arg.range),
vec![deprecated.message.clone()],
Vec::new(),
));
};
}
}
}
}

Expand Down Expand Up @@ -224,37 +251,7 @@ impl Visitor for DeprecatedVisitor<'_> {
_ => Vec::new(),
};

if let Some(Field {
field_kind: FieldKind::Function(function),
..
}) = self.standard_library.find_global(&name_path)
{
for (arg, arg_std) in arguments
.iter()
.zip(&function.arguments)
.filter(|(arg, _)| arg.display != "nil")
{
if let Some(deprecated) = &arg_std.deprecated {
self.diagnostics.push(Diagnostic::new_complete(
"deprecated",
"this parameter is deprecated".to_string(),
Label::new(arg.range),
vec![deprecated.message.clone()],
Vec::new(),
));
};
}
}

self.check_name_path(
call,
"function",
&name_path,
&arguments
.iter()
.map(|arg| arg.display.clone())
.collect::<Vec<_>>(),
);
self.check_name_path(call, "function", &name_path, &arguments);
}
}

Expand Down Expand Up @@ -297,6 +294,7 @@ mod tests {
"deprecated_allowed".to_owned(),
"more.*".to_owned(),
"wow.*.deprecated_allowed".to_owned(),
"a".to_owned(),
],
})
.unwrap(),
Expand Down
2 changes: 2 additions & 0 deletions selene-lib/tests/lints/deprecated/specific_allow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ more.deprecated_allowed()
wow.extra.deprecated_allowed()

deprecated_allowed.more()

a(1)
7 changes: 7 additions & 0 deletions selene-lib/tests/lints/deprecated/specific_allow.std.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,10 @@ globals:
args: []
deprecated:
message: "this is deprecated"
a:
args:
- required: false
type:
display: any
deprecated:
message: this is deprecated

0 comments on commit db889b7

Please sign in to comment.