Gleam: Provide a better warning when rejecting camelCase

Created on 30 Jan 2021  ยท  4Comments  ยท  Source: gleam-lang/gleam

camelCase variables are forbidden by the compiler to eliminate bikeshedding over naming conventions, but the current error doesn't communicate that at all:

error: Syntax error
    โ”Œโ”€ /.../thing..gleam:115:18
    โ”‚
115 โ”‚ pub fn overlappedBy(compare: fn (a, a) -> Order, a: Interval(a), b: Interval(a)) -> Bool {
    โ”‚                  ^^ I was not expecting this.

Expected one of: "("

It'd be good if the error explained why this is a syntax error, if you're coming from most other languages this will be quite confusing otherwise. I suggest:

error: Syntax error
    โ”Œโ”€ /.../thing..gleam:115:18
    โ”‚
115 โ”‚ pub fn overlappedBy(compare: fn (a, a) -> Order, a: Interval(a), b: Interval(a)) -> Bool {
    โ”‚                  ^^ I was not expecting this.

Gleam only allows lowercase letters and underscores in variable and type names. Try:

    overlappedby
    overlapped_by

Maybe with a little hint explaining its to avoid arguments over naming styles.

error-messaging good first issue help wanted

Most helpful comment

That looks perfect, let's do that

All 4 comments

Good idea! Thank you

Great suggestion. What do y'all think about:

error: Syntax error
    โ”Œโ”€ /.../thing..gleam:115:18
    โ”‚
115 โ”‚ pub fn overlappedBy(compare: fn (a, a) -> Order, a: Interval(a), b: Interval(a)) -> Bool {
    โ”‚        ^^^^^^^^^^^^ This is not a valid name.

Hint: In Gleam names must start with a lowercase letter and contain only lowercase letters, numbers, and '_'.
Try: overlapped_by

For the Try: I'm thinking calling .snake_case() is probably good enough.

That looks perfect, let's do that

I'm working on this! I'll throw up a patch shortly.

Was this page helpful?
0 / 5 - 0 ratings