Skip to content

Follow more HLint suggestions#4090

Merged
rhendric merged 41 commits intopurescript:masterfrom
rhendric:rhendric/hlint-campaign
May 27, 2021
Merged

Follow more HLint suggestions#4090
rhendric merged 41 commits intopurescript:masterfrom
rhendric:rhendric/hlint-campaign

Conversation

@rhendric
Copy link
Copy Markdown
Member

@rhendric rhendric commented May 14, 2021

Description of the change

We're ignoring quite a large number of HLint's warnings/suggestions, and I thought it might be a good idea to do something about that.

Here it is, one commit per line removed from .hlint.yaml (except for the first one). I've grouped the commits into sort-of themes and ordered them approximately from what I expect will be least to most controversial (bearing in mind that there are a few suggestions left that even I didn't think would lead to improvement). A handy reference list is below, so that each one can be quibbled about individually. Maybe it would be worth it to break some of these out into smaller PRs? Should each theme be its own PR? I don't know. Let's start talking.

Commits touching more than three code files are bolded.

🧠 The no-brainers

0696af28 Remove unneeded HLint ignore directives
a7fa8610 HLint fix: "Parse error"
0fd6f53f HLint fix: "Unused LANGUAGE pragma"

🤖 Boolean hijinks

50b475c0 HLint fix: "Redundant =="
b6a2aef8 HLint fix: "Redundant if"

📎 Did you mean...

c14cb8c1 HLint fix: "Use notElem"
667d083a HLint fix: "Use String"
b8784430 HLint fix: "Use isDigit"
9f2b72a1 HLint fix: "Use unless"
2dd2764c HLint fix: "Use traverse_"
6eef8922 HLint fix: "Use /="
518c3eda HLint fix: "Use $>"
cc1bd476 HLint fix: "Use =<<"
25b5042a HLint fix: "Use maybe"
9491b718 HLint fix: "Use zipWithM_"
da6cfd3a HLint fix: "Use fromMaybe"
aa0269fd HLint fix: "Use gets"
731a33f5 HLint fix: "Use unwords"

📜 To list or not to list?

fbcb5516 HLint fix: "Use &&"
82d83183 HLint fix: "Use ++"
bb6e1622 HLint fix: "Use list literal pattern"
7ff24174 HLint fix: "Use :"

🤔 Complex simplifications

c19cacab HLint fix: "Use ."
80fd0361 HLint fix: "Use Just"
54fd3dc0 HLint fix: "Hoist not"
d2edcb24 HLint fix: "Redundant fmap"

🔢 Getting it sorted

7cf1c80e HLint fix: "Use sortOn"
f279b60a HLint fix: "Avoid reverse"

💵 Dollars and sense

11eb5b21 HLint fix: "Redundant bracket"
9540bb99 HLint fix: "Redundant $"
864346c1 HLint fix: "Move brackets to avoid $"
f208a8da HLint fix: "Use <$>"
cbaf6a08 HLint fix: "Redundant do" #4090 (comment)

☝️ Pointlessness

f506048e HLint fix: "Eta reduce"
a8f3c712 HLint fix: "Use join"
93f66a42 HLint fix: "Use fmap"
a3a477b3 HLint fix: "Use const"
e3a27227 HLint fix: "Use lambda-case"

💇 Miscellaneous style choices

39d75e4d HLint fix: "Use infix"
102a4d51 HLint fix: "Use tuple-section"
74456748 HLint fix: "Use camelCase"

Finally, some words about the also-rans:

  • "Use newtype instead of data"
    This one wants single-constructor data types to be declared as newtype, which maybe sounds harmless enough, but in some of the cases we have, such as
    data ClientOptions = ClientOptions
      { clientPort :: Network.PortNumber
      }
    I think it would just obscure intent.
  • "Fuse foldr/map"
  • "Functor law"
  • "Fuse mapM/map"
    All of these are triggered by cases where, if one of the HOFs in question takes a lambda and the other a point-free expression, composition could lead to code that is less clear.
  • "Avoid lambda"
  • "Avoid lambda using infix"
  • "Use section"
    All of these really want things like \z -> TUnknown z b to be replaced with (`TUnknown` b), which I don't think is an improvement in cases where the function wasn't named and typed with the intent of being used infix.
  • "Use record patterns"
    This is the weirdest suggestion. It gets triggered by any all-wildcard constructor pattern with three or more wildcards. I think whether to use Ctor{} or Ctor _ _ _ has much more to do with semantics than the number of wildcards—specifically, whether adding a field to the constructor would be a good reason to revisit this code.
  • "Reduce duplication"
    This hint might have some value but silencing it involves substantial non-mechanical refactoring, which I just didn't want to undertake.

Checklist:

  • Added the change to the changelog's "Unreleased" section with a reference to this PR (e.g. "- Made a change (#0000)")
  • Added myself to CONTRIBUTORS.md (if this is my first contribution)
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation
  • Added a test for the contribution (if applicable)

