commandbox-cfformat icon indicating copy to clipboard operation
commandbox-cfformat copied to clipboard

Struct key quoting consistency

Open bockensm opened this issue 4 years ago • 1 comments

Would it be possible to expand formatting rule for when struct keys need to be quoted to be a bit more like ESLint's rule? https://eslint.org/docs/rules/quote-props

While I generally don't have a need to require that struct keys be quoted or not, I do want to enforce consistency so we don't end up with half the keys quoted and half not quoted in the same struct definition. I'm referring to struct shorthand here:

data = {
    key1: "value",
    "key2": "value"
};

The consistent option from ESLint would be a great addition to the rules here. consistent-as-needed would also be nice but I know it's not possible for a tool to know that I've quoted all of the keys for a specific reason even though there aren't any invalid key characters. consistent would probably have to see quote all props if a single one is quoted. The main difference to the current settings would be that it would only quote all props if one is quoted vs forcing all to be quoted all the time.

bockensm avatar Apr 27 '21 14:04 bockensm

This request would take a bit more work, but again, I think it is doable in principle. However, this too would be tricky with regards to backwards compatibility, as right now the struct.quote_keys setting is a boolean setting. Switching from a boolean setting would break backwards compatibility, and I am not eager to define another setting, and then figure out what the interplay would be between the current setting and the additional setting. This is also made trickier by the fact that it wouldn’t just change how things are formatted, it could additionally make everyone’s current settings files invalid.

jcberquist avatar May 02 '21 21:05 jcberquist