Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upCamelcase issue with JSON object from outer source and Object Matching Shorthand Notation. #985
Comments
This comment has been minimized.
This comment has been minimized.
|
@NightfallAlicorn For cases like this I just disable the camelcase rule: https://github.com/standard/standard#how-do-i-hide-a-certain-warning |
This comment has been minimized.
This comment has been minimized.
|
The idea with the rule is to not have any local variables not named in camel-case. I think that this would be the best approach: const {
example_property1: exampleProperty1,
example_property2: exampleProperty2,
example_property3: exampleProperty3
} = result.someJSON |
This comment has been minimized.
This comment has been minimized.
|
You can also disable the rule for the file or use the destructuring trick. The go JSON encoder is doing this again, isn't it >:[ |
This comment has been minimized.
This comment has been minimized.
const {
example_property1,
example_property2,
example_property3
} = result.someJSON
this.emit('someEvent', example_property1)It seems fine if it's put it in a function param. Thanks for your suggestions, guys. |
This comment has been minimized.
This comment has been minimized.
indiesquidge
commented
Jan 15, 2018
•
|
I agree with @NightfallAlicorn that this rule seems to become a nuisance when dealing with API objects. I could live with providing a name for the variables (e.g. #985 (comment)), but on top of @NightfallAlicorn's example of passing the destructured variable directly to a function, I would also like to consider the case when variables are destructured because you don't want to use them at all const { example_property1, example_property2, ...rest } = result.someJSONWhat if my only intent is to use the Yes, I could add variable names for the first properties, but that seems to send a confusing message to people reading this code later on: why am I giving these variables names if I do not plan on using them? I will simply add a comment to disable Standard for this part of my code for now, but it seems like there is more than one case in which this strict of a rule need not apply. |
This comment has been minimized.
This comment has been minimized.
|
A common pattern is to name unused variables with underscores, and as far as I know standard won't complain when the name is only underscores, this something like this should work and will signal the intent clearly. const { example_property1: _, example_property2: __, ...rest } = result.someJSONNot saying it's the best solution though, but I'm not sure that I like creating variables that aren't used either. This is very neat in Rust where |
This comment has been minimized.
This comment has been minimized.
stale
bot
commented
May 10, 2018
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
NightfallAlicorn commentedSep 14, 2017
I don't know if I should add an ignore comment to the code or mention it here. I did a search but nothing came up.
Visual Studio Code brings up this message "[standard] Identifier 'example_property1' is not in camel case. (camelcase)". However the
someJSONis from an external source through https.request and I'm trying to keep my script short and simple.Another solution is:
This result feels bloated. My actual script has 17 lines to declare.
Maybe allow Object Matching Shorthand Notation to allow external JSON decorations as long as they weren't declared in the current file?