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.7 to 0.0.8

rules/ng_foreach.js

5

gulpfile.js

@@ -14,3 +14,6 @@ (function () {

'no-console': 0,
'quotes': [2, 'single']
'quotes': [2, 'single'],
'angular/ng_definedundefined': 0,
'angular/ng_typecheck_string': 0,
'angular/ng_typecheck_function': 0
},

@@ -17,0 +20,0 @@ globals: {

@@ -17,4 +17,7 @@ (function(){

'ng_filter_name': require('./rules/ng_filter_name'),
'ng_foreach': require('./rules/ng_foreach'),
'ng_function_type': require('./rules/ng_function_type'),
'ng_interval_service': require('./rules/ng_interval_service'),
'ng_json_functions': require('./rules/ng_json_functions'),
'ng_module_getter': require('./rules/ng_module_getter'),
'ng_module_name': require('./rules/ng_module_name'),

@@ -51,5 +54,8 @@ 'ng_module_setter': require('./rules/ng_module_setter'),

'ng_empty_controller': 0,
'ng_foreach': 0,
'ng_filter_name': 0,
'ng_function_type': 0,
'ng_interval_service': 2,
'ng_json_functions': 2,
'ng_module_getter': 2,
'ng_module_name': 0,

@@ -56,0 +62,0 @@ 'ng_module_setter': 2,

2

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

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

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

This repository will give access to new rules for the ESLint tool. You should use it only if you are developing an AngularJS application.
This repository will give access to new rules for the ESLint tool. You should use it only if you are developing an AngularJS application.
Since the 0.0.4 release, some rules defined in [John Papa's Guideline](https://github.com/johnpapa/angular-styleguide) have been implemented. In the description below, you will have a link to the corresponding part of the guideline, in order to have more information.
Since the 0.0.4 release, some rules defined in [John Papa's Guideline](https://github.com/johnpapa/angular-styleguide) have been implemented. In the description below, you will have a link to the corresponding part of the guideline, in order to have more information.
# Usage
1. Install `eslint-plugin-angular` as a dev-dependency:
1. Install `eslint` as a dev-dependency:
```shell
npm install --save-dev eslint
```
2. Install `eslint-plugin-angular` as a dev-dependency:
```shell
npm install --save-dev eslint-plugin-angular
```
2. Enable the plugin by adding it to your `.eslintrc`:
3. Enable the plugin by adding it to your `.eslintrc`:

@@ -26,3 +32,3 @@ ```yaml

```
3. You can also configure these rules in your `.eslintrc`. All rules defined in this plugin have to be prefixed by 'angular/'
4. You can also configure these rules in your `.eslintrc`. All rules defined in this plugin have to be prefixed by 'angular/'

@@ -36,3 +42,3 @@ ```yaml

We provide also three samples :
We provide also three samples :
* demo/npm (launch: npm run lint)

@@ -50,19 +56,23 @@ * demo/grunt (launch: grunt)

| 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. ("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_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. 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_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_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. ("ng_filter_name": [2, "ng"]) | 'ng_filter_name': 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_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. 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_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 | 'ng_no_services': [2, ['$http', '$resource', 'Restangular']] |
| 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. 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_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 |

@@ -80,3 +90,3 @@ | ng_typecheck_array | You should use the angular.isArray method instead of the default JavaScript implementation (typeof [] === "[object Array]"). | 'ng_typecheck_array': 2 |

# Need your help
It is an opensource project. Any help will be very useful. You can :
It is an opensource project. Any help will be very useful. You can :
- Create issue

@@ -90,5 +100,6 @@ - Send Pull Request

All contributions should be pushed in the current GIT branch.
## How to create a new rule
Here are the things you should do before sending a Pull Request with a new Rule :
Here are the things you should do before sending a Pull Request with a new Rule :

@@ -100,3 +111,15 @@ * Create a JavaScript file for the new rule in the rules directory

## Who uses it ?
## Default ESLint Configuration file
Here is the basic configuration for the rules defined in the ESLint plugin, in order to be compatible with the guideline provided by @johnpapa :
```json
{
"rules": {
"no-use-before-define": 0
}
}
```
## Who uses it ?
- [argo](https://github.com/albertosantini/argo)

@@ -103,0 +126,0 @@ - [generator-gillespie59-angular](https://github.com/Gillespie59/generator-gillespie59-angular/)

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

//state can be defined like .state({...}) or .state('name', {...})
var isObjectState = node.arguments.length === 1
var isObjectState = node.arguments.length === 1;
stateObject = isObjectState ? node.arguments[0] : node.arguments[1];

@@ -42,0 +42,0 @@

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

(controllerNameMatcher && (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') &&
node.id && controllerNameMatcher.test(node.id.name))
node.id && controllerNameMatcher.test(node.id.name));
}

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

item.parents.filter(isControllerFunction).forEach(function () {
context.report(item.stmt, "You should assign 'this' to a consistent variable across your project: {{capture}}",
context.report(item.stmt, 'You should assign "this" to a consistent variable across your project: {{capture}}',
{

@@ -40,3 +40,3 @@ 'capture': context.options[0]

item.parents.filter(isControllerFunction).forEach(function () {
context.report(item.stmt, "You should not use 'this' directly. Instead, assign it to a variable called '{{capture}}'",
context.report(item.stmt, 'You should not use "this" directly. Instead, assign it to a variable called "{{capture}}"',
{

@@ -71,3 +71,3 @@ 'capture': context.options[0]

}
}
};
};
};

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

(controllerNameMatcher && (node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration') &&
node.id && controllerNameMatcher.test(node.id.name))
node.id && controllerNameMatcher.test(node.id.name));
}

@@ -30,5 +30,5 @@

if (isControllerFunction(parent)) {
context.report(item.stmt, "You should not set properties on $scope in controllers. Use controllerAs syntax and add data to 'this'");
context.report(item.stmt, 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"');
}
})
});
});

@@ -62,3 +62,3 @@ }

}
}
};
};
};

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

var angularObjectList = ['value', 'constant', 'factory', 'service', 'provider', 'controller', 'filter', 'directive'];
var angularNamedObjectList = ['value', 'factory', 'service', 'provider', 'controller', 'filter', 'directive'];

@@ -16,2 +16,18 @@ function report(node, syntax){

function checkDi(syntax, node, param){
if(syntax === 'function' && (!utils.isFunctionType(param) && !utils.isIdentifierType(param))){
report(node, syntax);
}
if(syntax === 'array'){
if(!utils.isArrayType(param)){
report(node, syntax);
} else {
var fn = param.elements[param.elements.length - 1];
if(utils.isFunctionType(fn) && fn.params.length !== param.elements.length - 1){
context.report(fn, 'The signature of the method is incorrect', {});
}
}
}
}
return {

@@ -21,18 +37,12 @@

var syntax = context.options[0];
var callee = node.callee;
if (utils.isAngularComponent(node) && callee.type === 'MemberExpression' && angularObjectList.indexOf(callee.property.name) >= 0) {
if(syntax === 'function' && (!utils.isFunctionType(node.arguments[1]) && !utils.isIdentifierType(node.arguments[1]))){
report(node, syntax);
}
if(syntax === 'array'){
if(!utils.isArrayType(node.arguments[1])){
report(node, syntax);
} else {
var fn = node.arguments[1].elements[node.arguments[1].elements.length - 1];
if(utils.isFunctionType(fn) && fn.params.length !== node.arguments[1].elements.length - 1){
context.report(fn, 'The signature of the method is incorrect', {});
}
}
}
if (utils.isAngularComponent(node) && node.callee.type === 'MemberExpression' && angularNamedObjectList.indexOf(node.callee.property.name) >= 0) {
/**
* Check AngularJS components using functions with two parameters : name and constructor
*/
checkDi(context.options[0], node, node.arguments[1]);
} else if(utils.isAngularRunSection(node) || utils.isAngularConfigSection(node)){
/**
* Check AngularJS components using functions with one parameter : the constructor
*/
checkDi(context.options[0], node, node.arguments[0]);
}

@@ -39,0 +49,0 @@ }

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

'CallExpression': function(node) {
if(node.callee.type === 'MemberExpression' && node.callee.object.name === 'JSON'){
if(node.callee.property.name === 'stringify'){
'MemberExpression': function(node) {
if(node.object.name === 'JSON'){
if(node.property.name === 'stringify'){
context.report(node, 'You should use the toJson method instead of JSON.stringify', {});
} else if(node.callee.property.name === 'parse'){
} else if(node.property.name === 'parse'){
context.report(node, 'You should use the fromJson method instead of JSON.parse', {});

@@ -14,0 +14,0 @@ }

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

'CallExpression': function(node) {
if(node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === '$digest'){
'MemberExpression': function(node) {
if(node.property.type === 'Identifier' && node.property.name === '$digest'){
context.report(node, 'Instead of using the $digest() method, you should prefer $apply()', {});

@@ -11,0 +11,0 @@ }

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

'MemberExpression': function(node) {
if(node.property.type === 'Identifier'){
check(node, node.property.name);
}
'Identifier': function(node) {
check(node, node.name);
}

@@ -22,0 +20,0 @@ };

@@ -9,2 +9,42 @@ module.exports = function(context) {

var message = 'REST API calls should be implemented in a specific service';
function isArray(item) {
return Object.prototype.toString.call(item) === '[object Array]';
}
function isObject(item) {
return Object.prototype.toString.call(item) === '[object Object]';
}
if (isArray(context.options[0])) {
var badServices = context.options[0];
}
if (isArray(context.options[1])) {
angularObjectList = context.options[1];
}
if (isObject(context.options[0])) {
var map = context.options[0],
result = [],
prop;
for (prop in map) {
if (map.hasOwnProperty(prop)) {
result.push(prop);
}
}
angularObjectList = result;
}
function isSetBedService(serviceName, angularObjectName) {
if (map) {
return map[angularObjectName].indexOf(serviceName) >= 0;
}
else {
return badServices.indexOf(serviceName) >= 0;
}
}
return {

@@ -14,10 +54,10 @@

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

@@ -29,4 +69,4 @@ });

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

@@ -33,0 +73,0 @@ });

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

if(node.callee.property.name === 'on' || node.callee.property.name === 'watch'){
if(node.callee.property.name === '$on' || node.callee.property.name === '$watch'){

@@ -21,0 +21,0 @@ if(node.parent.type !== 'VariableDeclarator' && node.parent.type !== 'AssignmentExpression'){

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

return {
'MemberExpression': function(node){
if(node.object.name === 'Array' && node.property.name === 'isArray') {
context.report(node, 'You should use the angular.isArray method', {});
}
},
'BinaryExpression': function(node) {

@@ -17,0 +21,0 @@

@@ -9,3 +9,6 @@ (function(){

}
return getCallingIdentifier(calleeObject.callee.object);
if (calleeObject.callee && calleeObject.callee.object) {
return getCallingIdentifier(calleeObject.callee.object);
}
return null;
}

@@ -90,2 +93,14 @@ module.exports = {

isAngularModuleGetter: function(node){
return 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';
},
isAngularConfigSection: function(node){
return node.callee.type === 'MemberExpression' && node.callee.property.type === 'Identifier' && node.callee.property.name === 'config';
},
isRouteDefinition: function (node) {

@@ -96,3 +111,3 @@ //the route def function is .when(), so when we find that, go up through the chain and make sure

var callObject = getCallingIdentifier(node.callee.object);
return callObject.name === '$routeProvider';
return callObject && callObject.name === '$routeProvider';
}

@@ -107,3 +122,3 @@ return false;

var callObject = getCallingIdentifier(node.callee.object);
return callObject.name === '$stateProvider';
return callObject && callObject.name === '$stateProvider';
}

@@ -110,0 +125,0 @@ return false;

@@ -21,3 +21,8 @@ //------------------------------------------------------------------------------

'something.when("string", { controller: "MyController" })',
'when("string", { controller: "MyController" })'
'when("string", { controller: "MyController" })',
'state("mystate2", { })',
'var state = "mystate2"',
'something[type][changeType][state](test)',
'var when = "mystate2"',
'something[type][changeType][when](test)'
],

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

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

args: [2, 'vm'],
errors: [{ message: 'You should not use \'this\' directly. Instead, assign it to a variable called \'vm\''}] },
errors: [{ message: 'You should not use "this" directly. Instead, assign it to a variable called "vm"'}] },
{ code: 'angular.module("test").controller("Test", function () { this.test(); } )',
args: [2, 'vm'],
errors: [{ message: 'You should not use \'this\' directly. Instead, assign it to a variable called \'vm\''}] },
errors: [{ message: 'You should not use "this" directly. Instead, assign it to a variable called "vm"'}] },
{ code: 'var myController = function () { var ctrl = this; ctrl.test(); }; angular.module("test").controller("Test", myController )',
args: [2, 'vm'],
errors: [{ message: 'You should assign \'this\' to a consistent variable across your project: vm'}] },
errors: [{ message: 'You should assign "this" to a consistent variable across your project: vm'}] },
{ code: 'function MyController () { var ctrl = this; ctrl.test(); }',
args: [2, 'vm', '/[A-Z].*Controller/'],
errors: [{ message: 'You should assign \'this\' to a consistent variable across your project: vm'}] }
errors: [{ message: 'You should assign "this" to a consistent variable across your project: vm'}] }
]
});

@@ -20,25 +20,25 @@ //------------------------------------------------------------------------------

{ code: 'angular.module("test").controller("Test", function () { $scope.name = "test" } );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'angular.module("test").controller("Test", function () { var test = function () { $scope.thing = "none" }; } );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'function controllerFunc() { $scope.name = "test" } angular.module("test").controller("Test", controllerFunc );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'var controllerFunc = function () { $scope.name = "test" }; angular.module("test").controller("Test", controllerFunc );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'var controllerFunc = function () { $scope.name() }; angular.module("test").controller("Test", controllerFunc );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'angular.module("test").controller("Test", ["$scope", function ($scope) { $scope.name = "test" }] );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'var controllerFunc = function () { $scope.name() }; angular.module("test").controller("Test", ["$scope", controllerFunc] );',
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'function MyController () { $scope.name() }',
args: [2, /MyController/],
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'module.exports = function MyController () { $scope.name() }',
args: [2, /MyController/],
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] },
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] },
{ code: 'module.exports = function MyController () { $scope.name() }',
args: [2, '/MyController/'],
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to \'this\''}] }
errors: [{ message: 'You should not set properties on $scope in controllers. Use controllerAs syntax and add data to "this"'}] }
]
});

@@ -8,6 +8,43 @@ //------------------------------------------------------------------------------

var angularObjectList = ['value', 'constant', 'factory', 'service', 'provider', 'controller', 'filter', 'directive'];
var angularNamedObjectList = ['value', 'factory', 'service', 'provider', 'controller', 'filter', 'directive'];
var angularObjectList = ['run', 'config'];
var valid = [], invalid = [];
angularObjectList.forEach(function(object){
valid.push({
code: 'angular.' + object + '(function(){});',
args: [1, 'function']
}, {
code: 'angular.' + object + '([function(){}]);',
args: [1, 'array']
}, {
code: 'angular.' + object + '(["Service1", function(Service1){}]);',
args: [1, 'array']
}, {
code: 'angular.' + object + '(myFunction);function MyFunction(){}',
args: [1, 'function']
});
invalid.push({
code: 'angular.' + object + '(function(){});',
args: [1, 'array'],
errors: [{ message: 'You should use the array syntax for DI'}]
}, {
code: 'angular.' + object + '([function(){}]);',
args: [1, 'function'],
errors: [{ message: 'You should use the function syntax for DI'}]
}, {
code: 'angular.' + object + '(["Service1", function(){}]);',
args: [1, 'array'],
errors: [{ message: 'The signature of the method is incorrect'}]
}, {
code: 'angular.' + object + '([function(Service1){}]);',
args: [1, 'array'],
errors: [{ message: 'The signature of the method is incorrect'}]
});
});
angularNamedObjectList.forEach(function(object){
valid.push({

@@ -14,0 +51,0 @@ code: 'angular.' + object + '("name", function(){});',

@@ -10,2 +10,7 @@ //------------------------------------------------------------------------------

var defaultBadService = ['$http', '$resource', 'Restangular', '$q'];
var mapAngularObjectToBarServices = {
controller: defaultBadService,
filter: defaultBadService,
directive: defaultBadService
};
var valid = [], invalid = [];

@@ -26,7 +31,7 @@

args: [1, defaultBadService],
errors: [{ message: 'REST API calls should be implemented in a specific service'}]
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
}, {
code: 'app.' + object + '("name", ["' + badService + '", function(' + badService + '){}]);',
args: [1, defaultBadService],
errors: [{ message: 'REST API calls should be implemented in a specific service'}]
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
});

@@ -36,2 +41,49 @@ });

});
angularObjectList.forEach(function(object){
valid.push({
code: 'app.' + object + '("name", function(Service1){});',
args: [1, defaultBadService, [object]]
}, {
code: 'app.' + object + '("name", ["Service1", function(Service1){}]);',
args: [1, defaultBadService, [object]]
});
defaultBadService.forEach(function(badService){
invalid.push({
code: 'app.' + object + '("name", function(' + badService + '){});',
args: [1, defaultBadService, [object]],
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
}, {
code: 'app.' + object + '("name", ["' + badService + '", function(' + badService + '){}]);',
args: [1, defaultBadService, [object]],
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
});
});
});
angularObjectList.forEach(function(object){
valid.push({
code: 'app.' + object + '("name", function(Service1){});',
args: [1, mapAngularObjectToBarServices]
}, {
code: 'app.' + object + '("name", ["Service1", function(Service1){}]);',
args: [1, mapAngularObjectToBarServices]
});
defaultBadService.forEach(function(badService){
invalid.push({
code: 'app.' + object + '("name", function(' + badService + '){});',
args: [1, mapAngularObjectToBarServices],
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
}, {
code: 'app.' + object + '("name", ["' + badService + '", function(' + badService + '){}]);',
args: [1, mapAngularObjectToBarServices],
errors: [{ message: 'REST API calls should be implemented in a specific service (' + badService + ' in ' + object + ')'}]
});
});
});
//------------------------------------------------------------------------------

@@ -38,0 +90,0 @@ // Tests

@@ -15,17 +15,17 @@ //------------------------------------------------------------------------------

valid: [
'var variable = scope.on()',
'var variable = scope.watch()',
'var variable = $scope.on()',
'var variable = $scope.watch()',
'var variable = $rootScope.on()',
'var variable = $rootScope.watch()'
'var variable = scope.$on()',
'var variable = scope.$watch()',
'var variable = $scope.$on()',
'var variable = $scope.$watch()',
'var variable = $rootScope.$on()',
'var variable = $rootScope.$watch()'
],
invalid: [
{ code: 'scope.on()', errors: [{ message: 'The "on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: 'scope.watch()', errors: [{ message: 'The "watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$scope.on()', errors: [{ message: 'The "on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$scope.watch()', errors: [{ message: 'The "watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$rootScope.on()', errors: [{ message: 'The "on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$rootScope.watch()', errors: [{ message: 'The "watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] }
{ code: 'scope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: 'scope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$scope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$scope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$rootScope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
{ code: '$rootScope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] }
]
});

@@ -25,4 +25,5 @@ //------------------------------------------------------------------------------

{ 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: '"[object Array]" !== variable', errors: [{ message: 'You should use the angular.isArray method'}] },
{ code: 'Array.isArray(variable)', errors: [{ message: 'You should use the angular.isArray 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