Skip to content

Commit

Permalink
Sort weeds by column too (#155)
Browse files Browse the repository at this point in the history
* Rewrite tests to use `tasty` & `tasty-golden`

* Sort weeds by column too

---------

Co-authored-by: Ollie Charles <[email protected]>
Co-authored-by: Tom Sydney Kerckhove <[email protected]>
  • Loading branch information
3 people authored Jun 9, 2024
1 parent 4a160e3 commit 2fb2eb9
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 30 deletions.
8 changes: 5 additions & 3 deletions src/Weeder.hs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import GHC.Types.Name
, isVarOcc
, occNameString
)
import GHC.Types.SrcLoc ( RealSrcSpan, realSrcSpanEnd, realSrcSpanStart, srcLocLine )
import GHC.Types.SrcLoc ( RealSrcSpan, realSrcSpanEnd, realSrcSpanStart, srcLocLine, srcLocCol )

-- lens
import Control.Lens ( (%=) )
Expand Down Expand Up @@ -157,7 +157,7 @@ data Analysis =
Analysis
{ dependencyGraph :: Graph Declaration
-- ^ A graph between declarations, capturing dependencies.
, declarationSites :: Map Declaration (Set Int)
, declarationSites :: Map Declaration (Set (Int, Int))
-- ^ A partial mapping between declarations and their line numbers.
-- This Map is partial as we don't always know where a Declaration was
-- defined (e.g., it may come from a package without source code).
Expand Down Expand Up @@ -350,7 +350,9 @@ addInstanceRoot x t cls = do
define :: MonadState Analysis m => Declaration -> RealSrcSpan -> m ()
define decl span =
when ( realSrcSpanStart span /= realSrcSpanEnd span ) do
#declarationSites %= Map.insertWith Set.union decl ( Set.singleton . srcLocLine $ realSrcSpanStart span )
let start = realSrcSpanStart span
let loc = (srcLocLine start, srcLocCol start)
#declarationSites %= Map.insertWith Set.union decl ( Set.singleton loc)
#dependencyGraph %= overlay ( vertex decl )


Expand Down
10 changes: 6 additions & 4 deletions src/Weeder/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ import Weeder.Config

data Weed = Weed
{ weedPath :: FilePath
, weedLoc :: Int
, weedLine :: Int
, weedCol :: Int
, weedDeclaration :: Declaration
, weedPrettyPrintedType :: Maybe String
}


formatWeed :: Weed -> String
formatWeed Weed{..} =
weedPath <> ":" <> show weedLoc <> ": "
weedPath <> ":" <> show weedLine <> ":" <> show weedCol <> ": "
<> case weedPrettyPrintedType of
Nothing -> occNameString ( declOccName weedDeclaration )
Just t -> "(Instance) :: " <> t
Expand Down Expand Up @@ -121,10 +122,11 @@ runWeeder weederConfig@Config{ rootPatterns, typeClassRoots, rootInstances } hie

weeds =
Map.toList warnings & concatMap \( weedPath, declarations ) ->
sortOn fst declarations & map \( weedLoc, weedDeclaration ) ->
sortOn fst declarations & map \( (weedLine, weedCol) , weedDeclaration ) ->
Weed { weedPrettyPrintedType = Map.lookup weedDeclaration (prettyPrintedType analysis)
, weedPath
, weedLoc
, weedLine
, weedCol
, weedDeclaration
}

Expand Down
4 changes: 2 additions & 2 deletions test/Spec/ApplicativeDo.failing
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/ApplicativeDo/ApplicativeDo.hs:6: (Instance) :: Functor Foo
test/Spec/ApplicativeDo/ApplicativeDo.hs:9: (Instance) :: Applicative Foo
test/Spec/ApplicativeDo/ApplicativeDo.hs:6:1: (Instance) :: Functor Foo
test/Spec/ApplicativeDo/ApplicativeDo.hs:9:1: (Instance) :: Applicative Foo
2 changes: 1 addition & 1 deletion test/Spec/BasicExample.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/BasicExample/BasicExample.hs:4: unrelated
test/Spec/BasicExample/BasicExample.hs:4:1: unrelated
4 changes: 2 additions & 2 deletions test/Spec/ConfigInstanceModules.stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/ConfigInstanceModules/Module1.hs:3: (Instance) :: Show T
test/Spec/ConfigInstanceModules/Module2.hs:3: (Instance) :: Bounded T
test/Spec/ConfigInstanceModules/Module1.hs:3:24: (Instance) :: Show T
test/Spec/ConfigInstanceModules/Module2.hs:3:30: (Instance) :: Bounded T
2 changes: 1 addition & 1 deletion test/Spec/DeriveGeneric.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/DeriveGeneric/DeriveGeneric.hs:12: (Instance) :: FromJSON T
test/Spec/DeriveGeneric/DeriveGeneric.hs:12:7: (Instance) :: FromJSON T
4 changes: 2 additions & 2 deletions test/Spec/InstanceTypeclass.stdout
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:4: Foo
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:10: (Instance) :: Foo Char
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:4:1: Foo
test/Spec/InstanceTypeclass/InstanceTypeclass.hs:10:1: (Instance) :: Foo Char
6 changes: 3 additions & 3 deletions test/Spec/Monads.failing
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test/Spec/Monads/Monads.hs:20: (Instance) :: Functor Identity'
test/Spec/Monads/Monads.hs:23: (Instance) :: Applicative Identity'
test/Spec/Monads/Monads.hs:27: (Instance) :: Monad Identity'
test/Spec/Monads/Monads.hs:20:1: (Instance) :: Functor Identity'
test/Spec/Monads/Monads.hs:23:1: (Instance) :: Applicative Identity'
test/Spec/Monads/Monads.hs:27:1: (Instance) :: Monad Identity'
2 changes: 1 addition & 1 deletion test/Spec/NumInstanceLiteral.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/NumInstanceLiteral/NumInstanceLiteral.hs:7: (Instance) :: Num Modulo1
test/Spec/NumInstanceLiteral/NumInstanceLiteral.hs:7:1: (Instance) :: Num Modulo1
2 changes: 1 addition & 1 deletion test/Spec/OverloadedLabels.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedLabels/OverloadedLabels.hs:17: (Instance) :: Has Point "y" Int
test/Spec/OverloadedLabels/OverloadedLabels.hs:17:1: (Instance) :: Has Point "y" Int
2 changes: 1 addition & 1 deletion test/Spec/OverloadedLists.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedLists/OverloadedLists.hs:9: (Instance) :: IsList (BetterList x)
test/Spec/OverloadedLists/OverloadedLists.hs:9:1: (Instance) :: IsList (BetterList x)
2 changes: 1 addition & 1 deletion test/Spec/OverloadedStrings.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/OverloadedStrings/OverloadedStrings.hs:10: (Instance) :: IsString BetterString
test/Spec/OverloadedStrings/OverloadedStrings.hs:10:1: (Instance) :: IsString BetterString
2 changes: 1 addition & 1 deletion test/Spec/RangeEnum.failing
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/RangeEnum/RangeEnum.hs:14: (Instance) :: Enum Colour
test/Spec/RangeEnum/RangeEnum.hs:14:13: (Instance) :: Enum Colour
2 changes: 1 addition & 1 deletion test/Spec/RootClasses.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/RootClasses/RootClasses.hs:5: (Instance) :: Enum T
test/Spec/RootClasses/RootClasses.hs:5:34: (Instance) :: Enum T
2 changes: 1 addition & 1 deletion test/Spec/StandaloneDeriving.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/StandaloneDeriving/StandaloneDeriving.hs:6: (Instance) :: Show A
test/Spec/StandaloneDeriving/StandaloneDeriving.hs:6:1: (Instance) :: Show A
2 changes: 1 addition & 1 deletion test/Spec/Types.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test/Spec/Types/Usages.hs:16: notRoot
test/Spec/Types/Usages.hs:16:1: notRoot
8 changes: 4 additions & 4 deletions test/Spec/TypesUnused.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test/Spec/TypesUnused/TypesUnused.hs:6: Modulo1
test/Spec/TypesUnused/TypesUnused.hs:8: Number
test/Spec/TypesUnused/TypesUnused.hs:10: Vector
test/Spec/TypesUnused/TypesUnused.hs:12: Family
test/Spec/TypesUnused/TypesUnused.hs:6:1: Modulo1
test/Spec/TypesUnused/TypesUnused.hs:8:1: Number
test/Spec/TypesUnused/TypesUnused.hs:10:1: Vector
test/Spec/TypesUnused/TypesUnused.hs:12:1: Family

0 comments on commit 2fb2eb9

Please sign in to comment.