Linting integration #17
No reviewers
Labels
No labels
ActivityPub
advanced features
basic functionality
bug
DHT
evaluation
refactoring
security
test case
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: schmittlauch/Hash2Pub#17
Loading…
Reference in a new issue
No description provided.
Delete branch "Hecate/Hash2Pub:hlint-configuration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This commit brings in an HLint configuration file
and several recommended modifications such as:
($)
removal;(++)
andmap
to(<>)
andfmap
;pure
overreturn
;And finally, a
stylish-haskell
helper scriptthat detects if code files are dirty. Can be useful for CI,
although manually calling it can be nice if you would rather
first implement then beautify.
Regarding the imports, I am of the school that says “non-local imports are noise, put them on top, and keep the local imports as close as your code as possible”.
I am not here to preach stuff, but I thought you'd like to know that this is “A Thing”.
Cheers!
Thanks for these opinionated insights, they're a good starting point for Haskell newbies like me.
I need some clarifications though:
So you're basically recommending to put imports of haskell platform and other libraries first, and the module imports from the same package should appear last? I already tried to follow that rule, but may not have been consistent.
What is the import oordering you suggest? base ==> haskell-platform ==> package local imports?
Why should pure be preferred over return in general? I always tried to use both of them depending on the context: When writing applicative-style functions, I used
pure
to make the applicative nature of the functions obvious, when messing around inside monads (e.g. withdo
notation) I usedreturn
to highlight the monad stuff, even when `pure could've been enough (example: Maybe).Two separated blocks for non-hash2pub modules and hash2pub modules.
Whether or not they belong to the Haskell platform is irrelevant:
They will get ordered alphabetically whilst staying in their lane.
See:
This is an interesting point, and I see why you do that. However, there are two benefits, on two different dimensions, for preferring
pure
toreturn
:return
has a strong, strong history of being a keyword in imperative languages to send back the value produced by the function, and this semantic overlap has been described as, at best confusing, as worse outright dangerous because newcomers start to ascribe some kind of magic properties.return
is mostly an artifact of the past:@hecate I do not fully understand what's the best way of using
stylish-haskell
in my workflow:On the one hand I'm too lazy for calling the tool itself for each single file of my project.
When using the helper script, I usually commit my changes first, then run the heloer script and
--amend
the formatting changes to the previous commit. This only works though when always committing all changes from the repo, not only those of a single file or even a chosen patch set.Why does the helper script care about a dirty working directory?
I have an editor plugin that calls it for the current buffer that I am saving.
The helper script can be run in a CI action or a pre-commit git hook (very useful, I also use that for hlint).
If run as a pre-commit hook, wouldn't it always complain about a dirty working directory then as before a commit changes aren't commited yet?
It will! Sorry for the confusion 😵
What I meant to say is that the script uses the in-place editing feature of
stylish-haskell
to then detect files that need to be passed through by checking thegit status
of those files (since they were edited bystylish-haskell
, they are now unstaged).But the important thing here is that since it returns 1 as an exit code, it will abort the commit step and let you apply
stylish-haskell
on the incriminated files.Am I clear enough? I haven't had much sleep recently…
@Hecate Honestly, no. But maybe you had time to catch up on sleep?
I haven't set it up as a pre-commit hook yet as I don't fully understand it, but running it manually before a commit does only complain about unclean working state.
Do you mean that I then manually shall invoke
stylish-haskell -i
on each Haskell file in the repo?Couldn't I just let the pre-commit script make that do automatically, or are there edge cases where stylish messes up the not-yet-commited changes (e.g. syntax errors, incomplete implementations)?
Then maybe the workflow of this script isn't suited for you. Which editor are you using?
NOPE! If you do so, stylish-haskell will edit the files in-place, then return the return code 0, then you'll be prompted to enter the commit's message, which won't include the edited files, because you couldn't add them in the meantime. Basically, you'll have to commit a fixup afterwards.
stylish-haskell will most definitely stumble on syntax errors. My vim bindings apply it each time I save the file, so it gets formatted in-place.