Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-no-use-extend-native

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-no-use-extend-native - npm Package Compare versions

Comparing version 0.3.8 to 0.3.9

7

package.json
{
"name": "eslint-plugin-no-use-extend-native",
"version": "0.3.8",
"version": "0.3.9",
"description": "ESLint plugin to prevent use of extended native objects",

@@ -28,2 +28,3 @@ "scripts": {

"is-js-type": "^1.0.0",
"is-obj-prop": "^1.0.0",
"is-proto-prop": "^1.0.0"

@@ -34,11 +35,11 @@ },

"babel-cli": "^6.7.7",
"babel-eslint": "^6.0.0-beta.6",
"babel-preset-es2015": "^6.6.0",
"coveralls": "^2.11.2",
"eslint": "^3.2.2",
"eslint-ava-rule-tester": "^2.0.0",
"eslint-config-dustinspecker": "^0.5.0",
"eslint-path-formatter": "^0.1.1",
"eslint-plugin-new-with-error": "^1.1.0",
"nyc": "^7.1.0"
"nyc": "^8.3.0"
}
}
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

@@ -13,2 +13,6 @@ var _isGetSetProp = require('is-get-set-prop');

var _isObjProp = require('is-obj-prop');
var _isObjProp2 = _interopRequireDefault(_isObjProp);
var _isProtoProp = require('is-proto-prop');

@@ -55,27 +59,45 @@

/**
* Returns the property name and prototype to validate
* @param {Object} node - node to examine
* @return {Object} - methodName and proto
*/
var getMethodNameAndPrototype = function getMethodNameAndPrototype(node) {
var methodName = void 0,
prototype = void 0;
if (node.object.type === 'NewExpression') {
prototype = node.object.callee.name;
} else if (node.object.type === 'Literal') {
prototype = getType(node.object);
} else if (node.object.type === 'BinaryExpression') {
prototype = binaryExpressionProduces(node.object);
} else if (node.object.type === 'Identifier' && node.property.name === 'prototype' && node.parent.property) {
prototype = node.object.name;
methodName = node.parent.property.name;
} else if (node.property.type === 'Identifier' && node.object.type === 'Identifier') {
prototype = node.object.name;
} else {
prototype = node.object.type.replace('Expression', '');
}
methodName = methodName || node.property.name || node.property.value;
return { methodName: methodName, prototype: prototype };
};
module.exports = function (context) {
return {
MemberExpression: function MemberExpression(node) {
/* eslint complexity: [2, 15] */
var methodName = void 0,
proto = void 0;
if (node.object.type === 'NewExpression') {
proto = node.object.callee.name;
} else if (node.object.type === 'Literal') {
proto = getType(node.object);
} else if (node.object.type === 'BinaryExpression') {
proto = binaryExpressionProduces(node.object);
} else if (node.object.type === 'Identifier' && node.property.name === 'prototype' && node.parent.property) {
proto = node.object.name;
methodName = node.parent.property.name;
} else {
proto = node.object.type.replace('Expression', '');
}
methodName = methodName || node.property.name || node.property.value;
/* eslint complexity: [2, 9] */
var isArgToParent = node.parent.arguments && node.parent.arguments.indexOf(node) > -1;
var type = isArgToParent ? node.type : node.parent.type;
if (typeof methodName !== 'string' || typeof proto !== 'string' || !(0, _isJsType2.default)(proto)) {
var _getMethodNameAndProt = getMethodNameAndPrototype(node);
var methodName = _getMethodNameAndProt.methodName;
var prototype = _getMethodNameAndProt.prototype;
if (typeof methodName !== 'string' || typeof prototype !== 'string' || !(0, _isJsType2.default)(prototype)) {
return;

@@ -85,9 +107,9 @@ }

var isExpression = type === 'ExpressionStatement' || type === 'MemberExpression';
var unknownGetterSetterOrProtoExpressed = isExpression && !(0, _isGetSetProp2.default)(proto, methodName) && !(0, _isProtoProp2.default)(proto, methodName);
var unknownGetterSetterOrPrototypeExpressed = isExpression && !(0, _isGetSetProp2.default)(prototype, methodName) && !(0, _isProtoProp2.default)(prototype, methodName) && !(0, _isObjProp2.default)(prototype, methodName);
var isFunctionCall = type === 'CallExpression';
var getterSetterCalledAsFunction = isFunctionCall && (0, _isGetSetProp2.default)(proto, methodName);
var unknownProtoCalledAsFunction = isFunctionCall && !(0, _isProtoProp2.default)(proto, methodName);
var getterSetterCalledAsFunction = isFunctionCall && (0, _isGetSetProp2.default)(prototype, methodName);
var unknownPrototypeCalledAsFunction = isFunctionCall && !(0, _isProtoProp2.default)(prototype, methodName) && !(0, _isObjProp2.default)(prototype, methodName);
if (unknownGetterSetterOrProtoExpressed || getterSetterCalledAsFunction || unknownProtoCalledAsFunction) {
if (unknownGetterSetterOrPrototypeExpressed || getterSetterCalledAsFunction || unknownPrototypeCalledAsFunction) {
context.report(node, 'Avoid using extended native objects');

@@ -94,0 +116,0 @@ }

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc