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

Add must_use lint #381

Merged
merged 3 commits into from
Jun 23, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added
- `table.insert(x)` no longer counts as a read to `x`, which allows selene to alert you that you are only assigning to it.
- This is done through a new standard library field for arguments called `observes`. This takes 3 values: "read-write" (the default), signifying a potential read and write, "read", signifying only a read, and "write", signifying only a write. Only "write" has meaning at this time.
- Added new `must_use` lint, which will warn you when you are not using the return value of a function that performs no other behavior.
- This is done through a new standard library field for functions called `must_use`. Set it to `true` to gain this functionality.

### Fixed
- Fixed a bunch of performance failures, lowering some benchmarks from 3 seconds to 200ms.
Expand Down
1 change: 1 addition & 0 deletions docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- [if_same_then_else](./lints/if_same_then_else.md)
- [ifs_same_cond](./lints/ifs_same_cond.md)
- [multiple_statements](./lints/multiple_statements.md)
- [must_use](./lint/must_use.md)
- [mismatched_arg_count](./lints/mismatched_arg_count.md)
- [parenthese_conditions](./lints/parenthese_conditions.md)
- [roblox_incorrect_color3_new_bounds](./lints/roblox_incorrect_color3_new_bounds.md)
Expand Down
23 changes: 23 additions & 0 deletions docs/src/lints/must_use.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# must_use
## What it does
Checks that the return values of functions [marked `must_use`](../usage/std.md#must_use) are used.

## Why this is bad
This lint will only catch uses where the function has no reason to be called other than to use its output.


## Example
```lua
bit32.bor(entity.flags, Flags.Invincible)
```

...should be written as...

```lua
entity.flags = bit32.bor(entity.flags, Flags.Invincible)
```

...as `bit32.bor` only produces a new value, it does not mutate anything.

## Remarks
The output is deemed "unused" if the function call is its own statement.
Loading