@rhendric rhendric marked this pull request as draft May 14, 2021 01:04
toMarkup D.pursuitCssT
H.body $ do
H.div ! A.class_ "everything-except-footer" $ do
H.div ! A.class_ "top-banner clearfix" $ do
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think I agree with hlint that redundant dos are a problem. In this case, I think I'd actually prefer to leave them in, as it means that you can go back and forth between elements with exactly one child vs more than one child without having to change the line which defines the parent. Can we keep ignoring the redundant do hint please?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Dropped.

@rhendric rhendric force-pushed the rhendric/hlint-campaign branch from b5b6717 to b0818c9 Compare May 15, 2021 17:47
@JordanMartinez
Copy link
Copy Markdown
Contributor

Any other updates on this PR? Seems like it could be ready to merge.

@rhendric rhendric marked this pull request as ready for review May 18, 2021 21:36
@rhendric
Copy link
Copy Markdown
Member Author

I wasn't planning on doing anything more in this PR other than striking commits that maintainers object to. I do think it should probably stay open for a little while longer just in case there are more objections; this covers a lot of small changes and almost all of it is subjective, and after it's squashed and merged it'll be harder to revert individual items.

@JordanMartinez
Copy link
Copy Markdown
Contributor

I fixed the merge conflict due to merging #4085. I'm not sure if that will cause CI to fail now if my code doesn't pass the new hlint requirements.

@JordanMartinez
Copy link
Copy Markdown
Contributor

@rhendric Since I broke your build due to merging #4085, do you want me to submit a PR to your fork to fix it? There's only three issues that need to be fixed (below):

Downloading and running hlint...
lib/purescript-cst/src/Language/PureScript/CST/Convert.hs:578:25: Suggestion: Move brackets to avoid $
Found:
  (N.runOpName $ qualName op) <> argName t2
Perhaps:
  N.runOpName (qualName op) <> argName t2

src/Language/PureScript/Sugar/TypeClasses/Instances.hs:38:31: Suggestion: Move brackets to avoid $
Found:
  genText <> (pack $ show uniqueIdent)
Perhaps:
  genText <> pack (show uniqueIdent)

src/Language/PureScript/TypeChecker.hs:403:6: Warning: Redundant bracket
Found:
  (d@(TypeInstanceDeclaration sa@(ss, _)
                              ch
                              idx
                              (Right dictName)
                              deps
                              className
                              tys
                              body))
Perhaps:
  d@(TypeInstanceDeclaration sa@(ss, _)
                             ch
                             idx
                             (Right dictName)
                             deps
                             className
                             tys
                             body)

3 hints
Error: Process completed with exit code 1.

IO.hSetBuffering IO.stderr IO.LineBuffering
cmd <- Opts.handleParseResult . execParserPure opts =<< getArgs
cmd
join $ Opts.handleParseResult . execParserPure opts =<< getArgs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this was the only thing in terms of readability where I found it easier to understand the original code rather than the updated code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

What's the strength of this opinion—are you objecting or hoping to start a discussion without necessarily objecting?

I personally prefer the updated version—I think join immediately communicates that what follows is an IO of an IO—but I don't mind dropping this commit if this is an actual objection.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Mm.... just ignore the comment for now and please merge this in as soon as you can.

The update is only not as readable to me because I am not as familiar with the code base. If I knew what handleParseResult and the other functions do, then the extra 'cmd' isn't necessary. That takes a few seconds to lookup.

@hdgarrood
Copy link
Copy Markdown
Contributor

As @JordanMartinez points out in #4094, I think it would probably be good to get this in sooner rather than later, and I think it's probably been open long enough for people to have the opportunity to object now.

and after it's squashed and merged it'll be harder to revert individual items.

I think we should enable the "create a merge commit" merge option then, and use that option when merging this PR. Squashing and merging is a good default, but in this case the utility of keeping these commits separate is obvious.

@JordanMartinez
Copy link
Copy Markdown
Contributor

"create a merge commit" merge option then

Sounds good to me!

How should we get CI to pass again?

@hdgarrood
Copy link
Copy Markdown
Contributor

I think it would be ideal to keep the history nice and clean, so the additional fixes which became made necessary after the merge should ideally be amended into the original commit which corresponds to the relevant hlint warning.

@thomashoneyman
Copy link
Copy Markdown
Member

I've enabled normal merge commits.

@rhendric rhendric force-pushed the rhendric/hlint-campaign branch from 9a45974 to 29a9d2d Compare May 27, 2021 19:20
@rhendric
Copy link
Copy Markdown
Member Author

Sorry to have taken a while to check in here; I just got back from a little vacation.

I've rebased and fixed all the conflicts in their appropriate commits. I'm ready to merge (and not squash) once the fate of "Use join" is decided.

@rhendric rhendric merged commit f9f75f4 into purescript:master May 27, 2021
@rhendric rhendric deleted the rhendric/hlint-campaign branch May 27, 2021 20:11
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

Successfully merging this pull request may close these issues.

5 participants