SpacemanDMM
SpacemanDMM copied to clipboard
[Feature Request] Warn about associative list variable key disambiguation
If you have a var (let's call it var/foo
) in the scope of an assoc list with a naked string key that's the same as that var, the linter should suggest disambiguating it.
var/foo = "bar"
world.log << json_encode(list(foo = "plaintext key", (foo) = "variable key"))
yields
{"foo":"plaintext key","bar":"variable key"}
Usually, people will use the former syntax and assume it will use the variable's value as the key; however, due to a convenience feature allowing text keys to go unquoted, BYOND will use the variable name itself as the key unless it's wrapped in parentheses.
A resolution to this would be to suggest disambiguating it:
list(foo = bar) -> list("foo" = bar)
to disambiguate, list(foo = bar) -> list((foo) = bar)
to fix.
This could probably either be done for all unquoted string keys, at which point it's a style thing and should probably be behind a config option, or only for unquoted keys that match a variable in the current scope.
Additionally, in my tests, (MACRO)
is taken as a constant value, just like MACRO
; I think this is purely a syntax change to force a certain interpretation by the parser, which makes it an advantage over "[foo]"
.