Skip to content

Commit

Permalink
Finish rues no-directive
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmanuelDemey committed Dec 9, 2015
1 parent 7c9cd8b commit 44220ac
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Users may use the shareable [eslint-config-angular](https://github.com/dustinspe
"angular/directive-name": 0,
"angular/directive-restrict": 0,
"angular/document-service": 2,
"angular/dumb-inject": 0,
"angular/empty-controller": 0,
"angular/file-name": 0,
"angular/filter-name": 0,
Expand All @@ -129,7 +130,9 @@ Users may use the shareable [eslint-config-angular](https://github.com/dustinspe
"angular/no-controller": 0,
"angular/no-cookiestore": 2,
"angular/no-digest": 0,
"angular/no-http-callback": 0,
"angular/no-directive": 0,
"angular/no-directive-replace": 0,
"angular/no-http-callback": -1,
"angular/no-inline-template": [0, {"allowSimple": true}],
"angular/no-jquery-angularelement": 2,
"angular/no-private-call": 2,
Expand Down Expand Up @@ -183,6 +186,7 @@ These are rules designed to prevent you from making mistakes. They either prescr
* [directive-restrict](docs/directive-restrict.md) - disallow any other directive restrict than 'A' or 'E' ([y074](https://github.com/johnpapa/angular-styleguide#style-y074))
* [empty-controller](docs/empty-controller.md) - disallow empty controllers
* [no-controller](docs/no-controller.md) - disallow use of controllers (according to the component first pattern)
* [no-directive](docs/no-directive.md) -
* [no-inline-template](docs/no-inline-template.md) - disallow the use of inline templates
* [no-run-logic](docs/no-run-logic.md) - keep run functions clean and simple ([y171](https://github.com/johnpapa/angular-styleguide#style-y171))
* [no-services](docs/no-services.md) - disallow DI of specified services for other angular components (`$http` for controllers, filters and directives)
Expand Down Expand Up @@ -216,7 +220,6 @@ Angular often provide multi ways to to something. These rules help you to define
* [dumb-inject](docs/dumb-inject.md) - unittest `inject` functions should only consist of assignments from injected values to describe block variables
* [function-type](docs/function-type.md) - require and specify a consistent function style for components ('named' or 'anonymous') ([y024](https://github.com/johnpapa/angular-styleguide#style-y024))
* [module-dependency-order](docs/module-dependency-order.md) - require a consistent order of module dependencies
* [no-directive](docs/no-directive.md) -
* [no-service-method](docs/no-service-method.md) - use `factory()` instead of `service()` ([y040](https://github.com/johnpapa/angular-styleguide#style-y040))
* [one-dependency-per-line](docs/one-dependency-per-line.md) - require all DI parameters to be located in their own line
* [rest-service](docs/rest-service.md) - disallow different rest service and specify one of '$http', '$resource', 'Restangular'
Expand Down
23 changes: 22 additions & 1 deletion docs/no-directive.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,30 @@

Since AngularJS 1.5, we can use a new API when creating directives. This API will help the migration to the next version of the framework

## Examples

The following patterns are considered problems;

/*eslint angular/no-directive: 2*/

// invalid
angular.module('myModule').directive('helloWorld', function() {
}); // error: Directive should be implemented with the component method

The following patterns are **not** considered problems;

/*eslint angular/no-directive: 2*/

// valid
angular.module('myModule').component('helloWorld', function() {
return {
template: '<h2>Hello World!</h2>'
};
});

## Version

This rule was introduced in eslint-plugin-angular 0.15.0
This rule was introduced in eslint-plugin-angular 0.16.0

## Links

Expand Down
12 changes: 12 additions & 0 deletions examples/no-directive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// example - valid: true
angular.module('myModule').component('helloWorld', function() {
return {
template: '<h2>Hello World!</h2>'
};
});

// example - valid: false, errorMessage: "Directive should be implemented with the component method"
angular.module('myModule').directive('helloWorld', function() {
});


14 changes: 7 additions & 7 deletions rules/no-directive.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
/**
/*
* Since AngularJS 1.5, we can use a new API when creating directives. This API will help the migration to the next version of the framework
*
* @version 0.15.0
* @category conventions
*
* @version 0.16.0
* @category bestPractice
* @sinceAngularVersion 1.5
*/
'use strict';

var angularRule = require('./utils/angular-rule');


module.exports = angularRule(function(context) {console.log('init')
module.exports = angularRule(function(context) {
function report(node) {
context.report(node, 'Directive should be implemented with the "component" method', {});
context.report(node, 'Directive should be implemented with the component method', {});
}

return {
'angular:directive': function(callExpression, fn) {console.log('directive');
'angular:directive': function(callExpression, fn) {
report(callExpression);
}
};
Expand Down
8 changes: 4 additions & 4 deletions test/no-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ var RuleTester = require('eslint').RuleTester;
var eslintTester = new RuleTester();
eslintTester.run('no-directive', rule, {
valid: [
'module.component("", {})',
'module.component("", obj)'
'angular.module("").component("", {})',
'angular.module("").component("", obj)'
],
invalid: [
{code: 'module.directive("", function(){});', errors: [{message: 'Directive should be implemented wiith the "component" method'}]},
{code: 'module.directive("", fn);', errors: [{message: 'Directive should be implemented wiith the "component" method'}]}
{code: 'angular.module("").directive("", function(){});', errors: [{message: 'Directive should be implemented with the component method'}]},
{code: 'angular.module("").directive("", fn);', errors: [{message: 'Directive should be implemented with the component method'}]}
]
});

0 comments on commit 44220ac

Please sign in to comment.