Skip to content

For rule 'di' add allowCamelCaseMatch option #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
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
40 changes: 40 additions & 0 deletions docs/rules/di.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,24 @@ The following patterns are **not** considered problems when configured `"array"`
// ...
}]);

The following patterns are considered problems when configured `"array"` and `{"matchNames":true,"allowCamelCaseMatch":true}`:

/*eslint angular/di: [2,"array",{"matchNames":true,"allowCamelCaseMatch":true}]*/

// invalid
angular.module('myModule').factory('myService', ['$http', '$log', 'AnotherService', function ($log, $http, anotherservice) {
// ...
}]); // error: You have an error in your DI configuration. Each items of the array should match exactly one function parameter

The following patterns are **not** considered problems when configured `"array"` and `{"matchNames":true,"allowCamelCaseMatch":true}`:

/*eslint angular/di: [2,"array",{"matchNames":true,"allowCamelCaseMatch":true}]*/

// valid
angular.module('myModule').factory('myService', ['$http', '$log', 'AnotherService', function ($http, $log, anotherService) {
// ...
}]);

The following patterns are **not** considered problems when configured `"array"` and `{"matchNames":false}`:

/*eslint angular/di: [2,"array",{"matchNames":false}]*/
Expand Down Expand Up @@ -99,6 +117,28 @@ The following patterns are **not** considered problems when configured `"$inject
// ...
}

The following patterns are considered problems when configured `"$inject"` and `{"matchNames":true,"allowCamelCaseMatch":true}`:

/*eslint angular/di: [2,"$inject",{"matchNames":true,"allowCamelCaseMatch":true}]*/

// invalid
angular.module('myModule').factory('myService', myServiceFn);
myServiceFn.$inject=['$log', '$http', 'AnotherService'];
function myServiceFn($http, $log, 'anotherservice') {
// ...
} // error: You have an error in your DI configuration. Each items of the array should match exactly one function parameter

The following patterns are **not** considered problems when configured `"$inject"` and `{"matchNames":true,"allowCamelCaseMatch":true}`:

/*eslint angular/di: [2,"$inject",{"matchNames":true,"allowCamelCaseMatch":true}]*/

// valid
angular.module('myModule').factory('myService', myServiceFn);
myServiceFn.$inject=['$http', '$log', 'AnotherService'];
function myServiceFn($http, $log, anotherService) {
// ...
}

The following patterns are **not** considered problems when configured `"$inject"` and `{"matchNames":false}`:

/*eslint angular/di: [2,"$inject",{"matchNames":false}]*/
Expand Down
23 changes: 23 additions & 0 deletions examples/di.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ angular.module('myModule').factory('myService', ['$http', '$log', 'anotherServic
// ...
}]);

// example - valid: true, options: ["array", {matchNames: true, allowCamelCaseMatch: true}]
angular.module('myModule').factory('myService', ['$http', '$log', 'AnotherService', function ($http, $log, anotherService) {
// ...
}]);
// example - valid: true, options: ["array", {matchNames: false}]
angular.module('myModule').factory('myService', ['eslintService', function (service) {
// ...
Expand All @@ -25,6 +29,13 @@ function myServiceFn($http, $log, anotherService) {
// ...
}

// example - valid: true, options: ["$inject", {matchNames: true, allowCamelCaseMatch: true}]
angular.module('myModule').factory('myService', myServiceFn);
myServiceFn.$inject=['$http', '$log', 'AnotherService'];
function myServiceFn($http, $log, anotherService) {
// ...
}

// example - valid: true, options: ["$inject", {matchNames: false}]
angular.module('myModule').factory('myService', myServiceFn);
myServiceFn.$inject=['eslintService'];
Expand All @@ -42,6 +53,11 @@ angular.module('myModule').factory('myService', ['$http', '$log', function ($log
// ...
}]);

// example - valid: false, options: ["array", {matchNames: true, allowCamelCaseMatch: true}], errorMessage: "You have an error in your DI configuration. Each items of the array should match exactly one function parameter"
angular.module('myModule').factory('myService', ['$http', '$log', 'AnotherService', function ($log, $http, anotherservice) {
// ...
}]);

// example - valid: false, options: ["array"], errorMessage: "The signature of the method is incorrect"
angular.module('myModule').factory('myService', ['$http', function ($http, $log) {
// ...
Expand All @@ -67,3 +83,10 @@ myServiceFn.$inject=['$log', '$http'];
function myServiceFn($http, $log) {
// ...
}

// example - valid: false, options: ["$inject", {matchNames: true, allowCamelCaseMatch: true}], errorMessage: "You have an error in your DI configuration. Each items of the array should match exactly one function parameter"
angular.module('myModule').factory('myService', myServiceFn);
myServiceFn.$inject=['$log', '$http', 'AnotherService'];
function myServiceFn($http, $log, 'anotherservice') {
// ...
}
Loading