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

False positives with Redundant check #5

Open
IsakSundeSingh opened this issue May 21, 2021 · 3 comments
Open

False positives with Redundant check #5

IsakSundeSingh opened this issue May 21, 2021 · 3 comments
Assignees

Comments

@IsakSundeSingh
Copy link

IsakSundeSingh commented May 21, 2021

Great rule! Unfortunately the issue with operator precedence still exists, despite it being announced as fixed in #3.

It can be seen in this example code:

Applied from the fixes for the following errors:
NoLeftPizza: Redundant left pizza (<|) operator application

498| testEmptyString text =
499|     String.trim >> String.isEmpty <| text
500|     String.trim >> String.isEmpty text
500|

The "fix" is to remove the pipe (🍕 ) operator, but then the type of the function changes.

This happens using elm-review-noleftpizza 2.0.0 with node-elm-review 2.4.6 and elm-syntax 7.2.1.

@jfmengels
Copy link

jfmengels commented May 21, 2021

This is not an issue about operator precedence, but rather an issue that the rule does not check what the contents on the left of the <| are.

The rule considers what is on the right to see if it's safe to remove the <|, but as shown with your example, it should also be done for the left side.

I'm guessing the left side should wrapped in parentheses when it turns out the removal of <| would change the behavior?

testEmptyString text =
- 499|     String.trim >> String.isEmpty <| text
+ 500|     (String.trim >> String.isEmpty) text

When using Redundant, I imagine it would be preferable not to report the error at all 🤔

@IsakSundeSingh
Copy link
Author

Ah, my mistake! I just assumed it was due to operator precedence.

I guess considering the left-hand of the expression is necessary to avoid false positives, yes.
Regarding this specific example it is not really a redundant use of <| so it should probably not be reported when Redundant is used.
For the non-redundant option it seems as if your option of wrapping the left-hand side in parentheses should be the correct solution 👍

@zwilias zwilias self-assigned this Jul 16, 2021
@Janiczek
Copy link

Janiczek commented Mar 2, 2022

Here's another example:

String.fromInt << List.length <| someList

The rule says

This left pizza operator can be removed without any further changes, without changing the semantics of your code.

But that's not true:

String.fromInt << List.length <| someList
===
(String.fromInt << List.length) <| someList

and removing the <| would change it into

String.fromInt << List.length someList
===
String.fromInt << (List.length someList)

which doesn't compile.

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

No branches or pull requests

4 participants