-
Notifications
You must be signed in to change notification settings - Fork 197
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
[Patch+test] Fix bug with postqualified imports and qualifiedStyle=unrestricted #1498
Conversation
, Just $ Just (Exactly, noLocA []) ) | ||
ImportStyleUnqualified -> (Just (NotQualified, "unqualified"), Nothing) | ||
expectedQualStyleDef = expectedQualStyle <|> Just (QualifiedPre, "qualified") |
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.
My ID of the root cause is this line 206 👀
Right here, QualifiedStyleUnrestricted
(no pre-/post- preference) was getting mapped into QualifiedPre
.
Hey @zliu41 @ndmitchell — I noticed somebody has run CI on the PR; thanks. I've checked all 4 workflows — none of them failed because of changes in the PR. Timeout; 143 oomkill; exitcode 251 (?) when building yaml haddock on Windows; build oomkilled on MacOS too. Tests do pass ✔️ on this branch; I explicitly centered the bugfix around tests. See PR diff. As a sidenote, the CI setup could use a brush-up. Misuse of |
@zliu41 @ndmitchell ping. Please review. |
Also hitting this same problem |
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'm inclined to remove the "should be imported post-qualified" hint, because there are tools available (e.g., stylish Haskell) for converting pre-qualified imports to post-qualified imports (or vice versa). If one cares about using pre-qualified or post-qualified imports consistently in their project, they can simply run the tool in the pre-commit hook.
That said, we can still merge this. @ulidtko the CI has been fixed since this PR was opened, can you rebase?
The test should not fail, but it does: > WANT: No hints > FULL OUTPUT FOR GOT: > tests/importStyle-3.hs:1:1-36: Warning: HypotheticalModule2 should be imported qualified or with an explicit import list > Found: > import HypotheticalModule2 qualified > Perhaps: > import qualified HypotheticalModule2 > Note: may break the code > > tests/importStyle-3.hs:2:1-43: Warning: HypotheticalModule4 should be imported qualified > Found: > import HypotheticalModule4 qualified as HM4 > Perhaps: > import qualified HypotheticalModule4 as HM4 > Note: may break the code > > 2 hints
This fixes the bug showcased in parent commit's test.
Including both the "positive" scenarios (intended usage allowed by the rule; no lint emitted) -- and "negative", where the corresponding rule is intended to emit suggestions.
2ffc129
to
0343ec5
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.
Hi @zliu41, thanks for review.
I'm inclined to remove the "should be imported post-qualified" hint [...]
No, please don't. In a large enough codebase, a "stop the world" PR with mass-rewrite of most imports has negligible chances to ever land, due to pervasive conflicts.
That's why an incremental approach can be preferred, based on hlint rules about individual modules.
That's also why qualifiedStyle=unrestricted
is an important feature: it enables smooth nondisruptive incremental transitions. That can be the only way in some conditions (e.g. big repo with moderate code-churn velocity and strict hlint-compliance) to get PostQualifiedImports
.
@ulidtko the CI has been fixed since this PR was opened, can you rebase?
Sure. Done.
I'll going to add clarifying comments in next commit.
Note also that the flag |
Good point. With To explain a motivating usecase further; my point to keep (and fix) # (project-local) .hlint.yaml
- modules:
# ...
- name: Core.Effects,
importStyle: explicitOrQualified,
asRequired: True,
as: Effects, — which encodes the intent to allow e.g. |
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.
Looks good. CI is somehow broken again, so I'll just merge it.
No, please don't. In a large enough codebase, a "stop the world" PR with mass-rewrite of most imports has negligible chances to ever land, due to pervasive conflicts.
A pre-commit hook can be made to run a program (hlint or a code formatter) only on the changed or added files. Alternatively, one can run a program (hlint or a code formatter) only on selected files, which allows them to do the migration piece by piece.
So the real question is, whether something is a formatting issue and can be taken care of by a code formatter, or a code smell that can only be detected by hlint.
Hi!
I'll be brief. The bug:
on the single-line file:
emits, erroneously, a silly hint:
I submit a direct testcase for the bug, then a fix, then more tests for better regression coverage.
Hoping for easy review & merge; release isn't urgent, batch up at will 🙌 Thanks in advance
Fixes #1499