Socket
Socket
Sign inDemoInstall

eslint-plugin-piggyback

Package Overview
Dependencies
147
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 2.0.0

58

lib/rules/no-jquery-extend.js

@@ -19,33 +19,39 @@ /**

module.exports = function(context) {
var jQueryIdentifiers = context.options;
if (jQueryIdentifiers.length === 0) {
jQueryIdentifiers = [ "$", "jQuery" ];
}
module.exports = {
meta: {
docs: {},
return {
"MemberExpression": function(node) {
if(node.object.type === "Identifier" && isJQuery(node.object) && !isValidJQueryProperty(node.property)) {
context.report(node, "'{{propertyName}}' piggybacks on '{{objectName}}' to extend jQuery", { propertyName: node.property.name, objectName: node.object.name });
schema: {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
},
create: function(context) {
var jQueryIdentifiers = context.options;
if (jQueryIdentifiers.length === 0) {
jQueryIdentifiers = [ "$", "jQuery" ];
}
return {
"MemberExpression": function(node) {
if(node.object.type === "Identifier" && isJQuery(node.object) && !isValidJQueryProperty(node.property)) {
context.report(node, "'{{propertyName}}' piggybacks on '{{objectName}}' to extend jQuery", { propertyName: node.property.name, objectName: node.object.name });
}
}
};
function isJQuery(node) {
return jQueryIdentifiers.some(function(identifier) {
return identifier == node.name;
});
}
};
function isJQuery(node) {
return jQueryIdentifiers.some(function(identifier) {
return identifier == node.name;
});
function isValidJQueryProperty(node) {
return typeof $[node.name] != 'undefined';
}
}
function isValidJQueryProperty(node) {
return typeof $[node.name] != 'undefined';
}
};
module.exports.schema = {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
};

@@ -13,41 +13,47 @@ /**

module.exports = function(context) {
var globalScopeIdentifiers = context.options;
if (globalScopeIdentifiers.length === 0) {
return {};
}
module.exports = {
meta: {
docs: {},
var globalScope;
schema: {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
}
},
return {
"Program": function() {
globalScope = context.getScope();
},
create: function(context) {
var globalScopeIdentifiers = context.options;
if (globalScopeIdentifiers.length === 0) {
return {};
}
"MemberExpression": function(node) {
if(node.object.type === "Identifier" && isGlobalObject(node.object) && !isGlobalProperty(node.property)) {
context.report(node, "'{{propertyName}}' piggybacks on '{{objectName}}' to extend the global scope", { propertyName: node.property.name, objectName: node.object.name });
var globalScope;
return {
"Program": function() {
globalScope = context.getScope();
},
"MemberExpression": function(node) {
if(node.object.type === "Identifier" && isGlobalObject(node.object) && !isGlobalProperty(node.property)) {
context.report(node, "'{{propertyName}}' piggybacks on '{{objectName}}' to extend the global scope", { propertyName: node.property.name, objectName: node.object.name });
}
}
};
function isGlobalObject(node) {
return globalScopeIdentifiers.some(function(identifier) {
return identifier == node.name;
});
}
};
function isGlobalObject(node) {
return globalScopeIdentifiers.some(function(identifier) {
return identifier == node.name;
});
function isGlobalProperty(node) {
return globalScope.variables.some(function(variable) {
return variable.name == node.name;
});
}
}
function isGlobalProperty(node) {
return globalScope.variables.some(function(variable) {
return variable.name == node.name;
});
}
};
module.exports.schema = {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
};
{
"name": "eslint-plugin-piggyback",
"version": "1.0.0",
"version": "2.0.0",
"description": "A set of ESLint rules that help catch undeclared references",

@@ -25,7 +25,7 @@ "keywords": [

"devDependencies": {
"eslint": "~2.0.0",
"eslint": "~2.13.0",
"mocha": "~2.4.5"
},
"peerDependencies": {
"eslint": ">=2.0.0"
"eslint": ">=2.13.0"
},

@@ -32,0 +32,0 @@ "engines": {

@@ -0,1 +1,4 @@

![node](https://img.shields.io/node/v/eslint-plugin-piggyback.svg)
![npm](https://img.shields.io/npm/v/eslint-plugin-piggyback.svg)
# eslint-plugin-piggyback

@@ -27,3 +30,3 @@

With both `no-under` and `no-restricted-global-extend` in-use:
With both `no-undef` and `no-restricted-global-extend` in-use:

@@ -39,4 +42,4 @@ ```javascript

This rule helps catch cases where you're using [jQuery plugins](http://plugins.jquery.com/) (e.g. [`$.cookie`](https://github.com/carhartl/jquery-cookie), [`$.query`](https://github.com/blairmitchelmore/jquery.plugins)).
jQuery plugins are somewhat of an anti-pattern when it comes to properly declaring your module dependencies because they don't export anything, but rather extend the jQuery object itself.
This rule helps catch cases where you're using [jQuery plugins](http://plugins.jquery.com/) (e.g. [`$.cookie`](https://github.com/carhartl/jquery-cookie), [`$.query`](https://github.com/blairmitchelmore/jquery.plugins)).
jQuery plugins are somewhat of an anti-pattern when it comes to properly declaring your module dependencies because they don't export anything, but rather extend the jQuery object itself.
Generally speaking, if you're refactoring old code that uses a jQuery plugin, there's probably a modern library available that provides the same functionality without relying on or extending jQuery.

@@ -51,3 +54,3 @@

$.when( ... ); //This is fine.
$.cookie( ... ); //This will now trigger an ESLint warning
$.cookie( ... ); //This will now trigger an ESLint error
```

@@ -114,5 +117,6 @@

**1.0.0** - Add the `no-jquery-extend` rule. This is a breaking change because as of this version Node.js >= 4 or newer is required.
**2.0.0** - Switch to ESLint's [new rule format](http://eslint.org/blog/2016/07/eslint-new-rule-format). This is a breaking change because as of this ESLint version >= 2.13.0 is required.
**1.0.0** - Add the `no-jquery-extend` rule. This is a breaking change because as of this Node.js version >= 4 is required.
## Running tests
Run mocha tests with `npm test`

@@ -19,5 +19,3 @@ "use strict";

{ code: "/*global window, foo*/ (function() { window.foo(); })();", options: ["window"] },
{ code: "/*eslint-env browser*/ (function() { window.location.reload(); })();", options: ["window"] },
{ code: "", options: ["window"] },
{ code: "/*eslint-env browser*/ define([\r\n\'jquery\',\r\n\'fusion\/customization\/customized-code-provider\',\r\n\'fusion\/plugins\/query\'\r\n], function ($, getCustomizedCode, query) {\r\n\t\tfunction buildUrl(settings) {\r\n\t\t\tvar returnUrl = settings.returnUrl;\r\n\t\t\tif (typeof (returnUrl) == \'undefined\' || returnUrl == \'\')\r\n\t\t\t\treturnUrl = window.location.pathname + createParams(window.location.search, settings.extraParameter);\r\n\r\n\t\t\tfunction createAppSettings() {\r\n\t\t\t\tif (typeof (settings.registrationSettings) == \'undefined\' && typeof (settings.activationSettings) == \'undefined\' && typeof (settings.signInSettings) == \'undefined\')\r\n\t\t\t\t\treturn \'\';\r\n\r\n\t\t\t\treturn encodeURIComponent(JSON.stringify({\r\n\t\t\t\t\tregistration: settings.registrationSettings,\r\n\t\t\t\t\tactivation: settings.activationSettings,\r\n\t\t\t\t\tsignIn: settings.signInSettings\r\n\t\t\t\t}));\r\n\t\t\t}\r\n\r\n\t\t\tfunction createParams(currentParams, p) {\r\n\t\t\t\tif (!p) {\r\n\t\t\t\t\treturn currentParams;\r\n\t\t\t\t}\r\n\r\n\t\t\t\treturn addParam(currentParams, encodeURIComponent(p));\r\n\t\t\t}\r\n\r\n\t\t\tfunction addParam(currentParams, p) {\r\n\t\t\t\tif (!currentParams) {\r\n\t\t\t\t\treturn \'?p=\' + p;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (paramExists(currentParams))\r\n\t\t\t\t\treturn replaceParam(currentParams, p);\r\n\r\n\t\t\t\treturn currentParams + \'&p=\' + p;\r\n\t\t\t}\r\n\r\n\t\t\tfunction paramExists(currentParams) {\r\n\t\t\t\treturn \/[?&]p=\/.test(currentParams);\r\n\t\t\t}\r\n\r\n\t\t\tfunction replaceParam(currentParams, p) {\r\n\t\t\t\treturn currentParams.replace(\/(p=)[^\\&]+\/, \'p=\' + p);\r\n\t\t\t}\r\n\r\n\t\t\tvar customizations = getCustomizedCode();\r\n\t\t\tvar customizationCode = settings.appCustomizationCode ? settings.appCustomizationCode : (settings.customizedCode ? settings.customizedCode : customizations.code);\r\n\t\t\tvar customizedAppSettings = createAppSettings();\r\n\t\t\tvar memberNumber = query.get(\'syw\');\r\n\t\t\tvar resetPasswordToken = query.get(\'resetPasswordToken\');\r\n\t\t\tvar email = query.get(\'email\');\r\n\t\t\tvar url = settings.iframeUrl +\r\n\t\t\t\'?returnUrl=\' + encodeURIComponent(returnUrl) +\r\n\t\t\t\'&customCode=\' + customizationCode +\r\n\t\t\t\'&hae=\' + customizations.hae +\r\n\t\t\t\'&mnumber=\' + memberNumber +\r\n\t\t\t\'&customizedAppSettings=\' + customizedAppSettings +\r\n\t\t\t\'&resetPasswordToken=\' + resetPasswordToken +\r\n\t\t\t\'&email=\' + email +\r\n\t\t\t\'&emailValue=\' + (settings.values ? settings.values.email : \"\") +\r\n\t\t\t\'&hideOpenId=\' + (settings.hideOpenId ? true : false) +\r\n\t\t\t\'&ignoreIfSignedIn=\' + (settings.forceLogin ? true : false);\r\n\r\n\t\t\treturn url;\r\n\t\t}\r\n\r\n\t\treturn buildUrl;\r\n\t}, \'SYW.Authentication.buildUrl\');", options: ["window"] }
{ code: "/*eslint-env browser*/ (function() { window.location.reload(); })();", options: ["window"] }
],

@@ -24,0 +22,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc