lspitzner / brittany

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

Strange hiding formatting #150

Closed pbrisbin closed 6 years ago

pbrisbin commented 6 years ago

With brittany-0.11.0.0, I'm getting the following for a long hiding import, is it intentional?

import Prelude as X
    hiding ( head
    , init
    , last
    , maximum
    , minimum
    , pred
    , read
    , readFile
    , succ
    , tail
    )

It looks quite weird to me, I would've expected this:

import Prelude as X hiding
    ( head
    , init
    , last
    , maximum
    , minimum
    , pred
    , read
    , readFile
    , succ
    , tail
    )

Or maybe this:

import Prelude as X
    hiding
        ( head
        , init
        , last
        , maximum
        , minimum
        , pred
        , read
        , readFile
        , succ
        , tail
        )

I'm using this configuration:

---
conf_debug:
  dconf_roundtrip_exactprint_only: false
  dconf_dump_bridoc_simpl_par: false
  dconf_dump_ast_unknown: false
  dconf_dump_bridoc_simpl_floating: false
  dconf_dump_config: false
  dconf_dump_bridoc_raw: false
  dconf_dump_bridoc_final: false
  dconf_dump_bridoc_simpl_alt: false
  dconf_dump_bridoc_simpl_indent: false
  dconf_dump_annotations: false
  dconf_dump_bridoc_simpl_columns: false
  dconf_dump_ast_full: false
conf_forward:
  options_ghc: []
conf_errorHandling:
  econf_ExactPrintFallback: ExactPrintFallbackModeInline
  econf_Werror: false
  econf_omit_output_valid_check: false
  econf_produceOutputOnErrors: false
conf_preprocessor:
  ppconf_CPPMode: CPPModeAbort
  ppconf_hackAroundIncludes: false
conf_version: 1
conf_layout:
  lconfig_altChooser:
    tag: AltChooserBoundedSearch
    contents: 3
  lconfig_importColumn: 60
  lconfig_alignmentLimit: 1
  lconfig_indentListSpecial: true
  lconfig_indentAmount: 4
  lconfig_alignmentBreakOnMultiline: true
  lconfig_cols: 80
  lconfig_indentPolicy: IndentPolicyLeft
  lconfig_indentWhereSpecial: true
  lconfig_columnAlignMode:
    tag: ColumnAlignModeDisabled
    contents: 0.7
pbrisbin commented 6 years ago

Oh, I'm sorry! I don't know for sure if this is caused by brittany, stylish-haskell, or the fact that I'm using both in the same project. I'm going to close and may re-open if I can suss that out.

EDIT: This is indeed Brittany. Using only stylish-haskell, I get:

import Prelude as X hiding
    (head, init, last, maximum, minimum, pred, read, readFile, succ, tail)

And I get a correct vertical alignment when I go past 80 columns.

lspitzner commented 6 years ago

@pbrisbin this fix produces the very basic

-- brittany { lconfig_indentPolicy: IndentPolicyLeft, lconfig_indentAmount: 4 }

import Prelude as X
    hiding
    ( head
    , init
    , last
    , maximum
    , minimum
    , pred
    , read
    , readFile
    , succ
    , tail
    , undefined
    )

I can change this to one of your proposed versions. I think I'd rather go with the second one, as the reader might overlook the "hiding" in the first version? What is your preference?

pbrisbin commented 6 years ago

Thanks for such a quick turn around! It's totally up to you if you want to change things further, but if you're asking for my own total ideal, it would be this:

(indent 4, columns 80)

import {module} (as {alias}) hiding
    ( ...
    )

But, if "import {module} (as {alias})" cross 80-columns, then

import qualified {super duper long module name} as {also super duper long alias name}
    hiding
        ( ...
        )

Or maybe this?

import qualified {super duper long module name}
    as {also super duper long alias name}
    hiding
        ( ...
        )