Skip to content
Merged

2.2.0 #463

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions docs/no-services.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,45 @@ The following patterns are **not** considered problems with default config;
// ...
});

The following patterns are considered problems when configured `["$http","$q"]`:
The following patterns are considered problems when configured `["http","q"]`:

/*eslint angular/no-services: [2,["$http","$q"]]*/
/*eslint angular/no-services: [2,["http","q"]]*/

// invalid
app.directive('helloWorld', function($q) {
// ...
}); // error: REST API calls should be implemented in a specific service ($q in directive)

The following patterns are **not** considered problems when configured `["$http","$q"]`:
The following patterns are **not** considered problems when configured `["http","q"]`:

/*eslint angular/no-services: [2,["$http","$q"]]*/
/*eslint angular/no-services: [2,["http","q"]]*/

// valid
app.directive('helloWorld', function($resource) {
// ...
});

The following patterns are considered problems when configured `["$http","$q"]` and `["directive"]`:
The following patterns are considered problems when configured `["http","q"]` and `["directive"]`:

/*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/
/*eslint angular/no-services: [2,["http","q"],["directive"]]*/

// invalid
app.directive('MyController', function($http) {
// ...
}); // error: REST API calls should be implemented in a specific service ($http in directive)

The following patterns are **not** considered problems when configured `["$http","$q"]` and `["directive"]`:
The following patterns are **not** considered problems when configured `["http","q"]` and `["directive"]`:

/*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/
/*eslint angular/no-services: [2,["http","q"],["directive"]]*/

// valid
app.controller('MyController', function($http) {
// ...
});

The following patterns are considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`:
The following patterns are considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`:

/*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/
/*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/

// invalid
app.controller('MyController', function($resource, $log) {
Expand All @@ -84,9 +84,9 @@ The following patterns are considered problems when configured `{"directive":["$
// ...
}); // error: REST API calls should be implemented in a specific service ($http in directive)

The following patterns are **not** considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`:
The following patterns are **not** considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`:

/*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/
/*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/

// valid
app.controller('MyController', function($http, $q, $log) {
Expand Down
17 changes: 9 additions & 8 deletions examples/no-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ app.controller('MyController', function(myService) {
// ...
});


// example - valid: false, errorMessage: "REST API calls should be implemented in a specific service ($http in controller)"
app.controller('MyController', function($http) {
// ...
Expand All @@ -13,43 +14,43 @@ app.directive('helloWorld', function($resource) {
// ...
});

// example - valid: true, options: [["$http","$q"]]
// example - valid: true, options: [["http","q"]]
app.directive('helloWorld', function($resource) {
// ...
});

// example - valid: false, options: [["$http","$q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)"
// example - valid: false, options: [["http","q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)"
app.directive('helloWorld', function($q) {
// ...
});

// example - valid: true, options: [["$http","$q"],["directive"]]
// example - valid: true, options: [["http","q"],["directive"]]
app.controller('MyController', function($http) {
// ...
});

// example - valid: false, options: [["$http","$q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
// example - valid: false, options: [["http","q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
app.directive('MyController', function($http) {
// ...
});


// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}]
// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}]
app.controller('MyController', function($http, $q, $log) {
// ...
});

// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}]
// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}]
app.directive('helloWorld', function($resource, $log) {
// ...
});

// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)"
// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)"
app.controller('MyController', function($resource, $log) {
// ...
});

// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
app.directive('helloWorld', function($http, $log) {
// ...
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-plugin-angular",
"version": "2.1.0",
"version": "2.2.0",
"description": "ESLint rules for AngularJS projects",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 4 additions & 4 deletions rules/module-dependency-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ module.exports = {
];

function checkLiteral(node) {
if (node && node.type !== 'Literal') {
context.report(node, 'Unexpected non-literal value');
if (node && node.type !== 'Literal' && node.type !== 'Identifier') {
context.report(node, 'Unexpected non-literal or identifier value' + node.type);
return false;
}
if (!node) {
Expand All @@ -76,7 +76,7 @@ module.exports = {
if (!checkLiteral(node)) {
return;
}
var value = node.value;
var value = node.value || node.name;
if (lastCorrect === undefined || lastCorrect.localeCompare(value) < 0) {
lastCorrect = value;
} else {
Expand All @@ -103,7 +103,7 @@ module.exports = {
if (!checkLiteral(node)) {
return;
}
var value = node.value;
var value = node.value || node.name;
if (lastCorrect === undefined) {
lastCorrect = value;
if (isCustomModule(value)) {
Expand Down
2 changes: 1 addition & 1 deletion rules/no-services.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = {
}

if (context.options[0] === undefined) {
badServices = ['/\$http/', '/\$resource/', 'Restangular', '/\$q/', '/\$filter/'];
badServices = [/\$http/, /\$resource/, /Restangular/, /\$q/, /\$filter/];
}

if (isArray(context.options[0])) {
Expand Down
26 changes: 15 additions & 11 deletions test/module-dependency-order.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ eslintTester.run('module-dependency-order', rule, {
code: 'angular.module("", ["app.filters","ngCordova","ngMaterial","ui.router"])',
options: [{grouped: false}]
},
{
code: 'angular.module("", [appFilters,ngCordova,ngMaterial,uiRouter])',
options: [{grouped: false}]
},
{
code: 'angular.module("", [appFilters,"ngCordova",ngMaterial,uiRouter])',
options: [{grouped: false}]
},
// grouped mode
'angular.module("", ["ng","ngAnimate","ngAria","ngCookies","ngLocale","ngMaterial","ngMessageFormat","ngMessages","ngMock","ngNewRouter","ngResource","ngRoute","ngSanitize","ngTouch"])',
'angular.module("", ["ngAnimate","ngResource","ngCordova"])',
'angular.module("", [ngAnimate,ngResource,ngCordova])',
'angular.module("", [ngAnimate,"ngResource",ngCordova])',
{
code: 'angular.module("", ["ngAnimate","ngResource","ngCordova","app.filters"])',
options: [{prefix: 'app'}]
Expand All @@ -38,14 +48,6 @@ eslintTester.run('module-dependency-order', rule, {
{message: 'Dependencies should be a literal array'}
]
},
// combined mode
{
code: 'angular.module("", [dep])',
options: [{grouped: false}],
errors: [
{message: 'Unexpected non-literal value'}
]
},
{
code: 'angular.module("", ["ngCordova","app.filters","app.resources","ngMaterial","app.user","ui.router"])',
options: [{grouped: false}],
Expand All @@ -55,11 +57,13 @@ eslintTester.run('module-dependency-order', rule, {
{message: 'app.user should be sorted before ngMaterial'}
]
},
// grouped mode
{
code: 'angular.module("", [dep])',
code: 'angular.module("", [ngCordova,"app.filters","app.resources",ngMaterial,"app.user","ui.router"])',
options: [{grouped: false}],
errors: [
{message: 'Unexpected non-literal value'}
{message: 'app.filters should be sorted before ngCordova'},
{message: 'app.resources should be sorted before ngCordova'},
{message: 'app.user should be sorted before ngMaterial'}
]
},
{
Expand Down