lspitzner / lspitzner/brittany

Operator precedence sensitive layout

Open
#79 13 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Haskell
Stars
686
Forks
69
PR merge metrics
No merged PRs in 30d

Description

Consider the following piece of code as formatted by britanny:

dP =
  string "ne"
    $>  NE
    <|> string "nw"
    $>  NW
    <|> string "n"
    $>  N
    <|> string "se"
    $>  SE
    <|> string "sw"
    $>  SW
    <|> string "s"
    $>  S

This doesn't reflect the precedence of the operators involved very well and also makes the meaning less clear.

I would expect it to be formatted as such:

dP =
  string "ne" $>  NE
  <|> string "nw" $>  NW
  <|> string "n" $>  N
  <|> string "se" $>  SE
  <|> string "sw" $>  SW
  <|> string "s" $>  S

And I am sure there are other cases where long expressions with different operators could be layed out better if precedence was taken into account.

Is this something brittany can do?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Haskell example in the issue and locate brittany's layout handling for long expressions with mixed operators. Compare the current output with the expected grouping, then verify the formatter preserves operator precedence across additional mixed-precedence cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.