CppCXY / EmmyLuaCodeStyle

fast, powerful, and feature-rich Lua formatting and checking tool.
MIT License
140 stars 27 forks source link

Additional name style categories #158

Closed AndreaWalchshoferSCCH closed 9 months ago

AndreaWalchshoferSCCH commented 10 months ago

There are 2 concepts in Lua for which I'd like to set a name style specifically:

  1. Constants, constants_name_style e.g. for local PI <const> = 3.14, I want to force UPPER_SNAKE_CASE, but don't want to allow it for all local variables (as I am now)

  2. Module-local variables, module_local_name_style e.g.

    
    local _module1 = {};

local _variable = "module_local_variable"

-- more code

return _module1;


I want to force variables like `_variable` to be named with e.g. a leading underscore, but it is currently mixed into all local variable name styles as well. As these may collide with other namestyles, e.g. the constants above, the rule should be applied if it's not constant/module definition/module import already.

- Is it technically possible to add these options to the namestyle configurations?
- And is it something you would accept (/implement) in the formatter, or do you see any problems with it we should discuss?

Thank you!
CppCXY commented 10 months ago

we already have module_name_style, and the constant local t isn't too difficult, but the current parser and syntax tree aren't designed for code analysis, so it's still a bit of a pain in the ass to use, and I'll work on that when I get a chance. Maybe like this project https://github.com/CppCXY/EmmyLuaAnalyzer. I'm currently working hard on this project, so I probably don't have a lot of energy to deal with this side of things.