From db889b7c6d1b465b76441e1eb0bf8a594c072c9c Mon Sep 17 00:00:00 2001 From: Christopher Chang <51393127+chriscerie@users.noreply.github.com> Date: Fri, 29 Mar 2024 11:37:08 -0700 Subject: [PATCH] Use allow config --- selene-lib/src/lints/deprecated.rs | 64 +++++++++---------- .../tests/lints/deprecated/specific_allow.lua | 2 + .../lints/deprecated/specific_allow.std.yml | 7 ++ 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/selene-lib/src/lints/deprecated.rs b/selene-lib/src/lints/deprecated.rs index cb602aab..1373dba5 100644 --- a/selene-lib/src/lints/deprecated.rs +++ b/selene-lib/src/lints/deprecated.rs @@ -99,7 +99,7 @@ impl<'a> DeprecatedVisitor<'a> { node: &N, what: &str, name_path: &[String], - parameters: &[String], + arguments: &[Argument], ) { assert!(!name_path.is_empty()); @@ -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::>(), + ) { notes.push(format!("try: {replace_with}")); } @@ -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(), + )); + }; + } + } } } @@ -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::>(), - ); + self.check_name_path(call, "function", &name_path, &arguments); } } @@ -297,6 +294,7 @@ mod tests { "deprecated_allowed".to_owned(), "more.*".to_owned(), "wow.*.deprecated_allowed".to_owned(), + "a".to_owned(), ], }) .unwrap(), diff --git a/selene-lib/tests/lints/deprecated/specific_allow.lua b/selene-lib/tests/lints/deprecated/specific_allow.lua index 71671714..275ea6c2 100644 --- a/selene-lib/tests/lints/deprecated/specific_allow.lua +++ b/selene-lib/tests/lints/deprecated/specific_allow.lua @@ -5,3 +5,5 @@ more.deprecated_allowed() wow.extra.deprecated_allowed() deprecated_allowed.more() + +a(1) diff --git a/selene-lib/tests/lints/deprecated/specific_allow.std.yml b/selene-lib/tests/lints/deprecated/specific_allow.std.yml index f31f8cb6..be492b1d 100644 --- a/selene-lib/tests/lints/deprecated/specific_allow.std.yml +++ b/selene-lib/tests/lints/deprecated/specific_allow.std.yml @@ -16,3 +16,10 @@ globals: args: [] deprecated: message: "this is deprecated" + a: + args: + - required: false + type: + display: any + deprecated: + message: this is deprecated