eslint-plugin-angular
Advanced tools
Comparing version
@@ -23,3 +23,3 @@ (function () { | ||
})) | ||
.pipe(eslint.failOnError()); | ||
.pipe(eslint.format()); | ||
}); | ||
@@ -26,0 +26,0 @@ |
18
index.js
@@ -9,5 +9,14 @@ (function(){ | ||
'ng_definedundefined': require('./rules/ng_definedundefined'), | ||
'ng_di': require('./rules/ng_di'), | ||
'ng_directive_name': require('./rules/ng_directive_name'), | ||
'ng_document_service': require('./rules/ng_document_service'), | ||
'ng_empty_controller': require('./rules/ng_empty_controller'), | ||
'ng_filter_name': require('./rules/ng_filter_name'), | ||
'ng_interval_service': require('./rules/ng_interval_service'), | ||
'ng_json_functions': require('./rules/ng_json_functions'), | ||
'ng_module_name': require('./rules/ng_module_name'), | ||
'ng_no_digest': require('./rules/ng_no_ng_no_digest'), | ||
'ng_no_jquery_angularelement': require('./rules/ng_no_jquery_angularelement'), | ||
'ng_no_private_call': require('./rules/ng_no_private_call'), | ||
'ng_no_services': require('./rules/ng_no-service-ctrl'), | ||
'ng_on_watch': require('./rules/ng_on_watch'), | ||
@@ -30,5 +39,14 @@ 'ng_service_name': require('./rules/ng_service_name'), | ||
'ng_definedundefined': 2, | ||
'ng_di': [2, 'function'], | ||
'ng_directive_name': 0, | ||
'ng_document_service': 2, | ||
'ng_empty_controller': 0, | ||
'ng_filter_name': 0, | ||
'ng_interval_service': 2, | ||
'ng_json_functions': 2, | ||
'ng_module_name': 0, | ||
'ng_no_digest': 2, | ||
'ng_no_jquery_angularelement': 2, | ||
'ng_no_private_call': 2, | ||
'ng_no_services': [2, ['$http', '$resource', 'Restangular']], | ||
'ng_on_watch': 2, | ||
@@ -35,0 +53,0 @@ 'ng_service_name': 0, |
{ | ||
"name": "eslint-plugin-angular", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "ESLint rules for AngularJS projects", | ||
@@ -18,17 +18,23 @@ "main": "index.js", | ||
"chai": "^1.10.0", | ||
"eslint": "^0.8.2", | ||
"eslint-tester": "^0.3.0", | ||
"coveralls": "^2.11.2", | ||
"eslint": "^0.13.0", | ||
"eslint-tester": "^0.5.0", | ||
"gulp": "^3.8.10", | ||
"gulp-eslint": "^0.1.8", | ||
"gulp-istanbul": "^0.5.0", | ||
"gulp-eslint": "^0.3.0", | ||
"gulp-istanbul": "0.6.0", | ||
"gulp-mocha": "^2.0.0", | ||
"istanbul": "^0.3.5", | ||
"mocha": "https://registry.npmjs.org/mocha/-/mocha-1.21.5.tgz", | ||
"mocha": "2.1.0", | ||
"shelljs": "^0.3.0", | ||
"shelljs-nodecli": "^0.1.1" | ||
}, | ||
}, | ||
"peerDependencies": { | ||
"eslint": ">=0.8.0" | ||
}, | ||
"keywords": ["eslint", "eslintplugin", "angular", "angularjs"] | ||
}, | ||
"keywords": [ | ||
"eslint", | ||
"eslintplugin", | ||
"angular", | ||
"angularjs" | ||
] | ||
} |
[](https://travis-ci.org/Gillespie59/eslint-plugin-angular) | ||
[](https://david-dm.org/Gillespie59/eslint-plugin-angular) | ||
[](https://david-dm.org/Gillespie59/eslint-plugin-angular#info=devDependencies) | ||
[](https://gitter.im/Gillespie59/eslint-plugin-angular?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) | ||
[](https://coveralls.io/r/Gillespie59/eslint-plugin-angular?branch=master) | ||
This repository will give access to new rules for the ESLint tool. You should use it only if you are developping an AngularJS application. | ||
Since the 0.0.4 release, some rules defined in [John Papa's Guideline](https://github.com/johnpapa/angularjs-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 informations. | ||
# Usage | ||
@@ -26,22 +29,31 @@ | ||
| Name | Description | | ||
| ------------- | ------------- | | ||
| ng_angularelement | The angular.element method should be used of the $ or jQuery object (if you are using jQuery of course). If the jQuery library is imported, angular.element will be a wrapper around the jQuery object. | | ||
| ng_controller_name | All your controllers should have a name starting the parameter you can define in your config object ("ng_controller_name": [2, "ng"]) | | ||
| ng_definedundefined | You should use the angular.isUndefined or angular.isDefined methods instead of using the keyword undefined (myVar === undefined) | | ||
| ng_directive_name | All your directives should have a name starting the parameter you can define in your config object ("ng_directive_name": [2, "ng"]) | | ||
| ng_filter_name | All your filters should have a name starting the parameter you can define in your config object ("ng_filter_name": [2, "ng"]) | | ||
| ng_json_functions | You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify | | ||
| 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 | | ||
| ng_service_name | All your services should have a name starting the parameter you can define in your config object ("ng_service_name": [2, "ng"]) | | ||
| ng_timeout_service | Instead of the default setTimeout function, you should use the AngularJS wrapper service $timeout | | ||
| ng_typecheck_array | You should use the angular.isArray method instead of the default JavaScript implementation (typeof [] === "[object Array]"). | | ||
| ng_typecheck_boolean | You should use the angular.isBoolean method instead of the default JavaScript implementation (typeof true === "[object Boolean]"). | | ||
| ng_typecheck_date | You should use the angular.isDate method instead of the default JavaScript implementation (typeof new Date() === "[object Date]"). | | ||
| ng_typecheck_function | You should use the angular.isFunction method instead of the default JavaScript implementation (typeof function(){} ==="[object Function]"). | | ||
| ng_typecheck_number | You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]"). | | ||
| ng_typecheck_object | Yo u should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]"). | | ||
| ng_typecheck_regexp | You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]"). | | ||
| ng_typecheck_string | You should use the angular.isString method instead of the default JavaScript implementation (typeof "" === "[object String]"). | | ||
| ng_window_service | Instead of the default window object, you should prefer the AngularJS wrapper service $window. | | ||
| Name | Description | Default Configuration | | ||
| ------------- | ------------- | ------------- | | ||
| ng_angularelement | The angular.element method should be used of the $ or jQuery object (if you are using jQuery of course). If the jQuery library is imported, angular.element will be a wrapper around the jQuery object. | 'ng_angularelement': 1 | | ||
| 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/angularjs-styleguide#style-y123), [Y124](https://github.com/johnpapa/angularjs-styleguide#style-y124)| 'ng_controller_name': 0 | | ||
| ng_definedundefined | You should use the angular.isUndefined or angular.isDefined methods instead of using the keyword undefined. We check also 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 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/angularjs-styleguide#style-y073), [Y126](https://github.com/johnpapa/angularjs-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/angularjs-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 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_interval_service | Instead of the default setInterval function, you should use the AngularJS wrapper service $interval [Y181](https://github.com/johnpapa/angularjs-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/angularjs-styleguide#style-y127)| 'ng_module_name': 0 | | ||
| 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 ne 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_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 | 'ng_on_watch': 2 | | ||
| ng_service_name | All your services should have a name starting 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/angularjs-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/angularjs-styleguide#style-y181) | 'ng_timeout_service': 2 | | ||
| ng_typecheck_array | You should use the angular.isArray method instead of the default JavaScript implementation (typeof [] === "[object Array]"). | 'ng_typecheck_array': 2 | | ||
| ng_typecheck_boolean | You should use the angular.isBoolean method instead of the default JavaScript implementation (typeof true === "[object Boolean]"). | 'ng_typecheck_boolean': 2 | | ||
| ng_typecheck_date | You should use the angular.isDate method instead of the default JavaScript implementation (typeof new Date() === "[object Date]"). | 'ng_typecheck_date': 2 | | ||
| ng_typecheck_function | You should use the angular.isFunction method instead of the default JavaScript implementation (typeof function(){} ==="[object Function]"). | 'ng_typecheck_function': 2 | | ||
| ng_typecheck_number | You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]"). | 'ng_typecheck_number': 2 | | ||
| ng_typecheck_object | Yo u should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]"). | 'ng_typecheck_object': 2 | | ||
| ng_typecheck_regexp | You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]"). | 'ng_typecheck_regexp': 2 | | ||
| ng_typecheck_string | You should use the angular.isString method instead of the default JavaScript implementation (typeof "" === "[object String]"). | 'ng_typecheck_string': 2 | | ||
| ng_window_service | Instead of the default window object, you should prefer the AngularJS wrapper service $window. [Y180](https://github.com/johnpapa/angularjs-styleguide#style-y180) | 'ng_window_service': 2 | | ||
@@ -57,1 +69,11 @@ # Need your help | ||
- Reply to issues | ||
## Who use it ? | ||
- [argo](https://github.com/albertosantini/argo) | ||
- [generator-gillespie59-angular](https://github.com/Gillespie59/generator-gillespie59-angular/) | ||
## Team | ||
[](http://gillespie59.github.io/) | | ||
:---:| | ||
[Emmanuel DEMEY](http://gillespie59.github.io/) |
@@ -5,10 +5,4 @@ module.exports = function(context) { | ||
function report(node, name, prefix){ | ||
var utils = require('./utils/utils'); | ||
context.report(node, 'The {{controller}} controller should be prefixed by {{prefix}}', { | ||
controller: name, | ||
prefix: prefix | ||
}); | ||
} | ||
return { | ||
@@ -23,4 +17,12 @@ | ||
if(name !== undefined && !(name.indexOf(prefix) === 0)){ | ||
report(node, name, prefix); | ||
if(name !== undefined && !utils.isRegexp(prefix) && !(name.indexOf(prefix) === 0)){ | ||
context.report(node, 'The {{controller}} controller should be prefixed by {{prefix}}', { | ||
controller: name, | ||
prefix: prefix | ||
}); | ||
} else if(utils.isRegexp(prefix) && !prefix.test(name)){ | ||
context.report(node, 'The {{controller}} controller should follow this pattern: {{prefix}}', { | ||
controller: name, | ||
prefix: prefix.toString() | ||
}); | ||
} | ||
@@ -27,0 +29,0 @@ |
@@ -9,2 +9,15 @@ module.exports = function(context) { | ||
return { | ||
'MemberExpression': function(node){ | ||
if(node.object.name === 'angular' | ||
&& node.parent !== undefined && node.parent.parent !== undefined && node.parent.parent.operator === '!'){ | ||
if(node.property.name === 'isDefined'){ | ||
context.report(node, 'Instead of !angular.isDefined, you can use the out-of-box angular.isUndefined method', {}); | ||
} else if(node.property.name === 'isUndefined'){ | ||
context.report(node, 'Instead of !angular.isUndefined, you can use the out-of-box angular.isDefined method', {}); | ||
} | ||
} | ||
}, | ||
'BinaryExpression': function(node) { | ||
@@ -11,0 +24,0 @@ |
@@ -5,10 +5,4 @@ module.exports = function(context) { | ||
function report(node, name, prefix){ | ||
var utils = require('./utils/utils'); | ||
context.report(node, 'The {{directive}} directive should be prefixed by {{prefix}}', { | ||
directive: name, | ||
prefix: prefix | ||
}); | ||
} | ||
return { | ||
@@ -23,4 +17,18 @@ | ||
if(name !== undefined && !(name.indexOf(prefix) === 0)){ | ||
report(node, name, prefix); | ||
if(name !== undefined && name.indexOf('ng') === 0){ | ||
context.report(node, 'The {{directive}} directive should not start with "ng". This is reserved for AngularJS directives', { | ||
directive: name | ||
}); | ||
} else { | ||
if(name !== undefined && !utils.isRegexp(prefix) && !(name.indexOf(prefix) === 0)){ | ||
context.report(node, 'The {{directive}} directive should be prefixed by {{prefix}}', { | ||
directive: name, | ||
prefix: prefix | ||
}); | ||
} else if(utils.isRegexp(prefix) && !prefix.test(name)){ | ||
context.report(node, 'The {{directive}} directive should follow this pattern: {{prefix}}', { | ||
directive: name, | ||
prefix: prefix.toString() | ||
}); | ||
} | ||
} | ||
@@ -27,0 +35,0 @@ |
@@ -5,10 +5,4 @@ module.exports = function(context) { | ||
function report(node, name, prefix){ | ||
var utils = require('./utils/utils'); | ||
context.report(node, 'The {{filter}} filter should be prefixed by {{prefix}}', { | ||
filter: name, | ||
prefix: prefix | ||
}); | ||
} | ||
return { | ||
@@ -23,4 +17,12 @@ | ||
if(name !== undefined && !(name.indexOf(prefix) === 0)){ | ||
report(node, name, prefix); | ||
if(name !== undefined && !utils.isRegexp(prefix) && !(name.indexOf(prefix) === 0)){ | ||
context.report(node, 'The {{filter}} filter should be prefixed by {{prefix}}', { | ||
filter: name, | ||
prefix: prefix | ||
}); | ||
} else if(utils.isRegexp(prefix) && !prefix.test(name)){ | ||
context.report(node, 'The {{filter}} filter should follow this pattern: {{prefix}}', { | ||
filter: name, | ||
prefix: prefix.toString() | ||
}); | ||
} | ||
@@ -27,0 +29,0 @@ |
@@ -5,10 +5,4 @@ module.exports = function(context) { | ||
function report(node, name, prefix){ | ||
var utils = require('./utils/utils'); | ||
context.report(node, 'The {{service}} service should be prefixed by {{prefix}}', { | ||
service: name, | ||
prefix: prefix | ||
}); | ||
} | ||
return { | ||
@@ -24,6 +18,19 @@ | ||
if(name !== undefined && !(name.indexOf(prefix) === 0)){ | ||
report(node, name, prefix); | ||
if(name !== undefined && name.indexOf('$') === 0){ | ||
context.report(node, 'The {{service}} service should not start with "$". This is reserved for AngularJS services', { | ||
service: name | ||
}); | ||
} else { | ||
if(name !== undefined && !utils.isRegexp(prefix) && !(name.indexOf(prefix) === 0)){ | ||
context.report(node, 'The {{service}} service should be prefixed by {{prefix}}', { | ||
service: name, | ||
prefix: prefix | ||
}); | ||
} else if(utils.isRegexp(prefix) && !prefix.test(name)){ | ||
context.report(node, 'The {{service}} service should follow this pattern: {{prefix}}', { | ||
service: name, | ||
prefix: prefix.toString() | ||
}); | ||
} | ||
} | ||
} | ||
@@ -30,0 +37,0 @@ } |
@@ -5,12 +5,16 @@ module.exports = function(context) { | ||
function report(node){ | ||
context.report(node, 'You should use the $timeout service instead of the default window.setTimeout method', {}); | ||
} | ||
var message = 'You should use the $timeout service instead of the default window.setTimeout method'; | ||
return { | ||
'MemberExpression': function(node) { | ||
if(node.object.name === 'window' && node.property.name === 'setTimeout'){ | ||
context.report(node, message, {}); | ||
} | ||
}, | ||
'CallExpression': function(node) { | ||
if(node.callee.type === 'MemberExpression' && node.callee.object.name === 'window' && node.callee.property.name === 'setTimeout'){ | ||
report(node); | ||
} | ||
if(node.callee.name === 'setTimeout'){ | ||
context.report(node, message, {}); | ||
} | ||
} | ||
@@ -17,0 +21,0 @@ }; |
@@ -9,6 +9,7 @@ module.exports = function(context) { | ||
var restrict = ['document', 'setInterval', 'setTimeout']; | ||
return { | ||
'MemberExpression': function(node) { | ||
if(node.object.name === 'window'){ | ||
if(node.object.name === 'window' && restrict.indexOf(node.property.name) < 0){ | ||
report(node); | ||
@@ -15,0 +16,0 @@ } |
@@ -17,2 +17,5 @@ //------------------------------------------------------------------------------ | ||
args: [1, 'eslint'] | ||
}, { | ||
code: 'angular.controller("eslintController", function(){});', | ||
args: [1, /^eslint/] | ||
}], | ||
@@ -29,4 +32,9 @@ invalid: [ | ||
errors: [{ message: 'The esLintController controller should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.controller("Controller", function(){});', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The Controller controller should follow this pattern: /^eslint/'}] | ||
} | ||
] | ||
}); |
@@ -22,4 +22,6 @@ //------------------------------------------------------------------------------ | ||
{ code: 'undefined !== variable', errors: [{ message: 'You should not use directly the "undefined" keyword. Prefer angular.isUndefined or angular.isDefined'}] }, | ||
{ code: 'variable !== undefined', errors: [{ message: 'You should not use directly the "undefined" keyword. Prefer angular.isUndefined or angular.isDefined'}] } | ||
{ code: 'variable !== undefined', errors: [{ message: 'You should not use directly the "undefined" keyword. Prefer angular.isUndefined or angular.isDefined'}] }, | ||
{ code: '!angular.isUndefined(variable)', errors: [{ message: 'Instead of !angular.isUndefined, you can use the out-of-box angular.isDefined method'}] }, | ||
{ code: '!angular.isDefined(variable)', errors: [{ message: 'Instead of !angular.isDefined, you can use the out-of-box angular.isUndefined method'}] } | ||
] | ||
}); |
@@ -17,2 +17,5 @@ //------------------------------------------------------------------------------ | ||
args: [1, 'eslint'] | ||
}, { | ||
code: 'angular.directive("eslintDirective", function(){});', | ||
args: [1, /^eslint/] | ||
}], | ||
@@ -29,4 +32,13 @@ invalid: [ | ||
errors: [{ message: 'The esLintDirective directive should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.directive("Directive", function(){});', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The Directive directive should follow this pattern: /^eslint/'}] | ||
}, { | ||
code: 'angular.directive("ngDirective", []);', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The ngDirective directive should not start with "ng". This is reserved for AngularJS directives'}] | ||
} | ||
] | ||
}); |
@@ -17,2 +17,5 @@ //------------------------------------------------------------------------------ | ||
args: [1, 'eslint'] | ||
}, { | ||
code: 'angular.filter("eslintFilter", function(){});', | ||
args: [1, /^eslint/] | ||
}], | ||
@@ -24,9 +27,12 @@ invalid: [ | ||
errors: [{ message: 'The Filter filter should be prefixed by eslint'}] | ||
}, | ||
{ | ||
}, { | ||
code: 'angular.filter("esLintFilter", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintFilter filter should be prefixed by eslint'}] | ||
}, { | ||
code: 'angular.filter("Filter", function(){});', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The Filter filter should follow this pattern: /^eslint/'}] | ||
} | ||
] | ||
}); |
@@ -11,73 +11,37 @@ //------------------------------------------------------------------------------ | ||
//------------------------------------------------------------------------------ | ||
var eslintTester = new ESLintTester(eslint); | ||
eslintTester.addRuleTest('rules/ng_service_name', { | ||
valid: [{ | ||
code: 'angular.service("eslintDirective", function(){});', | ||
var valid = [], invalid = []; | ||
['service', 'factory', 'provider', 'constant', 'value'].forEach(function(syntax){ | ||
valid.push({ | ||
code: 'angular.' + syntax + '("eslintDirective", function(){});', | ||
args: [1, 'eslint'] | ||
}, { | ||
code: 'angular.factory("eslintDirective", function(){});', | ||
args: [1, 'eslint'] | ||
code: 'angular.' + syntax + '("eslintDirective", function(){});', | ||
args: [1, /^eslint/] | ||
}); | ||
invalid.push({ | ||
code: 'angular.' + syntax + '("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, { | ||
code: 'angular.provider("eslintDirective", function(){});', | ||
args: [1, 'eslint'] | ||
code: 'angular.' + syntax + '("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
}, { | ||
code: 'angular.constant("eslintDirective", function(){});', | ||
args: [1, 'eslint'] | ||
}, { | ||
code: 'angular.value("eslintDirective", function(){});', | ||
args: [1, 'eslint'] | ||
}], | ||
invalid: [ | ||
{ | ||
code: 'angular.service("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.service("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.provider("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.provider("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.factory("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.factory("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.constant("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.constant("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.value("Service", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The Service service should be prefixed by eslint'}] | ||
}, | ||
{ | ||
code: 'angular.value("esLintService", function(){});', | ||
args: [1, 'eslint'], | ||
errors: [{ message: 'The esLintService service should be prefixed by eslint'}] | ||
} | ||
] | ||
code: 'angular.' + syntax + '("Service", function(){});', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The Service service should follow this pattern: /^eslint/'}] | ||
}, | ||
{ | ||
code: 'angular.' + syntax + '("$Service", function(){});', | ||
args: [1, /^eslint/], | ||
errors: [{ message: 'The $Service service should not start with "$". This is reserved for AngularJS services'}] | ||
}); | ||
}); | ||
var eslintTester = new ESLintTester(eslint); | ||
eslintTester.addRuleTest('rules/ng_service_name', { | ||
valid: valid, | ||
invalid: invalid | ||
}); |
@@ -21,4 +21,6 @@ //------------------------------------------------------------------------------ | ||
{ code: 'window.setTimeout(function(){}, 1000)', errors: [{ message: 'You should use the $timeout service instead of the default window.setTimeout method'}] }, | ||
{ code: 'window.setTimeout(function(){}, 1000, param1)', errors: [{ message: 'You should use the $timeout service instead of the default window.setTimeout method'}] } | ||
{ code: 'window.setTimeout(function(){}, 1000, param1)', errors: [{ message: 'You should use the $timeout service instead of the default window.setTimeout method'}] }, | ||
{ code: 'setTimeout(function(){}, 1000)', errors: [{ message: 'You should use the $timeout service instead of the default window.setTimeout method'}] }, | ||
{ code: 'setTimeout(function(){}, 1000, param1)', errors: [{ message: 'You should use the $timeout service instead of the default window.setTimeout method'}] } | ||
] | ||
}); |
@@ -16,3 +16,7 @@ //------------------------------------------------------------------------------ | ||
'$window.location.href = ""', | ||
'$window.alert("")' | ||
'$window.alert("")', | ||
'window.setInterval(function(){}, 0)', | ||
'window.setTimeout(function(){}, 0)', | ||
'window.document', | ||
'window.document.title' | ||
], | ||
@@ -19,0 +23,0 @@ invalid: [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
79243
61.02%62
44.19%1457
54.18%78
39.29%12
9.09%