Skip to content

Improve auto-format of modules and declaration names #107

@georgesboris

Description

@georgesboris

I'm using elm-codegen for the first time and found some inconsistent behavior. Let me know what you think!

  • Elm.file does not format the module name - so ["My", "module"] would generate an invalid elm module.
  • Elm.declaration does format the declaration name, but only by lowercasing the first letter.

Since both of these scenarios have some strict rules, maybe it would be worth to enforce them automatically?
An example solution using elmcraft/core-extra as dependency (for brevity sake):

toModulePart string =
  String.Extra.classify string

toDeclarationName string =
  let
      classifiedString =
          String.Extra.classify string
  in
  (String.toLower (String.left 1 classifiedString)) ++ (String.dropLeft 1 classifiedString)

Note

  1. Since these rules are compiled enforced, I don't think there would be backwards compatibility problems, right? Anything else would be causing compile errors anyway. This would, at worst, automatically fix those.
  2. This could probably be applied to other scenarios that I haven't tried yet like type definitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions