about summary refs log tree commit diff
path: root/users/Profpatsch/.hlint.yaml
blob: f00f78c5259d6c372c4a7751a3b45ab534061deb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# HLint configuration file
# https://github.com/ndmitchell/hlint
# Run `hlint --default` to see the example configuration file.
##########################

# WARNING: These need to be synced with the default-extensions field
# in the cabal file.
- arguments: [-XGHC2021, -XOverloadedRecordDot]

# Ignore some builtin hints

# often functions are more readable with explicit arguments
- ignore: { name: Eta reduce }

# these redundancy warnings are just completely irrelevant
- ignore: { name: Redundant bracket }
- ignore: { name: Move brackets to avoid $ }
- ignore: { name: Redundant $ }
- ignore: { name: Redundant do }
- ignore: { name: Redundant multi-way if }

# allow case-matching on bool, because why not
- ignore: { name: Use if }

# hlint cannot distinguish actual newtypes from data types
# that accidentally have only one field
# (but might have more in the future).
# Since it’s a mostly irrelevant runtime optimization, we don’t care.
- ignore: { name: Use newtype instead of data }

# these lead to harder-to-read/more implicit code
- ignore: { name: Use fmap }
- ignore: { name: Use <$> }
- ignore: { name: Use tuple-section }
- ignore: { name: Use forM_ }
- ignore: { name: Functor law }
# fst and snd are usually a code smell and should be explicit matches, _naming the ignored side.
- ignore: { name: Use fst }
- ignore: { name: Use snd }
- ignore: { name: Use fromMaybe }
- ignore: { name: Use const }
- ignore: { name: Replace case with maybe }
- ignore: { name: Replace case with fromMaybe }
- ignore: { name: Avoid lambda }
- ignore: { name: Avoid lambda using `infix` }
- ignore: { name: Use curry }
- ignore: { name: Use uncurry }
- ignore: { name: Use first }
- ignore: { name: Redundant first }
- ignore: { name: Use second }
- ignore: { name: Use bimap }
# just use `not x`
- ignore: { name: Use unless }
- ignore: { name: Redundant <&> }

# list comprehensions are a seldomly used part of the Haskell language
# and they introduce syntactic overhead that is usually not worth the conciseness
- ignore: { name: Use list comprehension }

# Seems to be buggy in cases
- ignore: { name: Use section }

# multiple maps in a row are usually used for clarity,
# and the compiler will optimize them away, thank you very much.
- ignore: { name: Use map once }
- ignore: { name: Fuse foldr/map }
- ignore: { name: Fuse traverse/map }
- ignore: { name: Fuse traverse_/map }
- ignore: { name: Fuse traverse/<$> }

# this is silly, why would I use a special function if I can just (heh) `== Nothing`
- ignore: { name: Use isNothing }

# The duplication heuristic is not very smart
# and more annoying than helpful.
# see https://github.com/ndmitchell/hlint/issues/1009
- ignore: { name: Reduce duplication }

# Stops the pattern match trick
- ignore: { name: Use record patterns }
- ignore: { name: Use null }
- ignore: { name: Use uncurry }

# we don’t want void, see below
- ignore: { name: Use void }

