gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Convert variable names to snake_case

Open GearsDatapacks opened this issue 2 months ago • 5 comments

Closes #2978 Let me summarise what I've done:

  • BadName errors are now no longer reported in the lexer. The lexer treats all previous bad names as valid.
  • The analyser now is responsible for validating names. It checks the name of variables (let, use and const), functions, parameters, types and type constructors.
  • Finding an error in a variable name still declares it, to allow any references to that variable to still type-check correctly.
  • When the analyser finds an invalid name, it adds it to a bad_names array, just like unused_imports.
  • I've had to add more location information to certain ast nodes to allow proper renaming of variables without overwriting other parts of the source code

The main problem I see with this approach is that it would be easy to miss validation of names in certain places, but I can't think of an easy way to check all names in the analyser. This implementation also doesn't rename any references to invalid variables, but #2956 may need to be closed before that's possible/easy to add.

GearsDatapacks avatar Jun 13 '24 18:06 GearsDatapacks