UPD ( 2015): eslint-plugin-angular ng_no_services, .
.
ESLint , , Controller Ctrl, , :
module.exports = function (context) {
"use strict";
var restrictedParams = context.options[0] || [];
var check = function (node) {
var name = node.id && node.id.name;
if (/(Controller|Ctrl)$/.test(name) && node.params) {
var params = node.params.map(
function (param) {
return param.name;
}
);
restrictedParams.filter(function (n) {
if (params.indexOf(n) != -1) {
context.report(node, "This controller function uses a restricted dependency {{param}}.", {
param: n
});
}
});
}
};
return {
"FunctionDeclaration": check,
"FunctionExpression": check
}
};
(eslint.json):
{
"env": {
"browser": true,
"node": true,
"jasmine": true
},
"globals": {
"angular": true,
"browser": true,
"element": true,
"by": false,
"inject": false
},
"plugins": [
"angularjs"
],
"rules": {
"ctrl-logic": [2, ["$http"]]
}
}
, , ( ):
angular
.module("app")
.controller("AppController", AppController);
AppController.$inject = ["$scope", "ConnectionService", "ConfigService", "StatusService", "$http"];
function AppController($scope, ConnectionService, ConfigService, StatusService, $http) {
...
}
ESLint, :
$ grunt lint
Running "eslint:target" (eslint) task
app/app-controller.js
8:0 error This controller function uses a restricted dependency $http ctrl-logic
✖ 1 problem
, , , , , , ( ).