Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: check template literal in no-proto, no-iterator (fixes #12801) #12806

Merged
merged 3 commits into from Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions lib/rules/no-iterator.js
Expand Up @@ -5,6 +5,12 @@

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const { getStaticPropertyName } = require("./utils/ast-utils");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -33,9 +39,7 @@ module.exports = {

MemberExpression(node) {

if (node.property &&
(node.property.type === "Identifier" && node.property.name === "__iterator__" && !node.computed) ||
(node.property.type === "Literal" && node.property.value === "__iterator__")) {
if (getStaticPropertyName(node) === "__iterator__") {
context.report({
node,
messageId: "noIterator"
Expand Down
11 changes: 7 additions & 4 deletions lib/rules/no-proto.js
Expand Up @@ -5,6 +5,12 @@

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const { getStaticPropertyName } = require("./utils/ast-utils");

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
Expand All @@ -28,10 +34,7 @@ module.exports = {
return {

MemberExpression(node) {

if (node.property &&
(node.property.type === "Identifier" && node.property.name === "__proto__" && !node.computed) ||
(node.property.type === "Literal" && node.property.value === "__proto__")) {
if (getStaticPropertyName(node) === "__proto__") {
context.report({ node, message: "The '__proto__' property is deprecated." });
}
}
Expand Down
20 changes: 19 additions & 1 deletion tests/lib/rules/no-iterator.js
Expand Up @@ -21,7 +21,9 @@ const ruleTester = new RuleTester();
ruleTester.run("no-iterator", rule, {
valid: [
"var a = test[__iterator__];",
"var __iterator__ = null;"
"var __iterator__ = null;",
{ code: "foo[`__iterator`] = null;", parserOptions: { ecmaVersion: 6 } },
{ code: "foo[`__iterator__\n`] = null;", parserOptions: { ecmaVersion: 6 } }
],
invalid: [
{
Expand All @@ -44,6 +46,22 @@ ruleTester.run("no-iterator", rule, {
messageId: "noIterator",
type: "MemberExpression"
}]
},
{
code: "var a = test[`__iterator__`];",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "noIterator",
type: "MemberExpression"
}]
},
{
code: "test[`__iterator__`] = function () {};",
parserOptions: { ecmaVersion: 6 },
errors: [{
messageId: "noIterator",
type: "MemberExpression"
}]
}
]
});
8 changes: 6 additions & 2 deletions tests/lib/rules/no-proto.js
Expand Up @@ -21,10 +21,14 @@ const ruleTester = new RuleTester();
ruleTester.run("no-proto", rule, {
valid: [
"var a = test[__proto__];",
"var __proto__ = null;"
"var __proto__ = null;",
{ code: "foo[`__proto`] = null;", parserOptions: { ecmaVersion: 6 } },
{ code: "foo[`__proto__\n`] = null;", parserOptions: { ecmaVersion: 6 } }
],
invalid: [
{ code: "var a = test.__proto__;", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] },
{ code: "var a = test['__proto__'];", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] }
{ code: "var a = test['__proto__'];", errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] },
{ code: "var a = test[`__proto__`];", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] },
{ code: "test[`__proto__`] = function () {};", parserOptions: { ecmaVersion: 6 }, errors: [{ message: "The '__proto__' property is deprecated.", type: "MemberExpression" }] }
]
});