Skip to content

Commit

Permalink
Update: check template literal in no-proto, no-iterator (fixes #12801) (
Browse files Browse the repository at this point in the history
#12806)

* Fix: check template literal prop in no-proto (#12801)

* Fix: check template literal prop in no-iterator (#12801)

* add test cases
  • Loading branch information
yeonjuan authored and kaicataldo committed Jan 28, 2020
1 parent 562e784 commit 03a69db
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
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" }] }
]
});

0 comments on commit 03a69db

Please sign in to comment.