lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
690 stars 72 forks source link

Guards lead to unreadable code #304

Open jrp2014 opened 4 years ago

jrp2014 commented 4 years ago

Brittany generally does a great job, but he following code is not rendered very prettily:

  91 usedImport dynflags action anns impPs@(L (RealSrcSpan locPs) declPs) (L (RealSrcSpan _) declRn, used, unused)
   92 
   93 -- unused applies to an explicit import list.  It will be null for a simple module
   94 -- imports
   95 
   96   | -- Do not remove `import M ()`
   97     Just (False, L _ []) <- ideclHiding declRn
   98   = (anns, [impPs])
   99   | -- Note [Do not warn about Prelude hiding]
  100     -- TODO: add ability to support custom prelude
  101     Just (True, L _ hides) <- ideclHiding declRn
  102   , not (null hides)
  103   , ideclImplicit declRn -- pRELUDE_NAME == unLoc (ideclName decl)
  104   = (anns, [impPs])
  105   | -- Nothing used
  106     null used
  107   = case action of

Putting the "=" under the "|" seems to be part of the cause. Putting the comments on the same line as the "|" rather than on a preceding line is another thing that could be improved.

(ormolu is better, but not much)

   92 usedImport dynflags action anns impPs@(L (RealSrcSpan locPs) declPs) (L (RealSrcSpan _) declRn, used, unused)
   93   -- unused applies to an explicit import list.  It will be null for a simple module
   94   -- import
   95 
   96   | -- Do not remove `import M ()`
   97     Just (False, L _ []) <- ideclHiding declRn =
   98     (anns, [impPs])
   99   | -- Note [Do not warn about Prelude hiding]
  100     -- TODO: add ability to support custom prelude
  101     Just (True, L _ hides) <- ideclHiding declRn,
  102     not (null hides),
  103     ideclImplicit declRn = -- pRELUDE_NAME == unLoc (ideclName decl)
  104     (anns, [impPs])
  105   | -- Nothing used
  106     null used =