Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Warnings on problematic indentation #135

Open
SquidDev opened this issue Nov 17, 2018 · 0 comments
Open

Warnings on problematic indentation #135

SquidDev opened this issue Nov 17, 2018 · 0 comments

Comments

@SquidDev
Copy link
Member

SquidDev commented Nov 17, 2018

Within the pre-parse/context system, we should warn in various circumstances if the indentation is a little wobbly. We already have such a warning for silly ins:

let x = ()
   in x
(* ^ Produces a warning, as the in should be aligned with the let *)

However, there are other forms we could also warn on:

Misaligned and

let a = ()
   and b = 2 
(* ^ Produce a warning here *)
in x

One thing to be aware of here, is that we shouldn't warn when one has multiple ands on one line: only the first one for each line should be considered.

Misaligned |

Similar to above, but for matches and functions - all |s should be aligned, unless they are on the same line. One thing to be aware of is that they do not have to align with the parent expression (though obviously it's prettier if they do).

Offside expressions

We should warn when an expression appears to the left of one parent's offside location. Some examples:

let () = 
  let x = (
2 (* Offside compared with x, but won't be picked up as it's inside a parenthesis.
  ) in x
let () = 
  let x = function
| _ -> () (* Similar to above *)

I think the cleanest rule here is just "should not occur to the far left of the line which started the parent context". This is a bit verbose, but probably is the most flexible while still resulting in sane code.

Automatic correction

One awesome thing to try would be proving a way to automatically fix indentation warnings in the source code. However, I suspect we'd have to look into providing some sort of framework for transforming code while still preserving formatting, which is a long way away.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant