Visitar URL original
Add smell for limitting the number of explicit imports by crtschin · Pull Request #1677 · ndmitchell/hlint · GitHub
Skip to content

Add smell for limitting the number of explicit imports - #1677

Merged
zliu41 merged 2 commits into
ndmitchell:masterfrom
crtschin:crtschin/explicit-import-limit
Nov 6, 2026
Merged

zliu41 merged 2 commits into
ndmitchell:masterfrom
crtschin:crtschin/explicit-import-limit

Conversation

@crtschin

Copy link
Copy Markdown
Contributor

Fixes #1676.

Does what it says on the tin. Adds a new smell called many explicit imports that the user can use to limit the number of explicit imports. Extended both inline (I think that's what these are) and golden tests to include this setting.

@arybczak

arybczak commented Mar 26, 2026 •

Copy link
Copy Markdown

This is especially helpful to contain the number of explicit imports in the codebase where a portion of people use HLS, since HLS by default uses explicit import lists, but lots of explicit imports make the codebase incredibly hard/tedious to modify for people who don't use HLS.

@crtschin
crtschin force-pushed the crtschin/explicit-import-limit branch from cd98ab3 to 3723414 Compare September 29, 2026 08:44
@matsumonkie

Copy link
Copy Markdown
Contributor

Gentle ping @zliu41, @ndmitchell
I also would like this feature in hlint. Is there any way we can get a review of it? 🙏

@zliu41 zliu41 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hints.md should be updated.

Comment thread src/Hint/Smell.hs Outdated
case Map.lookup SmellManyExplicitImports sm of
Just limit ->
case ideclImportList decl of
Just (Exactly, L _ names) | length names > limit ->

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is inconsistent: > vs. >= (used by manyImportsHint).

@crtschin
crtschin force-pushed the crtschin/explicit-import-limit branch 4 times, most recently from e05d934 to eb344c2 Compare October 26, 2026 10:13
@crtschin

Copy link
Copy Markdown
Contributor Author

Smells weren't included in hints.md, I've edited the generator to include them.

@crtschin
crtschin force-pushed the crtschin/explicit-import-limit branch from eb344c2 to 292ca5b Compare October 26, 2026 10:26
@crtschin
crtschin requested a review from zliu41 October 26, 2026 10:27
Comment thread src/Summary.hs Outdated
data Summary = Summary
{ sBuiltinRules :: ![BuiltinHint]
, sLhsRhsRules :: ![HintRule]
, sSmells :: ![SmellHint]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This doesn't seem right. There are two kinds of hints: builtin hints, and configured (lhs-rhs) hints. The smell hints should be part of builtin hints. I don't see why it needs to be added as the third kind.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I initially included them with the rest, but the setup in the table didn't make sense to me for smells when I looked at it. See below. With the other hints there are neat examples of what the code should look like comparisons, which there aren't for smells.

Including smells in with the other hints

Builtin Smell

Hint Name Hint Severity
Too many explicit imports Example:
import A (x, y)
Found:
import A ( x, y )
Warning
Many imports Example:
import A; import B
Found:
import A
import B
Warning
Many arg function Example:
f :: Int -> Int -> Int
f = undefined
Found:
f :: Int -> Int -> Int
Warning
Long type list Example:
f :: Bool -> Int -> (Int -> Proxy '[a, b])
Found:
f :: Bool -> Int -> (Int -> Proxy '[a, b])
Warning
Long function Example:
f = do
  return z
  where
   z = do
    a
    b
Found:
= do a
     b
Warning

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It seems the other restricting hints (such as "Avoid restricted extensions") are not part of the summary. Then I think it's OK to not include the smell hints in the summary either.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, I've removed the summary generator edits again.

@arybczak arybczak mentioned this pull request Oct 30, 2026
@crtschin
crtschin force-pushed the crtschin/explicit-import-limit branch from 292ca5b to 79fb3bf Compare November 3, 2026 10:12
@crtschin
crtschin requested a review from zliu41 November 3, 2026 10:13
@zliu41
zliu41 merged commit 1cc1908 into ndmitchell:master Nov 6, 2026
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.

Make it possible to restrict the number of explicit imports

4 participants