openhab / openhab-vscode

VS Code extension for openHAB configuration files
https://marketplace.visualstudio.com/items?itemName=openhab.openhab
Eclipse Public License 2.0
159 stars 47 forks source link

Pascal Case is used for new Item names #132

Closed thewilli closed 5 years ago

thewilli commented 5 years ago

This extension allows for creating Item definitions including bindings from Things.

Expected Behavior

If I look at the Item documentation, all Item names are spelled using Upper Snake Case. The documentation for all of the official Bindings that I've checked behaves the same - and so do the many tutorials found online.

Guest Bathroom Switch => Guest_Bathroom_Switch

Current Behavior

In order to generate a new name for an Item, the classify() function of the underscore.string library is used internally. The result is a Pascal Case conversion of the Thing name.

Guest Bathroom Switch => GuestBathroomSwitch

Possible Solution

the first which comes into my mind would be something like

// result: "Foo_Bar_Baz_XY"
_.classify("Foo Bar baz XY").replace(/(?<=[^A-Z])([A-Z])/g, "_$1")

// instead of

// result: "FooBarBazXY"
_.classify("Foo Bar baz XY")

Steps to Reproduce (for Bugs)

Context

I think that the current behavior:

Your Environment

SamuelBrucksch commented 5 years ago

Ok so you want to have Bathroom_Light instead of BathroomLight?

I have not seen any documentation yet, that says how to case item names. if you look at the grammar everything from Camel Case to lower case to snake case to whatever case is possible. You can even start with digits if you want: https://github.com/eclipse/smarthome/blob/7176f8961a4caba501fe38bab52a44c8705011c3/bundles/model/org.eclipse.smarthome.model.item/src/org/eclipse/smarthome/model/Items.xtext#L67

terminal ID         : '^'?('a'..'z'|'A'..'Z'|'_'|'0'..'9') ('a'..'z'|'A'..'Z'|'_'|'-'|'0'..'9')*;

there are no restrictions on how to write the item names. i dont think that anyone is confused by case conventions here.

I guess all the other docs are more or less just copy&paste of the original docs.

here for example is a binding that just uses lower case: https://www.openhab.org/addons/bindings/anel1/#item-configuration

Same here: https://www.openhab.org/addons/bindings/asterisk1/

here it is even mixed: https://www.openhab.org/addons/bindings/astro/

Its a bit extreme to say everyone does it like that.

However i would accept that some people want to define a way how items and names of generated parts are generated. So what i would propose is to add a config where you can set naming convention you want to use. however as this is in my opinion quite low prio at least i would not start with this for a while. However feel free to open a PR or give ideas on how to achieve an ideal solution for this.

thewilli commented 5 years ago

However feel free to open a PR or give ideas on how to achieve an ideal solution for this.

@SamuelBrucksch

133: here you go :wink: