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

Warns on error-prone and unnecessary negations #46

Merged
merged 1 commit into from
Jan 21, 2022

Conversation

arichard4
Copy link

Closes #43

@arichard4
Copy link
Author

One false positive here: sometimes metatables override the various boolean operators, and end up implementing them in terms of each other.

Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. It looks pretty good to me. I do want to put it through a couple paces before merging, but as far as I'm concerned this is on the right track.

@alerque
Copy link
Member

alerque commented Jan 18, 2022

Having not actually run this bot looking at the code, then looking at use cases from my own code, wouldn't this be a false positive for a situation like this:

if not (t and #t >= 1 and t[#t].prop) then ... end

?

@UncombedCoconut
Copy link

Having not actually run this bot looking at the code, then looking at use cases from my own code, wouldn't this be a false positive for a situation like this:

if not (t and #t >= 1 and t[#t].prop) then ... end

?

Nope, that's still clean. Neither rule has anything to say about the negation of a conjunction.
There is a known false positive mentioned here, though: #43 (comment) -- fortunately a niche use case compared to the above.

@arichard4
Copy link
Author

arichard4 commented Jan 19, 2022

I'll update the docs to talk specifically about 'relational operators' rather than 'binary boolean operators'; that's the correct term, and it's clearer that conjunctions aren't included.

@arichard4
Copy link
Author

Oh, one more false-positive case: if one side is NaN, the proposed replacement would fail. (Because for any concrete number, NaN isn't greater than, equal to, or less than that number.)

@arichard4
Copy link
Author

arichard4 commented Jan 21, 2022

@alerque For context- I have a local test suite of 13 large open source projects that use luacheck already; the only false positive, so far as I can tell, was luarocks, line 63 here: https://github.com/luarocks/luarocks/blob/master/src/luarocks/core/vers.lua

It seems like no projects actually cared about the NaN case, but in theory that could matter too. I've clarified messaging for both cases.

@arichard4 arichard4 force-pushed the negated_binary branch 2 times, most recently from bbd4153 to eb62cc3 Compare January 21, 2022 01:23
Copy link
Member

@alerque alerque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think my only remaining objection is the false positives this generates in my own projects, but the cases are all metatable related and convoluted that the reason why they use an unconventional order really should be annotated anyway, so having to adding a lint suppression seems fair enough.

@alerque
Copy link
Member

alerque commented Jan 21, 2022

@arichard4 It might be a good idea to submit a fix with a lint suppressor for that Luarocks metatable trickery (or flip it and add a :__ge method to compensate) so that the fix can land before this lint issue pops up.

@alerque
Copy link
Member

alerque commented Jan 21, 2022

Any idea what's up with the Luajit test segfault? Doesn't seem to be related to this PR.

@alerque alerque merged commit c795cbe into lunarmodules:master Jan 21, 2022
@arichard4 arichard4 deleted the negated_binary branch January 21, 2022 12:31
@arichard4
Copy link
Author

arichard4 commented Jan 21, 2022

Both the luajit test jobs seems to frequently suffer segfaults. Some things I've noticed:

(1) They're both building against Luajit 2.1-beta3, which is way out of date (from 2017); plausibly they should try to build against a more recent commit instead. The build target seems to come from https://github.com/leafo/gh-actions-lua/blob/master/.github/workflows/publish.yml
(2) As of 2017, there were a bunch of issues reported in busted/luassert involving busted reloading requires, and the previous required modules getting GC'd, causing luajit-specific segfaults: e.g. lunarmodules/busted#496 Luacheck has a lot of tests, if (1) doesn't fix the tests plausibly the luajit tests should be dropped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Question: is there interest in adding warnings about questionable expressions?
3 participants