Import style plugin

I’ve recently released plugin that helps you to keep import style. It supports configuration via yaml. You also can derive your own plugin based on mine to share style all over your projects without copy-paste

github
hackage

How it looks (HLS also highlights that):

src/MyLib.hs:12:1: warning: [-Wx-import-style]
    Use 'Data.Map.Strict'
   |
12 | import Data.Map
   | ^^^^^^^^^^^^^^^

src/MyLib.hs:13:1: warning: [-Wx-import-style]
    Import should satisfy the following rules:
      * Module should be qualified
      * Alias should be Text
    or
      * Module should not be qualified
      * Module should import only the following names: Text
   |
13 | import Data.Text qualified as T
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 Likes

This looks cool.

I think hlint also has support for rules like that described here:

Wonder how those approaches compare. Had you tried hlint for your use case before and considered it unsatisfiying?

1 Like

Tell you the truth, I completely forgot that hlint provides such functionality, and I feel a little ashamed. But fortunately, I can name several differences.

  1. The default settings of hlint are somewhat annoying (and it’s inconvenient to configure hlint for each new project), so I have developed some sort of blindness to hlint hints (this is not about plugin vs hlint, this is about me vs hlint)

  2. Hlint is not part of the compiler, so its use requires either additional effort or integration, for example, with HLS (but since HLS sometimes breaks for quite strange reasons, its use is not always possible either). The plugin, on the other hand, will definitely report a style violation (plus, you can explicitly specify which stylistic rules are errors (not warnings) and then the code won’t even compile)

  3. The plugin allows you to add a style as a library (if you write your own plugin based on mine, there is an instruction in README), while hlint can only work with either the default set of rules or a configuration in the form of YAML, which will need to be copied from one project to another, making it difficult to centralize the style.

I understand the awkwardness of the situation and am actually very glad that I invented something not entirely the same as hlint

3 Likes

I like it, I’ve bookmarked it :slight_smile: