feat(eslint-plugin): Add no-polymorphic-call rule
ADD
packages/eslint-plugin/lib/rules/no-polymorphic-call.js
+"use strict"
+
+module.exports = {
+ meta: {
+ docs: {
+ description:
+ "disallow polymorphic function calls e.g.: 'array.slice()'",
+ category: "Possible Security Errors",
+ recommended: true,
+ url:
+ "https://github.com/endojs/endo/blob/master/packages/eslint-plugin/lib/rules/no-polymorphic-call.js",
+ },
+ type: "problem",
+ fixable: null,
+ schema: [],
+ supported: true,
+ },
+ create (context) {
+ return {
+ CallExpression(node) {
+ if (node.callee.type !== 'MemberExpression') {
+ return
+ }
+ const reportHint = prepareMemberExpressionHint(node.callee)
+ context.report(node, `Polymorphic call: "${reportHint}". May be vulnerable to corruption or trap`)
+ }
+ }
+ },
+}
+
+function prepareMemberExpressionHint (node) {
+ const { object, property, computed } = node
+ let objectHint
+ let propertyHint
+ if (object.type === 'Identifier') {
+ objectHint = object.name
+ } else if (object.type === 'MemberExpression') {
+ objectHint = prepareMemberExpressionHint(object)
+ } else {
+ objectHint = `[[${object.type}]]`
+ }
+ if (property.type === 'Identifier') {
+ if (computed) {
+ propertyHint = `[${property.name}]`
+ } else {
+ propertyHint = property.name
+ }
+ } else {
+ propertyHint = `[[${property.type}]]`
+ }
+ return `${objectHint}.${propertyHint}`
+}
\ No newline at end of file

MODIFY
packages/ses/package.json
packages/ses/package.json
"parseFloat",
"parseInt",
"unescape"
- ]
+ ],
+ "@endo/no-polymorphic-call": "warn"
},
"overrides": [
{
"files": [
"test/**/*.js",
- "demos/**/*.js"
+ "demos/**/*.js",
+ "scripts/**/*.js"
],
"rules": {
- "no-restricted-globals": "off"
+ "no-restricted-globals": "off",
+ "@endo/no-polymorphic-call": "off"
}
}
]

feat(eslint-plugin): Add no-polymorphic-call rule