Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show missing required param message when in standard library format #545

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- `roblox_incorrect_roact_usage` now lints for illegal `Name` property
- Added `ignore_pattern` config to `global_usage`, which will ignore any global variables with names that match the pattern
- `roblox_incorrect_roact_usage` now checks for incorrect Roact17's `createElement` usage on variables named `React`. For Roact17 only, `key`, `children`, and `ref` are valid properties to Roblox instances.
- When given in standard library format, additional information now shows up in `incorrect_standard_library_use` missing required parameter errors.

### Fixed
- `string.pack` and `string.unpack` now have proper function signatures in the Lua 5.3 standard library.
Expand Down
14 changes: 13 additions & 1 deletion selene-lib/src/lints/standard_library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,17 @@ impl Visitor for StandardLibraryVisitor<'_> {
if (arguments_length < expected_args && !maybe_more_arguments)
|| (!vararg && arguments_length > max_args)
{
self.diagnostics.push(Diagnostic::new(
let required_param_message = function
.arguments
.get(arguments_length)
.into_iter()
.filter_map(|arg| match &arg.required {
Required::Required(Some(message)) => Some(message.clone()),
_ => None,
})
.collect();

self.diagnostics.push(Diagnostic::new_complete(
"incorrect_standard_library_use",
format!(
"standard library function `{}` requires {} parameters, {} passed",
Expand All @@ -577,6 +587,8 @@ impl Visitor for StandardLibraryVisitor<'_> {
argument_types.len(),
),
Label::from_node(call, None),
required_param_message,
Vec::new(),
));
}

Expand Down
1 change: 1 addition & 0 deletions selene-lib/tests/lints/standard_library/assert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ assert(...)
assert(true)
assert(true, "message", call())
assert(true, "message", ...)
assert()
8 changes: 8 additions & 0 deletions selene-lib/tests/lints/standard_library/assert.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[incorrect_standard_library_use]: standard library function `assert` requir
6 │ assert(true)
│ ^^^^^^^^^^^^
= A failed assertion without a message is unhelpful to users.

error[incorrect_standard_library_use]: standard library function `assert` requires 2 parameters, 3 passed
┌─ assert.lua:7:1
Expand All @@ -16,3 +18,9 @@ error[incorrect_standard_library_use]: standard library function `assert` requir
8 │ assert(true, "message", ...)
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[incorrect_standard_library_use]: standard library function `assert` requires 2 parameters, 0 passed
┌─ assert.lua:9:1
9 │ assert()
│ ^^^^^^^^

Loading