question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add `allowedPattern` in `quote-props`

See original GitHub issue

What 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 like dot-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 me Identifier is not in camel case.

So I want to wrap it with quotes and let ESlint judge it’s needed.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ilyavolodincommented, Mar 26, 2017

@platinumazure Issue has been updated. Sort-of.

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.

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.

1reaction
not-an-aardvarkcommented, Mar 27, 2017

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 the camelcase rule.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using regular expressions in AWS CloudFormation templates
Regular expressions (commonly known as regexes) can be specified in a number of places within an AWS CloudFormation template, such as for the...
Read more >
Options - Prettier
Quote Props. Change when properties in objects are quoted. Valid options: "as-needed" - Only add quotes around object properties where required.
Read more >
AllowedPattern parameter behaviour apparently failing to ...
The AllowedPattern Parameters property requires the pattern to match the ... To match more than one character, you need to add a "greedy ......
Read more >
AllowedPattern for emails in Cloudformation template
Important. Since AWS CloudFormation templates use the JSON syntax for specifying objects and data, you will need to add an additional ...
Read more >
Solved: CloudFormation Samples - Esri Community
You need to add default values for all your parameters. Refer the following aws document ... "AllowedPattern": "^[a-zA-Z][a-zA-Z0-9_]{6,}$",
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found