-
Notifications
You must be signed in to change notification settings - Fork 718
Make cabal init conform with --no-comments
flag for commented fields
#7770
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
Conversation
| fieldContents == empty && (hasNoComments || isMinimal) = | ||
fieldSEmptyContents NoComment | ||
| fieldContents == empty = | ||
fieldSEmptyContents $ commentPositionFor fieldName fieldComments | ||
|
||
-- If the "--no-comments" or "--minimal" flag is set, strip comments. | ||
| hasNoComments || isMinimal = | ||
fieldSWithContents NoComment | ||
|
||
| otherwise = | ||
-- If the "--no-comments" or "--minimal" flag is set, strip comments. | ||
let comments | ||
| isMinimal = [] | ||
| hasNoComments = [] | ||
| otherwise = fieldComments | ||
|
||
-- If the "--minimal" flag is set, strip comments. | ||
in fieldSWithContents comments | ||
fieldSWithContents $ commentPositionFor fieldName fieldComments |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be written more succinctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you elaborate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't propose anything, just made a gut feeling suggestion. But if you'd like my help, let me think: wouldn't the following guards suffice: hasNoComments || isMinimal
, otherwise
. And if so, how come so much code is unneeded? Are we missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, I just swapped things around, to make it more uniform, that's all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, my bad, I didn't notice that fieldSEmptyContents
and fieldSWithContents
are different functions. So the only simplification could be that fieldContents == empty
decides between the two functions and hasNoComments || isMinimal
between their arguments. But that's not necessarily more readable than separate four cases from multiplying the pair of two cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, let's try:
(if fieldContents == empty then fieldSEmptyContents else fieldSWithContents)
$ if hasNoComments || isMinimal then NoComment else commentPositionFor fieldName fieldComments
You be the judge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's straightforwarder, but are you sure it's more readable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I don't think so. It makes it harder to mix up the two functions that I mixed up and makes it clearer which bits determine which outcome. However, it's overall much harder to read and it's an eureka moment to even discover this is four-branch conditional in disguise. As I said, you be the judge --- it's your PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think using a subexpression and guards make it more readable (and continue being more succint):
fieldD fieldName fieldContents fieldComments includeField opts
| hasNoComments || isMinimal = contents NoComment
| otherwise = contents $ commentPositionFor fieldName fieldComments
where contents | fieldContents == empty = fieldSEmptyContents
| otherwise = fieldSWithContents
But being shorter is not the main goal imo but no repeat conditions, as you will have to remember update 2 call sites if they change. Boolean blindness will make types not help with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a sound strategy, I'll be using that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -1,11 +1,7 @@ | |||
executable y |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've observed comments are being removed from test cases with -no-comment
suffix (so makes total sense) but also from test cases without that suffix, is that on purpose? i suppose we have still test cases with comments, should we suffix these cases with -no-comment
as well to be consistent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is on purpose, they're set to no comments, see here:
let opts = WriteOpts False False True v pkgDir Executable pkgName defaultCabalVersion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well i think if all cases without comments had have the -no-comment
suffix maybe it would be more evident that something was wrong with the test cases themselves, as they had comments!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we go, now the golden files have more meaningful names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for take in account our feedback 👍
6d1a4aa
to
e211005
Compare
e211005
to
96375e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@andreasabel: does the failure in docs/readthedocs.org:cabal job tell you anything? We are now waiting for your docs test to pass (or not) to compare... |
Er, no, my docs test, named "Users guide" did not run on this PR, as it is only triggered by changes under This is the "Read the Docs" CI that is failing. I did not contribute it. cabal/.github/workflows/users-guide.yml Lines 3 to 23 in e74a53b
|
I tried to get more information on the |
@andreasabel: thank you, in that case, let me mark your test, again, as not mandatory in Settings/ |
I triggered a readthedocs build on master and it failed, so as expected the problem isn't introduced with this pr |
Ah, so the PR was waiting for my test, which did not run because it is not triggered? Of course, if the semantics of "mandatory" is "needs to run, and needs to succeed" (Run & Succeed) rather than "if it runs it should succeed" (Run => Succeed), then my test should not be "mandatory". |
That's only because I force-added it to Settings/ after asking around on #hackage.
That's, because I've now removed it from Settings/.
Sadly, that's the semantics, so it was waiting for your test when it was marked in Settings for a moment (in a failed effort to check if it fails similarly to readthedocs test). |
@fgaz wrote:
Also, locally the docs build fine with A documentation concerning the offending
Locally, I get 0.16:
Remotely (on rtd), 0.18 is used:
That can make the difference. |
@andreasabel: thank you for diagnosing the problem and opening a new issue. @ptkato: in that case, we are making ourselves scarce from your PR. Given that all other jobs passed fine, let me merge manually. |
@Mergifyio rebase |
☑️ Nothing to do
|
This PR fixes #7769.
Please include the following checklist in your PR: