NoConfusingPrefixOperator #57
Replies: 8 comments 15 replies
-
Would this report As you said, I think the rule makes sense for non-commutative operators (i.e. where
As I mentioned (recently) in the repository, I don't intend to maintain that package myself. But I think it makes sense for someone to do it. I was originally thinking that it would be a repository for simplifying code (like what is proposed in #52), not for simplifying the readability. But that might work too. I think that people who will want to enable In that sense I think it also makes sense to report |
Beta Was this translation helpful? Give feedback.
-
I feel like this rule could be grouped in the same package as @lxierita's https://github.com/lxierita/no-typealias-constructor's rule, which forbids creating a value with a type alias constructor |
Beta Was this translation helpful? Give feedback.
-
Hey! Just saw your tweet and I think I might be able to work on it. But I might need some help. |
Beta Was this translation helpful? Give feedback.
-
Hello! I've been prompted by @jfmengels to weigh in here. I would love this rule to exist 👍 as I've even written down some thoughts about it in the past:
They both boil down to
This is about as succint as I can make it. Interestingly that coding style has some support from The Man Himself™️: https://twitter.com/evancz/status/856611881728958464 if you want to consider idiomaticness. |
Beta Was this translation helpful? Give feedback.
-
I'm wondering whether we should make this rule also handle functions as well, n which case the name of the rule should change, and ideally not something that mentions "commutative" (I don't think people will try to enable that rule, it's not a sexy word 😅 ). I'm in favor, but probably only for the functions defined in |
Beta Was this translation helpful? Give feedback.
-
It could also be worth discussing if we should ban partial application of all operators. For example, this might look good at first: userIds |> List.filter ((/=) selectedUserId) But then gets refactored to: users |> List.filter (.id >> (/=) selectedUserId) Both of them look good with lambdas: userIds |> List.filter (\id -> id /= selectedUserId) users |> List.filter (\user -> user.id /= selectedUserId) Also, bonus point if one could get autofixes to the above, rather than: users |> List.filter (.id >> (\id -> id /= selectedUserId)) Note: |
Beta Was this translation helpful? Give feedback.
-
@Janiczek just complained about this again on Twitter. Let's get this rule in |
Beta Was this translation helpful? Give feedback.
-
Released as part of (This only includes the part that was about the operators, not the functions that can be confusing like |
Beta Was this translation helpful? Give feedback.
-
What the rule should do:
Report for example
(<) 0
, such as inList.filter ((<) 0)
. My brain automatically reads that as “keep all negative numbers”, but it actually meansList.filter (\x -> 0 < x)
which does the opposite – keeping all positive numbers.Example of things the rule would report:
Example of things the rule would not report:
More comprehensive thoughts:
The following operators are OK to partially apply, because the order of the operands does not matter:
The following are not OK:
I think these are technically OK, but it’s pretty weird partially applying them?
Trivia:
In Haskell you can also do
(<) 0
and it means the same thing as in Elm. But Haskell has additional syntax:(0 <)
means\x -> 0 < x
(just like(<) 0
)(< 0)
means\x -> x < 0
When (not) to enable this rule:
I think this rule always makes sense!
I am looking for:
Is this a good fit for https://github.com/jfmengels/review-simplification? That package already has NoFullyAppliedPrefixOperator which is a bit similar.
I’d love to implement this myself, but I already have lots of other fun open source stuff to do so I might not get around to it.
Beta Was this translation helpful? Give feedback.
All reactions