@@ -19,7 +19,6 @@ module Dhall.Lint
19
19
) where
20
20
21
21
import Control.Applicative ((<|>) )
22
- import Data.List.NonEmpty (NonEmpty (.. ))
23
22
24
23
import Dhall.Syntax
25
24
( Binding (.. )
@@ -38,7 +37,6 @@ import Dhall.Syntax
38
37
39
38
import qualified Data.Foldable as Foldable
40
39
import qualified Data.List.NonEmpty as NonEmpty
41
- import qualified Data.Map as Map
42
40
import qualified Data.Text as Text
43
41
import qualified Dhall.Core as Core
44
42
import qualified Dhall.Map
@@ -63,7 +61,6 @@ lint = Dhall.Optics.rewriteOf subExpressions rewrite
63
61
<|> fixParentPath e
64
62
<|> removeLetInLet e
65
63
<|> addPreludeExtensions e
66
- <|> sortImports e
67
64
68
65
-- | Remove unused `Let` bindings.
69
66
removeUnusedBindings :: Eq a => Expr s a -> Maybe (Expr s a )
@@ -212,53 +209,3 @@ useToMap (ListLit _ keyValues)
212
209
Nothing
213
210
useToMap _ =
214
211
Nothing
215
-
216
- -- | This sorts `let` bindings to move imports to the front if doing so does not
217
- -- change the behavior of the code.
218
- sortImports :: Eq s => Expr s Import -> Maybe (Expr s Import )
219
- sortImports oldExpression@ (Let binding0 oldBody0)
220
- | oldExpression == newExpression = Nothing
221
- | otherwise = Just newExpression
222
- where
223
- toBool (Embed _ ) = False
224
- toBool (Note _ e) = toBool e
225
- toBool _ = True
226
-
227
- process (seen, index) Binding {.. } oldBody function = (pair, pairs, newBody)
228
- where
229
- order =
230
- if b then index else Map. findWithDefault (0 :: Int ) variable seen
231
-
232
- b = toBool value
233
-
234
- pair = (order, function)
235
-
236
- ~ (pairs, newBody) =
237
- label (Map. insert variable order seen, index + 1 ) oldBody
238
-
239
- label state (Let binding oldBody) = (pair : pairs, newBody)
240
- where
241
- function = Let binding
242
-
243
- ~ (pair, pairs, newBody) = process state binding oldBody function
244
-
245
- label state (Note src (Let binding oldBody)) = (pair : pairs, newBody)
246
- where
247
- function e = Note src (Let binding e)
248
-
249
- ~ (pair, pairs, newBody) = process state binding oldBody function
250
-
251
- label _ body =
252
- ([] , body)
253
-
254
- ~ (pairs0, newBody0) = (pair :| pairs, newBody)
255
- where
256
- function = Let binding0
257
-
258
- ~ (pair, pairs, newBody) =
259
- process (Map. empty, 1 ) binding0 oldBody0 function
260
-
261
- sortedFunctions = fmap snd (NonEmpty. sortWith fst pairs0)
262
-
263
- newExpression = foldr id newBody0 sortedFunctions
264
- sortImports _ = Nothing
0 commit comments