Socket
Socket
Sign inDemoInstall

eslint-plugin-angular

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-angular - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

demo/npm/app/.eslintrc

2

package.json
{
"name": "eslint-plugin-angular",
"version": "0.0.8",
"version": "0.0.9",
"description": "ESLint rules for AngularJS projects",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -47,40 +47,44 @@ [![Build Status](https://travis-ci.org/Gillespie59/eslint-plugin-angular.svg?branch=master)](https://travis-ci.org/Gillespie59/eslint-plugin-angular)

| Name | Description | Default Configuration |
| ------------- | ------------- | ------------- |
| ng_angularelement | The angular.element method should be used instead of the $ or jQuery object (if you are using jQuery of course). If the jQuery library is imported, angular.element will be a wrapper around the jQuery object. | 'ng_angularelement': 1 |
| ng_controller_as | You should not set properties on $scope in controllers. Use controllerAs syntax and add data to 'this'. Implements 'this' check part of [Y031](https://github.com/johnpapa/angular-styleguide#style-y031). The second parameter can be a Regexp for identifying controller functions (when using something like Browserify) | 'ng_controller_as': 2 |
| ng_controller_as_route | You should use Angular's controllerAs syntax when defining routes or states. Implements route part [Y031](https://github.com/johnpapa/angular-styleguide#style-y031) | 'ng_controller_as_route': 2 |
| ng_controller_as_vm | You should use a capture variable for 'this' when using the controllerAs syntax. [Y031](https://github.com/johnpapa/angular-styleguide#style-y032). The second parameter specifies the capture variable you want to use in your application. The third parameter can be a Regexp for identifying controller functions (when using something like Browserify) | 'ng_controller_as_vm': [2, 'vm'] |
| ng_controller_name | All your controllers should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. ("ng_controller_name": [2, "ng"]) [Y123](https://github.com/johnpapa/angular-styleguide#style-y123), [Y124](https://github.com/johnpapa/angular-styleguide#style-y124)| 'ng_controller_name': [2, /[A-Z].*Controller$/] |
| ng_definedundefined | You should use the angular.isUndefined or angular.isDefined methods instead of using the keyword undefined. We also check the use of !angular.isUndefined and !angular.isDefined (should prefer the reverse function)| 'ng_definedundefined': 2 |
| ng_di | All your DI should use the same syntax : the Array or function syntaxes ("ng_di": [2, "function or array"])| 'ng_di': [2, 'function'] |
| ng_directive_name | All your directives should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your directives by "ng" (reserved keyword for AngularJS directives) ("ng_directive_name": [2, "ng"]) [Y073](https://github.com/johnpapa/angular-styleguide#style-y073), [Y126](https://github.com/johnpapa/angular-styleguide#style-y126) | 'ng_directive_name': 0 |
| ng_document_service | Instead of the default document object, you should prefer the AngularJS wrapper service $document. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) | 'ng_document_service': 2 |
| ng_empty_controller | If you have one empty controller, maybe you have linked it in your Router configuration or in one of your views. You can remove this declaration because this controller is useless | 'ng_empty_controller': 0 |
| ng_foreach | You should use the angular.forEach method instead of the default JavaScript implementation [].forEach. | 'ng_foreach': 0 |
| ng_filter_name | All your filters should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. ("ng_filter_name": [2, "ng"]) | 'ng_filter_name': 0 |
| ng_function_type | Anonymous or named functions inside AngularJS components. The first parameter sets which type of function is required and can be 'named' or 'anonymous'. The second parameter is an optional list of angular object names. [Y024](https://github.com/johnpapa/angular-styleguide/blob/master/README.md#style-y024) | 'ng_function_type': 0 |
| ng_interval_service | Instead of the default setInterval function, you should use the AngularJS wrapper service $interval [Y181](https://github.com/johnpapa/angular-styleguide#style-y181) | 'ng_interval_service': 2 |
| ng_json_functions | You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify | 'ng_json_functions': 2 |
|ng_module_getter | When using a module, avoid using a variable and instead use chaining with the getter syntax [Y022](https://github.com/johnpapa/angular-styleguide#style-y022)| 'ng_module_getter':2 |
| ng_module_name | When you create a new module, its name should start with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your modules by "ng" (reserved keyword for AngularJS modules) ("ng_module_name": [2, "ng"]) [Y127](https://github.com/johnpapa/angular-styleguide#style-y127)| 'ng_module_name': 0 |
|ng_module_setter | Declare modules without a variable using the setter syntax.[Y021](https://github.com/johnpapa/angular-styleguide#style-y021) | 'ng_module_setter':2 |
| ng_no_digest | The scope's $digest() method shouldn't be used. You should prefer the $apply method. | 'ng_no_digest': 2 |
| ng_no_jquery_angularelement | You should not wrap angular.element object into jQuery(), because angular.element already return jQLite element| 'ng_no_jquery_angularelement': 2 |
| ng_no_private_call | All scope's properties/methods starting with $$ are used interally by AngularJS. You should not use them directly. | 'ng_no_private_call': 2 |
| ng_no_services | Some services should be used only in a specific AngularJS service (Ajax-based service for example), in order to follow the separation of concerns paradigm. The second parameter specifies the services. The third parameter can be a list of angular objects (controller, factory, etc.). Or second parameter can be an object, where keys are angular object names and value is a list of services (like {controller: ['$http'], factory: ['$q']}) | 'ng_no_services': [2, ['$http', '$resource', 'Restangular']] |
| ng_no_service_method | You should prefer the factory() method instead of service() [Y181](https://github.com/johnpapa/angular-styleguide#style-y181)| 'ng_no_service_method': 2 |
| ng_on_watch | Watch and On methods on the scope object should be assigned to a variable, in order to be deleted in a $destroy event handler [Y035](https://github.com/johnpapa/angular-styleguide#style-y035) | 'ng_on_watch': 2 |
| ng_service_name | All your services should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your services by "$" (reserved keyword for AngularJS services) ("ng_service_name": [2, "ng"]) [Y125](https://github.com/johnpapa/angular-styleguide#style-y125) | 'ng_on_watch': 2 |
| ng_timeout_service | Instead of the default setTimeout function, you should use the AngularJS wrapper service $timeout [Y181](https://github.com/johnpapa/angular-styleguide#style-y181) | 'ng_timeout_service': 2 |
| ng_typecheck_array | You should use the angular.isArray method instead of the default JavaScript implementation (typeof [] === "[object Array]"). | 'ng_typecheck_array': 2 |
| ng_typecheck_boolean | You should use the angular.isBoolean method instead of the default JavaScript implementation (typeof true === "[object Boolean]"). | 'ng_typecheck_boolean': 2 |
| ng_typecheck_date | You should use the angular.isDate method instead of the default JavaScript implementation (typeof new Date() === "[object Date]"). | 'ng_typecheck_date': 2 |
| ng_typecheck_function | You should use the angular.isFunction method instead of the default JavaScript implementation (typeof function(){} ==="[object Function]"). | 'ng_typecheck_function': 2 |
| ng_typecheck_number | You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]"). | 'ng_typecheck_number': 2 |
| ng_typecheck_object | You should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]"). | 'ng_typecheck_object': 2 |
| ng_typecheck_regexp | You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]"). | 'ng_typecheck_regexp': 2 |
| ng_typecheck_string | You should use the angular.isString method instead of the default JavaScript implementation (typeof "" === "[object String]"). | 'ng_typecheck_string': 2 |
| ng_window_service | Instead of the default window object, you should prefer the AngularJS wrapper service $window. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) | 'ng_window_service': 2 |
| Name and Default | Description |
| ------------- | ------------- |
| 'ng_angularelement': 1 | The angular.element method should be used instead of the $ or jQuery object (if you are using jQuery of course). If the jQuery library is imported, angular.element will be a wrapper around the jQuery object. |
| 'ng_controller_as': 2 | You should not set properties on $scope in controllers. Use controllerAs syntax and add data to 'this'. Implements 'this' check part of [Y031](https://github.com/johnpapa/angular-styleguide#style-y031). The second parameter can be a Regexp for identifying controller functions (when using something like Browserify) |
| 'ng_controller_as_route': 2 | You should use Angular's controllerAs syntax when defining routes or states. Implements route part [Y031](https://github.com/johnpapa/angular-styleguide#style-y031) |
| 'ng_controller_as_vm': [2, 'vm'] | You should use a capture variable for 'this' when using the controllerAs syntax. [Y031](https://github.com/johnpapa/angular-styleguide#style-y032). The second parameter specifies the capture variable you want to use in your application. The third parameter can be a Regexp for identifying controller functions (when using something like Browserify) |
| 'ng_controller_name': [2, /[A-Z].*Controller$/] | All your controllers should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. ("ng_controller_name": [2, "ng"]) [Y123](https://github.com/johnpapa/angular-styleguide#style-y123), [Y124](https://github.com/johnpapa/angular-styleguide#style-y124)|
| 'ng_definedundefined': 2 | You should use the angular.isUndefined or angular.isDefined methods instead of using the keyword undefined. We also check the use of !angular.isUndefined and !angular.isDefined (should prefer the reverse function)|
| 'ng_di': [2, 'function'] | All your DI should use the same syntax : the Array or function syntaxes ("ng_di": [2, "function or array"])|
| 'ng_directive_name': 0 | All your directives should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your directives by "ng" (reserved keyword for AngularJS directives) ("ng_directive_name": [2, "ng"]) [Y073](https://github.com/johnpapa/angular-styleguide#style-y073), [Y126](https://github.com/johnpapa/angular-styleguide#style-y126) |
| 'ng_document_service': 2 | Instead of the default document object, you should prefer the AngularJS wrapper service $document. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) |
| 'ng_empty_controller': 0 | If you have one empty controller, maybe you have linked it in your Router configuration or in one of your views. You can remove this declaration because this controller is useless |
| 'ng_foreach': 0 | You should use the angular.forEach method instead of the default JavaScript implementation [].forEach. |
| 'ng_filter_name': 0 | All your filters should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. ("ng_filter_name": [2, "ng"]) |
| 'ng_function_type': 0 | Anonymous or named functions inside AngularJS components. The first parameter sets which type of function is required and can be 'named' or 'anonymous'. The second parameter is an optional list of angular object names. [Y024](https://github.com/johnpapa/angular-styleguide/blob/master/README.md#style-y024) |
| 'ng_interval_service': 2 | Instead of the default setInterval function, you should use the AngularJS wrapper service $interval [Y181](https://github.com/johnpapa/angular-styleguide#style-y181) |
| 'ng_json_functions': 2 | You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify |
| 'ng_module_getter':2 | When using a module, avoid using a variable and instead use chaining with the getter syntax [Y022](https://github.com/johnpapa/angular-styleguide#style-y022)|
| 'ng_module_name': 0 | When you create a new module, its name should start with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your modules by "ng" (reserved keyword for AngularJS modules) ("ng_module_name": [2, "ng"]) [Y127](https://github.com/johnpapa/angular-styleguide#style-y127)|
| 'ng_module_setter':2 | Declare modules without a variable using the setter syntax.[Y021](https://github.com/johnpapa/angular-styleguide#style-y021) |
| 'ng_no_digest': 2 | The scope's $digest() method shouldn't be used. You should prefer the $apply method. |
| 'ng_no_jquery_angularelement': 2 | You should not wrap angular.element object into jQuery(), because angular.element already return jQLite element|
| 'ng_no_private_call': 2 | All scope's properties/methods starting with $$ are used internally by AngularJS. You should not use them directly. |
| 'ng_no_services': [2, ['$http', '$resource', 'Restangular']] | Some services should be used only in a specific AngularJS service (Ajax-based service for example), in order to follow the separation of concerns paradigm. The second parameter specifies the services. The third parameter can be a list of angular objects (controller, factory, etc.). Or second parameter can be an object, where keys are angular object names and value is a list of services (like {controller: ['$http'], factory: ['$q']}) |
| 'ng_no_service_method': 2 | You should prefer the factory() method instead of service() [Y181](https://github.com/johnpapa/angular-styleguide#style-y181)|
| 'ng_on_watch': 2 | Watch and On methods on the scope object should be assigned to a variable, in order to be deleted in a $destroy event handler [Y035](https://github.com/johnpapa/angular-styleguide#style-y035) |
| 'ng_service_name': 2 | All your services should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your services by "$" (reserved keyword for AngularJS services) ("ng_service_name": [2, "ng"]) [Y125](https://github.com/johnpapa/angular-styleguide#style-y125) |
| 'ng_timeout_service': 2 | Instead of the default setTimeout function, you should use the AngularJS wrapper service $timeout [Y181](https://github.com/johnpapa/angular-styleguide#style-y181) |
| 'ng_typecheck_array': 2 | You should use the angular.isArray method instead of the default JavaScript implementation (typeof [] === "[object Array]"). |
| 'ng_typecheck_boolean': 2 | You should use the angular.isBoolean method instead of the default JavaScript implementation (typeof true === "[object Boolean]"). |
| 'ng_typecheck_date': 2 | You should use the angular.isDate method instead of the default JavaScript implementation (typeof new Date() === "[object Date]"). |
| 'ng_typecheck_function': 2 | You should use the angular.isFunction method instead of the default JavaScript implementation (typeof function(){} ==="[object Function]"). |
| 'ng_typecheck_number': 2 | You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]"). |
| 'ng_typecheck_object': 2 | You should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]"). |
| 'ng_typecheck_regexp': 2 | You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]"). |
| 'ng_typecheck_string': 2 | You should use the angular.isString method instead of the default JavaScript implementation (typeof "" === "[object String]"). |
| 'ng_window_service': 2 | Instead of the default window object, you should prefer the AngularJS wrapper service $window. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) |
<<<<<<< HEAD
=======
>>>>>>> 0.0.9
# Need your help

@@ -87,0 +91,0 @@ It is an opensource project. Any help will be very useful. You can :

@@ -11,8 +11,17 @@ module.exports = function(context) {

var calleeObject;
if ((utils.isAngularControllerDeclaration(node.expression) ||
utils.isAngularFilterDeclaration(node.expression) ||
utils.isAngularServiceDeclaration(node.expression) ||
utils.isAngularDirectiveDeclaration(node.expression) ||
utils.isAngularRunSection(node.expression) ||
utils.isAngularConfigSection(node.expression))
if (utils.isAngularComponent(node.expression) || utils.isAngularRunSection(node.expression) || utils.isAngularConfigSection(node.expression)) {
&& !utils.isAngularModuleDeclaration(node.expression)) {
calleeObject = node.expression.callee.object;
if (!(calleeObject.type === 'CallExpression' && utils.isAngularModuleGetter(calleeObject))) {
var calleeObject = node.expression.callee.object;
while(calleeObject !== undefined && calleeObject.type === 'CallExpression' && !utils.isAngularModuleGetter(calleeObject)){
calleeObject = calleeObject.callee.object;
}
if (!(calleeObject !== undefined && calleeObject.type === 'CallExpression' && utils.isAngularModuleGetter(calleeObject))) {
context.report(node, 'Avoid using a variable and instead use chaining with the getter syntax.');

@@ -19,0 +28,0 @@ }

@@ -53,10 +53,9 @@ module.exports = function(context) {

var callee = node.callee,
angularObjectName = callee.property.name;
var callee = node.callee;
if (utils.isAngularComponent(node) && callee.type === 'MemberExpression' && angularObjectList.indexOf(angularObjectName) >= 0) {
if (utils.isAngularComponent(node) && callee.type === 'MemberExpression' && angularObjectList.indexOf(callee.property.name) >= 0) {
if(utils.isFunctionType(node.arguments[1])){
node.arguments[1].params.forEach(function(service){
if(service.type === 'Identifier' && isSetBedService(service.name, angularObjectName)){
context.report(node, message + ' (' + service.name + ' in ' + angularObjectName + ')', {});
if(service.type === 'Identifier' && isSetBedService(service.name, callee.property.name)){
context.report(node, message + ' (' + service.name + ' in ' + callee.property.name + ')', {});
}

@@ -68,4 +67,4 @@ });

node.arguments[1].elements.forEach(function(service){
if(service.type === 'Literal' && isSetBedService(service.value, angularObjectName)){
context.report(node, message + ' (' + service.value + ' in ' + angularObjectName + ')', {});
if(service.type === 'Literal' && isSetBedService(service.value, callee.property.name)){
context.report(node, message + ' (' + service.value + ' in ' + callee.property.name + ')', {});
}

@@ -72,0 +71,0 @@ });

@@ -12,18 +12,68 @@ module.exports = function(context) {

/**
* Return true if the given node is a call expression calling a function
* named '$on' or '$watch' on an object named '$scope', '$rootScope' or
* 'scope'.
*/
function isScopeOnOrWatch(node) {
if (node.type !== 'CallExpression') {
return false;
}
var calledFunction = node.callee;
if(calledFunction.type !== 'MemberExpression') {
return false;
}
// can only easily tell what name was used if a simple
// identifiers were used to access it.
var parentObject = calledFunction.object;
var accessedFunction = calledFunction.property;
// cannot check name of the parent object if it is returned from a
// complex expression.
if (parentObject.type !== 'Identifier' ||
accessedFunction.type !== 'Identifier') {
return false;
}
var objectName = parentObject.name;
var functionName = accessedFunction.name;
return (objectName === '$rootScope' ||
objectName === '$scope' ||
objectName === 'scope') && (functionName === '$on' ||
functionName === '$watch');
}
/**
* Return true if the given node is a call expression that has a first
* argument of the string '$destroy'.
*/
function isFirstArgDestroy(node) {
if (node.type !== 'CallExpression') {
return false;
}
var args = node.arguments;
return (args.length >= 1 &&
args[0].type === 'Literal' &&
args[0].value === '$destroy');
}
return {
'CallExpression': function(node) {
if(node.callee.type === 'MemberExpression' &&
(node.callee.object.name === '$scope' || node.callee.object.name === '$rootScope' || node.callee.object.name === 'scope')){
if (isScopeOnOrWatch(node) && !isFirstArgDestroy(node)) {
if (node.parent.type !== 'VariableDeclarator' &&
node.parent.type !== 'AssignmentExpression' &&
!(isScopeOnOrWatch(node.parent) &&
isFirstArgDestroy(node.parent))) {
report(node, node.callee.property.name);
}
if(node.callee.property.name === '$on' || node.callee.property.name === '$watch'){
if(node.parent.type !== 'VariableDeclarator' && node.parent.type !== 'AssignmentExpression'){
report(node, node.callee.property.name);
}
}
}
}
}
};
};

@@ -22,6 +22,6 @@ module.exports = function(context) {

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -28,0 +28,0 @@ }

@@ -18,6 +18,6 @@ module.exports = function(context) {

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -24,0 +24,0 @@ }

@@ -18,6 +18,6 @@ module.exports = function(context) {

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -24,0 +24,0 @@ }

@@ -8,3 +8,3 @@ module.exports = function(context) {

function recordError(node, origin){
if(node.type === 'Literal' && node.value === 'function') {
if(node.type === 'Literal' && (node.value === 'function' || node.value === '[object Function]')) {
context.report(origin, 'You should use the angular.isFunction method', {});

@@ -19,6 +19,6 @@ }

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -25,0 +25,0 @@ }

@@ -18,6 +18,6 @@ module.exports = function(context) {

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -24,0 +24,0 @@ }

@@ -8,3 +8,3 @@ module.exports = function(context) {

function recordError(node, origin){
if(node.type === 'Literal' && node.value === 'object') {
if(node.type === 'Literal' && (node.value === 'object' || node.value === '[object Object]')) {
context.report(origin, 'You should use the angular.isObject method', {});

@@ -18,5 +18,5 @@ }

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
} else if(utils.isTypeOfStatement(node.right)){
} else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -23,0 +23,0 @@ }

@@ -5,2 +5,4 @@ module.exports = function(context) {

var utils = require('./utils/utils');
function recordError(node, origin){

@@ -14,6 +16,3 @@ if(node.type === 'Literal' && node.value === '[object RegExp]') {

return node.type === 'Identifier'
|| (node.type === 'CallExpression'
&& node.callee.type === 'MemberExpression'
&& node.callee.object.name === 'toString'
&& node.callee.property.name === 'call');
|| utils.isToStringStatement(node);
}

@@ -20,0 +19,0 @@

@@ -18,6 +18,6 @@ module.exports = function(context) {

if(node.operator === '===' || node.operator === '!=='){
if(utils.isTypeOfStatement(node.left)){
if(utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)){
recordError(node.right, node);
}
else if(utils.isTypeOfStatement(node.right)){
else if(utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)){
recordError(node.left, node);

@@ -24,0 +24,0 @@ }

@@ -14,4 +14,5 @@ (function(){

}
module.exports = {
module.exports = {
convertPrefixToRegex: function(prefix){

@@ -40,2 +41,6 @@ if(typeof prefix !== 'string'){

isToStringStatement: function(node){
return node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && node.callee.object.type === 'MemberExpression' && node.callee.object.property.name === 'toString' && node.callee.property.name === 'call' && node.callee.object.object.type === 'MemberExpression' && node.callee.object.object.object.name === 'Object' && node.callee.object.object.property.name === 'prototype';
},
isArrayType: function(node){

@@ -53,2 +58,6 @@ return node !== undefined && node.type === 'ArrayExpression';

isMemberExpression: function(node){
return node !== undefined && node.type === 'MemberExpression';
},
isLiteralType: function(node){

@@ -71,36 +80,36 @@ return node !== undefined && node.type === 'Literal';

isAngularComponent: function(node){
return node.arguments.length === 2 && this.isLiteralType(node.arguments[0]) && (this.isIdentifierType(node.arguments[1]) || this.isFunctionType(node.arguments[1]) || this.isArrayType(node.arguments[1]));
return node.arguments !== undefined && node.arguments.length === 2 && this.isLiteralType(node.arguments[0]) && (this.isIdentifierType(node.arguments[1]) || this.isFunctionType(node.arguments[1]) || this.isArrayType(node.arguments[1]));
},
isAngularControllerDeclaration: function(node){
return this.isAngularComponent(node) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'controller'
return this.isAngularComponent(node) && this.isMemberExpression(node.callee) && node.callee.property.name === 'controller'
},
isAngularFilterDeclaration: function(node){
return this.isAngularComponent(node) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'filter'
return this.isAngularComponent(node) && this.isMemberExpression(node.callee) && node.callee.property.name === 'filter'
},
isAngularDirectiveDeclaration: function(node){
return this.isAngularComponent(node) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'directive'
return this.isAngularComponent(node) && this.isMemberExpression(node.callee) && node.callee.property.name === 'directive'
},
isAngularServiceDeclaration: function(node){
return this.isAngularComponent(node) && node.callee.type === 'MemberExpression'
&& (node.callee.property.name === 'provider' || node.callee.property.name === 'service' || node.callee.property.name === 'factory' || node.callee.property.name === 'constant' || node.callee.property.name === 'value')
return this.isAngularComponent(node) && this.isMemberExpression(node.callee)
&& node.callee.object.name !== '$provide' && (node.callee.property.name === 'provider' || node.callee.property.name === 'service' || node.callee.property.name === 'factory' || node.callee.property.name === 'constant' || node.callee.property.name === 'value')
},
isAngularModuleDeclaration: function(node){
return this.isAngularComponent(node) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'module'
return this.isAngularComponent(node) && node.callee !== undefined && node.callee.type === 'MemberExpression' && node.callee.property.name === 'module'
},
isAngularModuleGetter: function(node){
return node.arguments.length > 0 && this.isLiteralType(node.arguments[0]) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'module';
return node.arguments !== undefined && node.arguments.length > 0 && this.isLiteralType(node.arguments[0]) && node.callee.type === 'MemberExpression' && node.callee.property.name === 'module';
},
isAngularRunSection: function(node){
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'run';
return this.isMemberExpression(node.callee) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'run';
},
isAngularConfigSection: function(node){
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'config';
return this.isMemberExpression(node.callee) && node.callee.property.type === 'Identifier' && node.callee.property.name === 'config';
},

@@ -107,0 +116,0 @@

@@ -30,3 +30,9 @@ //------------------------------------------------------------------------------

'angular.module("module").config(["$scope", function($scope) {}]);',
'angular.module("module").run(["$scope", function($scope) {}]);'
'angular.module("module").run(["$scope", function($scope) {}]);',
'"use strict";angular.module("module").run(["$scope", function($scope) {}]);',
'angular.module("argo", ["ngMaterial", "ui.router", "ngSocket", "LocalStorageModule"]);',
'angular.module("mwl.calendar").controller("MwlElementDimensionsCtrl", function($element, $scope, $parse, $attrs) {}).directive("mwlElementDimensions", function() {});',
'describe("suite test", function(){})',
'it("test", function(){})',
'$provide.value("accountsService", accountsService)'
],

@@ -33,0 +39,0 @@ invalid: [{

@@ -24,2 +24,5 @@ //------------------------------------------------------------------------------

args: [1, defaultBadService]
}, {
code: '"use strict";app.' + object + '("name", ["Service1", function(Service1){}]);',
args: [1, defaultBadService]
});

@@ -26,0 +29,0 @@

@@ -20,3 +20,9 @@ //------------------------------------------------------------------------------

'var variable = $rootScope.$on()',
'var variable = $rootScope.$watch()'
'var variable = $rootScope.$watch()',
'$scope.$on("$destroy")',
'$rootScope.$on("$destroy")',
'$scope.$on("$destroy", $scope.$on())',
'$rootScope.$on("$destroy", $scope.$on())',
'$scope.$on("$destroy", $rootScope.$on())',
'$rootScope.$on("$destroy", $rootScope.$on())'
],

@@ -23,0 +29,0 @@ invalid: [

@@ -18,7 +18,7 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'typeof [] === "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: '"[object Array]" === typeof []', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: 'Object.prototype.toString.call([]) === "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: '"[object Array]" === Object.prototype.toString.call([])', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: 'variable === "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: '"[object Array]" === variable', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: 'typeof [] !== "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: 'Object.prototype.toString.call([]) !== "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: '"[object Array]" !== typeof []', errors: [{ message: 'You should use the angular.isArray method'}] },

@@ -25,0 +25,0 @@ { code: 'variable !== "[object Array]"', errors: [{ message: 'You should use the angular.isArray method'}] },

@@ -18,11 +18,20 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'typeof variable === "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" === typeof variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'variable === "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" === variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'typeof variable !== "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" !== typeof variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'variable !== "[object Boolean]"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"[object Boolean]" !== variable', errors: [{ message: 'You should use the angular.isBoolean method'}] }
{ code: '"[object Boolean]" !== variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'typeof variable === "boolean"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"boolean" === typeof variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'variable === "boolean"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"boolean" === variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'typeof variable !== "boolean"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"boolean" !== typeof variable', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: 'typeof variable !== "boolean"', errors: [{ message: 'You should use the angular.isBoolean method'}] },
{ code: '"boolean" !== typeof variable', errors: [{ message: 'You should use the angular.isBoolean method'}] }
]
});

@@ -18,8 +18,8 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'typeof variable === "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: '"[object Date]" === typeof variable', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: '"[object Date]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: 'variable === "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: '"[object Date]" === variable', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: 'typeof variable !== "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: '"[object Date]" !== typeof variable', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: '"[object Date]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isDate method'}] },
{ code: 'variable !== "[object Date]"', errors: [{ message: 'You should use the angular.isDate method'}] },

@@ -26,0 +26,0 @@ { code: '"[object Date]" !== variable', errors: [{ message: 'You should use the angular.isDate method'}] }

@@ -25,4 +25,13 @@ //------------------------------------------------------------------------------

{ code: 'variable !== "function"', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: '"function" !== variable', errors: [{ message: 'You should use the angular.isFunction method'}] }
{ code: '"function" !== variable', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object Function]"', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: '"[object Function]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: 'variable === "[object Function]"', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: '"[object Function]" === variable', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object Function]"', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: '"[object Function]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: 'variable !== "[object Function]"', errors: [{ message: 'You should use the angular.isFunction method'}] },
{ code: '"[object Function]" !== variable', errors: [{ message: 'You should use the angular.isFunction method'}] }
]
});

@@ -18,11 +18,20 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'typeof variable === "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" === typeof variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'variable === "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" === variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'typeof variable !== "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'variable !== "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" !== variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'typeof variable === "number"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"number" === typeof variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'variable === "number"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"number" === variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'typeof variable !== "number"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" !== typeof variable', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: 'variable !== "[object Number]"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"[object Number]" !== variable', errors: [{ message: 'You should use the angular.isNumber method'}] }
{ code: 'variable !== "number"', errors: [{ message: 'You should use the angular.isNumber method'}] },
{ code: '"number" !== variable', errors: [{ message: 'You should use the angular.isNumber method'}] }
]
});

@@ -25,4 +25,13 @@ //------------------------------------------------------------------------------

{ code: 'variable !== "object"', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: '"object" !== variable', errors: [{ message: 'You should use the angular.isObject method'}] }
{ code: '"object" !== variable', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object Object]"', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: '"[object Object]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: 'variable === "[object Object]"', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: '"[object Object]" === variable', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object Object]"', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: '"[object Object]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: 'variable !== "[object Object]"', errors: [{ message: 'You should use the angular.isObject method'}] },
{ code: '"[object Object]" !== variable', errors: [{ message: 'You should use the angular.isObject method'}] }
]
});

@@ -18,8 +18,8 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'toString.call(value) === "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: '"[object RegExp]" === toString.call(value)', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: 'Object.prototype.toString.call(value) === "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: '"[object RegExp]" === Object.prototype.toString.call(value)', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: 'variable === "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: '"[object RegExp]" === variable', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: 'toString.call(value) !== "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: '"[object RegExp]" !== toString.call(value)', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: 'Object.prototype.toString.call(value) !== "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: '"[object RegExp]" !== Object.prototype.toString.call(value)', errors: [{ message: 'You should use the angular.isRegexp method'}] },
{ code: 'variable !== "[object RegExp]"', errors: [{ message: 'You should use the angular.isRegexp method'}] },

@@ -26,0 +26,0 @@ { code: '"[object RegExp]" !== variable', errors: [{ message: 'You should use the angular.isRegexp method'}] }

@@ -18,11 +18,20 @@ //------------------------------------------------------------------------------

invalid: [
{ code: 'typeof variable === "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" === typeof variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'Object.prototype.toString.call(variable) === "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" === Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'variable === "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" === variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'typeof variable !== "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" !== typeof variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'Object.prototype.toString.call(variable) !== "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" !== Object.prototype.toString.call(variable)', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'variable !== "[object String]"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"[object String]" !== variable', errors: [{ message: 'You should use the angular.isString method'}] }
{ code: '"[object String]" !== variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'typeof variable === "string"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"string" === typeof variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'variable === "string"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"string" === variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'typeof variable !== "string"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"string" !== typeof variable', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: 'variable !== "string"', errors: [{ message: 'You should use the angular.isString method'}] },
{ code: '"string" !== variable', errors: [{ message: 'You should use the angular.isString method'}] }
]
});
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