diff --git a/README.md b/README.md index 5b5d83c6..f5dd3527 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,7 @@ We provide also three samples : | '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_angular_mock':0 | All methods defined in the angular.mock object are also available in the object window. So you can remove angular.mock from your code +| 'ng_no_controller': 0 | According to the Component-First pattern, we should avoid the use of AngularJS controller. | | 'ng_no_cookiestore':2 | In Angular 1.4, the $cookieStore service is now deprected. Please use the $cookies service instead| | 'ng_no_digest': 2 | DEPRECATED! 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| diff --git a/index.js b/index.js index 91daf8bf..a38f161c 100644 --- a/index.js +++ b/index.js @@ -26,6 +26,7 @@ 'ng_module_name': require('./rules/ng_module_name'), 'ng_module_setter': require('./rules/ng_module_setter'), 'ng_no_angular_mock': require('./rules/ng_no_angular_mock'), + 'ng_no_controller': require('./rules/ng_no_controller'), 'ng_no_cookiestore': require('./rules/ng_no_cookiestore'), 'ng_no_digest': require('./rules/ng_no_digest'), 'ng_no_jquery_angularelement': require('./rules/ng_no_jquery_angularelement'), @@ -70,6 +71,7 @@ 'ng_module_name': 0, 'ng_module_setter': 2, 'ng_no_angular_mock': 0, + 'ng_no_controller': 0, 'ng_no_cookiestore': 2, 'ng_no_digest': 0, 'ng_no_jquery_angularelement': 2, diff --git a/package.json b/package.json index 36707410..bbf82ba3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-angular", - "version": "0.8.1", + "version": "0.9.0", "description": "ESLint rules for AngularJS projects", "main": "index.js", "repository": { diff --git a/rules/ng_no_controller.js b/rules/ng_no_controller.js new file mode 100644 index 00000000..225102b4 --- /dev/null +++ b/rules/ng_no_controller.js @@ -0,0 +1,18 @@ +module.exports = function(context) { + + 'use strict'; + var utils = require('./utils/utils'); + + return { + + 'CallExpression': function(node) { + if(utils.isAngularControllerDeclaration(node)) { + context.report(node, 'Based on the Component-First Pattern, you should avoid the use of controllers', {}); + } + } + }; +}; + +module.exports.schema = [ + // JSON Schema for rule options goes here +]; diff --git a/test/ng_no_controller.js b/test/ng_no_controller.js new file mode 100644 index 00000000..dcd537a3 --- /dev/null +++ b/test/ng_no_controller.js @@ -0,0 +1,22 @@ +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +var rule = require('../rules/ng_no_controller'), + RuleTester = require("eslint").RuleTester; + +//------------------------------------------------------------------------------ +// Tests +//------------------------------------------------------------------------------ + +var eslintTester = new RuleTester(); +eslintTester.run('ng_no_controller', rule, { + valid: [ + 'app.controller("")', + 'app.service("", function(){})' + ], + invalid: [ + { code: 'app.controller("", function(){})', errors: [{ message: 'Based on the Component-First Pattern, you should avoid the use of controllers'}] }, + { code: 'angular.module("").controller("", function(){})', errors: [{ message: 'Based on the Component-First Pattern, you should avoid the use of controllers'}] } + ] +});