- functions:
    # disallow Enum instance functions, they are partial
    - name: Prelude.succ
      within: [Relude.Extra.Enum]
      message: "Dangerous, will fail for highest element"
    - name: Prelude.pred
      within: [Relude.Extra.Enum]
      message: "Dangerous, will fail for lowest element"
    - name: Prelude.toEnum
      within: []
      message: "Extremely partial"
    - name: Prelude.fromEnum
      within: []
      message: "Dangerous for most uses"
    - name: Prelude.enumFrom
      within: []
    - name: Prelude.enumFromThen
      within: []
    - name: Prelude.enumFromThenTo
      within: []
    - name: Prelude.oundedEnumFrom
      within: []
    - name: Prelude.boundedEnumFromThen
      within: []

    - name: Text.Read.readMaybe
      within:
        # The BSON ObjectId depends on Read for parsing
        - Milkmap.Milkmap
        - Milkmap.FieldData.Value
      message: "`readMaybe` is probably not what you want for parsing values, please use the `FieldParser` module."

    # `void` discards its argument and is polymorphic,
    # thus making it brittle in the face of code changes.
    # (see https://tech.freckle.com/2020/09/23/void-is-a-smell/)
    # Use an explicit `_ <- …` instead.
    - name: Data.Functor.void
      within: []
      message: "`void` leads to bugs. Use an explicit `_ <- …` instead"

    - name: Data.Foldable.length
      within: ["MyPrelude"]
      message: "`Data.Foldable.length` is dangerous to use, because it also works on types you wouldn’t expect, like `length (3,4) == 1` and `length (Just 2) == 1`. Use the `length` function for your specific type instead, for example `List.length` or `Map.length`."

    - name: Prelude.length
      within: ["MyPrelude"]
      message: "`Prelude.length` is dangerous to use, because it also works on types you wouldn’t expect, like `length (3,4) == 1` and `length (Just 2) == 1`. Use the `length` function for your specific type instead, for example `List.length` or `Map.length`."

    # Using an explicit lambda with its argument “underscored”
    # is more clear in every case.
    # e.g. `const True` => `\_request -> True`
    # shows the reader that the ignored argument was a request.
    - name: Prelude.const
      within: []
      message: "Replace `const` with an explicit lambda with type annotation for code clarity and type safety, e.g.: `const True` => `\\(_ :: Request) -> True`. If you really don’t want to spell out the type (which might lead to bugs!), you can also use something like `\_request -> True`."

    - name: Data.List.nub
      within: []
      message: "O(n²), use `Data.Containers.ListUtils.nubOrd"

    - name: Prelude.maximum
      within: []
      message: "`maximum` crashes on empty list; use non-empty lists and `maximum1`"

    - name: Data.List.maximum
      within: []
      message: "`maximum` crashes on empty list; use non-empty lists and `maximum1`"

    - name: Prelude.minimum
      within: []
      message: "`minimum` crashes on empty list; use non-empty lists and `minimum1`"

    - name: Data.List.minimum
      within: []
      message: "`minimum` crashes on empty list; use non-empty lists and `minimum1`"

    - name: Data.Foldable.maximum
      within: []
      message: "`maximum` crashes on empty foldable stucture; use Foldable1 and `maximum1`."

    - name: Data.Foldable.minimum
      within: []
      message: "`minimum` crashes on empty foldable stucture; use Foldable1 and `minimum1`."

    # Using prelude functions instead of stdlib functions

    - name: "Data.Text.Encoding.encodeUtf8"
      within: ["MyPrelude"]
      message: "Use `textToBytesUtf8`"

    - name: "Data.Text.Lazy.Encoding.encodeUtf8"
      within: ["MyPrelude"]
      message: "Use `textToBytesUtf8Lazy`"

    - name: "Data.Text.Encoding.decodeUtf8'"
      within: ["MyPrelude"]
      message: "Use `bytesToTextUtf8`"

    - name: "Data.Text.Encoding.Lazy.decodeUtf8'"
      within: ["MyPrelude"]
      message: "Use `bytesToTextUtf8Lazy`"

    - name: "Data.Text.Encoding.decodeUtf8"
      within: ["MyPrelude"]
      message: "Either check for errors with `bytesToTextUtf8`, decode leniently with unicode replacement characters with `bytesToTextUtf8Lenient` or use the crashing version `bytesToTextUtf8Unsafe` (discouraged)."

    - name: "Data.Text.Encoding.Lazy.decodeUtf8"
      within: ["MyPrelude"]
      message: "Either check for errors with `bytesToTextUtf8Lazy`, decode leniently with unicode replacement characters with `bytesToTextUtf8LenientLazy` or use the crashing version `bytesToTextUtf8UnsafeLazy` (discouraged)."

    - name: "Data.Text.Lazy.toStrict"
      within: ["MyPrelude"]
      message: "Use `toStrict`"

    - name: "Data.Text.Lazy.fromStrict"
      within: ["MyPrelude"]
      message: "Use `toLazy`"

    - name: "Data.ByteString.Lazy.toStrict"
      within: ["MyPrelude"]
      message: "Use `toStrictBytes`"

    - name: "Data.ByteString.Lazy.fromStrict"
      within: ["MyPrelude"]
      message: "Use `toLazyBytes`"

    - name: "Data.Text.unpack"
      within: ["MyPrelude"]
      message: "Use `textToString`"

    - name: "Data.Text.pack"
      within: ["MyPrelude"]
      message: "Use `stringToText`"

    - name: "Data.Maybe.listToMaybe"
      within: []
      message: |
        `listToMaybe`` throws away everything but the first element of a list (it is essentially `safeHead`).
        If that is what you want, please use a pattern match like

        ```
        case xs of
          [] -> …
          (x:_) -> …
        ```

    - name: "Data.List.head"
      within: []
      message: |
        `List.head` fails on an empty list. I didn’t think I have to say this, but please use a pattern match on the list, like:

        ```
        case xs of
          [] -> … error handling …
          (x:_) -> …
        ```

        Also think about why the rest of the list should be ignored.

    - name: "Prelude.head"
      within: []
      message: |
        `List.head` fails on an empty list. I didn’t think I have to say this, but please use a pattern match on the list, like.

        ```
        case xs of
          [] -> … error handling …
          (x:_) -> …
        ```

        Also think about why the rest of the list should be ignored.

    - name: "Data.Maybe.fromJust"
      within: []
      message: |
        `Maybe.fromJust` is obviously partial. Please use a pattern match.

        In case you actually want to throw an error on an empty list,
        please add an error message, like so:

        ```
        myMaybe & annotate "my error message" & unwrapError
        ```

        If you are in `IO`, use `unwrapIOError` instead,
        or throw a monad-specific error.

    - name: "Data.Either.fromLeft"
      within: []
      message: |
        `Either.fromLeft` is obviously partial. Please use a pattern match.

    - name: "Data.Either.fromRight"
      within: []
      message: |
        `Either.fromRight` is obviously partial. Please use a pattern match.

# Make restricted functions into an error if found
- error: { name: "Avoid restricted function, see comment in .hlint.yaml" }

# Some functions that have (more modern) aliases.
# They are not dangerous per se,
# but we want to make it easier to read our code so we should
# make sure we don’t use too many things that are renames.

- hint:
    lhs: "undefined"
    rhs: "todo"
    note: "`undefined` is a silent error, `todo` will display a warning as long as it exists in the code."

- hint:
    lhs: "return"
    rhs: "pure"
    note: "Use `pure` from `Applicative` instead, it’s the exact same function."

- hint:
    lhs: "mapM"
    rhs: "traverse"
    note: "Use `traverse` from `Traversable` instead. It’s the exact same function."

- hint:
    lhs: "mapM_"
    rhs: "traverse_"
    note: "Use `traverse_` from `Traversable` instead. It’s the exact same function."

- hint:
    lhs: "forM"
    rhs: "for"
    note: "Use `for` from `Traversable` instead. It’s the exact same function."

- hint:
    lhs: "forM_"
    rhs: "for_"
    note: "Use `for_` from `Traversable` instead. It’s the exact same function."

- hint:
    lhs: "stringToText (show x)"
    rhs: "showToText x"

- hint:
    lhs: "Data.Set.toList (Data.Set.fromList x)"
    rhs: "List.nubOrd x"
    note: "`nubOrd` removes duplicate elements from a list."

- modules:
    # Disallowed Modules
    - name: Data.Map
      within: []
      message: "Lazy maps leak space, use `import Data.Map.Strict as Map` instead"
    - name: Control.Monad.Writer
      within: []
      message: "Lazy writers leak space, use `Control.Monad.Trans.Writer.CPS` instead"
    - name: Control.Monad.Trans.Writer.Lazy
      within: []
      message: "Lazy writers leak space, use `Control.Monad.Trans.Writer.CPS` instead"
    - name: Control.Monad.Trans.Writer.Strict
      within: []
      message: "Even strict writers leak space, use `Control.Monad.Trans.Writer.CPS` instead"

    # Qualified module imports
    - { name: Data.Map.Strict, as: Map }
    - { name: Data.HashMap.Strict, as: HashMap }
    - { name: Data.Set, as: Set }
    - { name: Data.ByteString.Char8, as: Char8 }
    - { name: Data.ByteString.Lazy.Char8, as: Char8.Lazy }
    - { name: Data.Text, as: Text }
    - { name: Data.Vector, as: Vector }
    - { name: Data.Vault.Lazy, as: Vault }
    - { name: Data.Aeson, as: Json }
    - { name: Data.Aeson.Types, as: Json }
    - { name: Data.Aeson.BetterErrors as Json }