add `allowedPattern` in `quote-props`
See original GitHub issueWhat rule do you want to change?
quote-props
Does this change cause the rule to produce more or fewer warnings?
I want anything not in camel case to be quote-wrapped in object definition.
{
appId: ...,
"content-type": ...,
"underscore_thing": ...
}
Because I regard any key in object as a variable name and variable name should be camel case. If it’s not in camel case, it should be wrapped with quotes so that I can regard it as a string.
In fact, I have another configuration in read:
// enforce dot notation whenever possible
"dot-notation": [ "error", {
allowPattern: "([a-zA-Z0-9])(_)+([a-zA-Z0-9])"
}],
That mean I can write code like:
temp.aAndB = 1;
temp._a_ = 2;
temp["a_1"] = 3;
temp["a-1"] = abcdeft();
temp["__a_____b__"] = .4;
How will the change be implemented? (New option, new default behavior, etc.)?
Two ways:
- Regard underscored key as
quote-needed
so that it won’t occur warnings. - Add an options
allowPattern
just likedot-notation
do.
Please provide some example code that this change will affect:
{
appId: ...,
"underscore_thing": ...
}
What does the rule currently do for this code?
Unnecessarily quoted property found.
What will the rule do after it’s changed?
No warning.
The previous version of this issue
Tell us about your environment
- ESLint Version: 3.16.1
- Node Version: 6.9.1
- npm Version: 2.16.11
What parser (default, Babel-ESLint, etc.) are you using?
default.
Please show your full configuration:
https://github.com/XadillaX/eslint-config-xadillax-style
What did you do? Please include the actual source code causing the issue.
const query = { appid: akyuu.config.appId, "redirect_uri": `${akyuu.config.server.baseUrl}/signin`, "response_type": "code" };
What did you expect to happen?
I want anything not in camel case to be quote-wrapped in object definition.
{ appId: ..., "content-type": ..., "underscore_thing": ... }
Because I regard any key in object as a variable name and variable name should be camel case. If it’s not in camel case, it should be wrapped with quotes so that I can regard it as a string.
In fact, I have another configuration in read:
// enforce dot notation whenever possible "dot-notation": [ "error", { allowPattern: "([a-zA-Z0-9])(_)+([a-zA-Z0-9])" }],
That mean I can write code like:
temp.aAndB = 1; temp._a_ = 2; temp["a_1"] = 3; temp["a-1"] = abcdeft(); temp["__a_____b__"] = .4;
What actually happened? Please include the actual, raw output from ESLint.
When I wrapped with quotes, it shows me
Unnecessarily quoted property found
. And when I removed the quotes, it shows meIdentifier is not in camel case
.So I want to wrap it with quotes and let ESlint judge it’s needed.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
@platinumazure Issue has been updated. Sort-of.
This seems like an extremely personal preference. I can’t say that I’ve ever seen anyone doing that. So I don’t think this would be a good fit for the core. I would suggest that you copy the rule and create your own implementation as a plugin.
I think the solution for that issue would be to not enforce that property names must be camelcase. You can do that by setting the
properties: never
option in thecamelcase
rule.