kowainik / stan

🕵️ Haskell STatic ANalyser
https://kowainik.github.io/projects/stan
Mozilla Public License 2.0
566 stars 48 forks source link

Inspection on field order in Semigroup instances #387

Open chshersh opened 4 years ago

chshersh commented 4 years ago

Consider the following code:

data RowLen = RowLen
    { rowLenModule :: !Int
    , rowLenLine   :: !Int
    , rowLenSev    :: !Int
    , rowLenMax    :: !Int
    , rowLenAvg    :: !Int
    }

instance Semigroup RowLen where
    RowLen a1 b1 c1 d1 e1 <> RowLen a2 b2 c2 d2 e2 =
      RowLen (max a1 a2) (max b1 b2) (max c1 c2) (max d1 d2) (max e1 e2)

This code involves some boilerplate and it's easy to introduce an error in there. We could implement an inspection that checks corresponding order of fileds on the leftt and right sides.