2020-03-07 11:45:40 +08:00
|
|
|
/**
|
|
|
|
* @fileoverview Rule to flag usage of __proto__ property
|
|
|
|
* @author Ilya Volodin
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
2020-05-15 05:33:08 +08:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Requirements
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const { getStaticPropertyName } = require("./utils/ast-utils");
|
|
|
|
|
2020-03-07 11:45:40 +08:00
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Rule Definition
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
meta: {
|
|
|
|
type: "suggestion",
|
|
|
|
|
|
|
|
docs: {
|
|
|
|
description: "disallow the use of the `__proto__` property",
|
|
|
|
category: "Best Practices",
|
|
|
|
recommended: false,
|
|
|
|
url: "https://eslint.org/docs/rules/no-proto"
|
|
|
|
},
|
|
|
|
|
2020-05-15 05:33:08 +08:00
|
|
|
schema: [],
|
|
|
|
|
|
|
|
messages: {
|
|
|
|
unexpectedProto: "The '__proto__' property is deprecated."
|
|
|
|
}
|
2020-03-07 11:45:40 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
create(context) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
MemberExpression(node) {
|
2020-05-15 05:33:08 +08:00
|
|
|
if (getStaticPropertyName(node) === "__proto__") {
|
|
|
|
context.report({ node, messageId: "unexpectedProto" });
|
2020-03-07 11:45:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|