Skip to content

Commit

Permalink
Fix: quotes false positive with backtick option in method names (#8327)
Browse files Browse the repository at this point in the history
This commit updates the `quotes` rule to not report quoted class method names when the backtick option is enabled, because backticks are not allowed as non-computed class method names.
  • Loading branch information
not-an-aardvark authored and gyandeeps committed Mar 27, 2017
1 parent d064ba2 commit cd9b774
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/rules/quotes.js
Expand Up @@ -209,6 +209,7 @@ module.exports = {

// LiteralPropertyName.
case "Property":
case "MethodDefinition":
return parent.key === node && !parent.computed;

// ModuleSpecifier.
Expand Down
18 changes: 15 additions & 3 deletions tests/lib/rules/quotes.js
Expand Up @@ -68,8 +68,10 @@ ruleTester.run("quotes", rule, {
{ code: "import a from \"a\"; import b from 'b';", options: ["backtick"], parserOptions: { sourceType: "module" } },
{ code: "export * from \"a\"; export * from 'b';", options: ["backtick"], parserOptions: { sourceType: "module" } },

// `backtick` should not warn property names (not computed).
{ code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }
// `backtick` should not warn property/method names (not computed).
{ code: "var obj = {\"key0\": 0, 'key1': 1};", options: ["backtick"], parserOptions: { ecmaVersion: 6 } },
{ code: "class Foo { 'bar'(){} }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } },
{ code: "class Foo { static ''(){} }", options: ["backtick"], parserOptions: { ecmaVersion: 6 } }
],
invalid: [
{
Expand Down Expand Up @@ -205,7 +207,7 @@ ruleTester.run("quotes", rule, {
errors: [{ message: "Strings must use backtick.", type: "Literal" }]
},

// `backtick` should not warn computed property names.
// `backtick` should warn computed property names.
{
code: "var obj = {[\"key0\"]: 0, ['key1']: 1};",
output: "var obj = {[`key0`]: 0, [`key1`]: 1};",
Expand All @@ -216,6 +218,16 @@ ruleTester.run("quotes", rule, {
{ message: "Strings must use backtick.", type: "Literal" }
]
},
{
code: "class Foo { ['a'](){} static ['b'](){} }",
output: "class Foo { [`a`](){} static [`b`](){} }",
options: ["backtick"],
parserOptions: { ecmaVersion: 6 },
errors: [
{ message: "Strings must use backtick.", type: "Literal" },
{ message: "Strings must use backtick.", type: "Literal" }
]
},

// https://github.com/eslint/eslint/issues/7084
{
Expand Down

0 comments on commit cd9b774

Please sign in to comment.