Skip to content

Commit 6f9be27

Browse files
committed
Merge pull request #350 from Gillespie59/1.0
1.0
2 parents 273171b + 24c8227 commit 6f9be27

34 files changed

+168
-479
lines changed

.eslintrc renamed to .eslintrc.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ rules:
3232
no-sparse-arrays: 2
3333
no-unreachable: 1
3434
use-isnan: 2
35+
3536
valid-jsdoc: 0
3637
valid-typeof: 2
3738

@@ -160,6 +161,13 @@ rules:
160161
- 2
161162
- 4
162163
- SwitchCase: 1
164+
165+
# http://eslint.org/docs/rules/keyword-spacing.html
166+
keyword-spacing:
167+
- 2
168+
- before: true
169+
after: true
170+
overrides: {}
163171
key-spacing:
164172
- 2
165173
- beforeColon: false
@@ -217,9 +225,6 @@ rules:
217225
sort-vars:
218226
- 2
219227
- ignoreCase: true
220-
space-after-keywords:
221-
- 2
222-
- always
223228
space-before-blocks:
224229
- 2
225230
- always
@@ -230,7 +235,6 @@ rules:
230235
- 2
231236
- never
232237
space-infix-ops: 2
233-
space-return-throw-case: 2
234238
space-unary-ops:
235239
- 2
236240
- words: true

README.md

Lines changed: 22 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -90,72 +90,6 @@ Users may use the shareable [eslint-config-angular](https://github.com/dustinspe
9090
```
9191

9292

93-
94-
## Defaults
95-
96-
```json
97-
{
98-
"plugins": [
99-
"angular/angular"
100-
],
101-
"rules": {
102-
"angular/angularelement": 1,
103-
"angular/component-limit": [0, 1],
104-
"angular/controller-as": 2,
105-
"angular/controller-as-route": 2,
106-
"angular/controller-as-vm": [2, "vm"],
107-
"angular/controller-name": [2, "/[A-Z].*Controller$/"],
108-
"angular/deferred": 0,
109-
"angular/definedundefined": 2,
110-
"angular/di": [2, "function"],
111-
"angular/di-order": 0,
112-
"angular/di-unused": 0,
113-
"angular/directive-name": 0,
114-
"angular/directive-restrict": 0,
115-
"angular/document-service": 2,
116-
"angular/dumb-inject": 0,
117-
"angular/empty-controller": 0,
118-
"angular/file-name": 0,
119-
"angular/filter-name": 0,
120-
"angular/foreach": 0,
121-
"angular/function-type": 0,
122-
"angular/interval-service": 2,
123-
"angular/json-functions": 2,
124-
"angular/log": 2,
125-
"angular/module-dependency-order": [0, {"grouped": false, "prefix": null}],
126-
"angular/module-getter": 2,
127-
"angular/module-name": 0,
128-
"angular/module-setter": 2,
129-
"angular/no-angular-mock": 0,
130-
"angular/no-controller": 0,
131-
"angular/no-cookiestore": 2,
132-
"angular/no-digest": 0,
133-
"angular/no-directive-replace": 0,
134-
"angular/no-http-callback": 0,
135-
"angular/no-inline-template": [0, {"allowSimple": true}],
136-
"angular/no-jquery-angularelement": 2,
137-
"angular/no-private-call": 2,
138-
"angular/no-run-logic": 0,
139-
"angular/no-services": [2, ["$http", "$resource", "Restangular", "$q"]],
140-
"angular/no-service-method": 2,
141-
"angular/on-watch": 2,
142-
"angular/one-dependency-per-line": 0,
143-
"angular/rest-service": 0,
144-
"angular/service-name": 0,
145-
"angular/timeout-service": 2,
146-
"angular/typecheck-array": 2,
147-
"angular/typecheck-date": 2,
148-
"angular/typecheck-function": 2,
149-
"angular/typecheck-number": 2,
150-
"angular/typecheck-object": 2,
151-
"angular/typecheck-regexp": 2,
152-
"angular/typecheck-string": 2,
153-
"angular/watchers-execution": [0, "$digest"],
154-
"angular/window-service": 2
155-
}
156-
}
157-
```
158-
15993
----
16094

16195

@@ -164,22 +98,22 @@ Users may use the shareable [eslint-config-angular](https://github.com/dustinspe
16498
Rules in eslint-plugin-angular are divided into several categories to help you better understand their value.
16599

166100

167-
## Possible Errors
101+
### Possible Errors
168102

169103
The following rules detect patterns that can lead to errors.
170104

171105
* [module-getter](docs/module-getter.md) - disallow to reference modules with variables and require to use the getter syntax instead `angular.module('myModule')` ([y022](https://github.com/johnpapa/angular-styleguide#style-y022))
172106
* [module-setter](docs/module-setter.md) - disallow to assign modules to variables (linked to [module-getter](docs/module-getter.md) ([y021](https://github.com/johnpapa/angular-styleguide#style-y021))
173107
* [no-private-call](docs/no-private-call.md) - disallow use of internal angular properties prefixed with $$
174108

175-
## Best Practices
109+
### Best Practices
176110

177111
These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns..
178112

179113
* [component-limit](docs/component-limit.md) - limit the number of angular components per file ([y001](https://github.com/johnpapa/angular-styleguide#style-y001))
180-
* [controller-as](docs/controller-as.md) - disallow assignments to `$scope` in controllers ([y031](https://github.com/johnpapa/angular-styleguide#style-y031))
181114
* [controller-as-route](docs/controller-as-route.md) - require the use of controllerAs in routes or states ([y031](https://github.com/johnpapa/angular-styleguide#style-y031))
182115
* [controller-as-vm](docs/controller-as-vm.md) - require and specify a capture variable for `this` in controllers ([y032](https://github.com/johnpapa/angular-styleguide#style-y032))
116+
* [controller-as](docs/controller-as.md) - disallow assignments to `$scope` in controllers ([y031](https://github.com/johnpapa/angular-styleguide#style-y031))
183117
* [deferred](docs/deferred.md) - use `$q(function(resolve, reject){})` instead of `$q.deferred`
184118
* [di-unused](docs/di-unused.md) - disallow unused DI parameters
185119
* [directive-restrict](docs/directive-restrict.md) - disallow any other directive restrict than 'A' or 'E' ([y074](https://github.com/johnpapa/angular-styleguide#style-y074))
@@ -190,15 +124,15 @@ These are rules designed to prevent you from making mistakes. They either prescr
190124
* [no-services](docs/no-services.md) - disallow DI of specified services for other angular components (`$http` for controllers, filters and directives)
191125
* [on-watch](docs/on-watch.md) - require `$on` and `$watch` deregistration callbacks to be saved in a variable
192126

193-
## Deprecated Angular Features
127+
### Deprecated Angular Features
194128

195129
These rules prevent you from using deprecated angular features.
196130

197131
* [no-cookiestore](docs/no-cookiestore.md) - use `$cookies` instead of `$cookieStore`
198132
* [no-directive-replace](docs/no-directive-replace.md) - disallow the deprecated directive replace property
199133
* [no-http-callback](docs/no-http-callback.md) - disallow the `$http` methods `success()` and `error()`
200134
201-
## Naming
135+
### Naming
202136
203137
These rules help you to specify several naming conventions.
204138
@@ -209,12 +143,12 @@ These rules help you to specify several naming conventions.
209143
* [module-name](docs/module-name.md) - require and specify a prefix for all module names ([y127](https://github.com/johnpapa/angular-styleguide#style-y127))
210144
* [service-name](docs/service-name.md) - require and specify a prefix for all service names ([y125](https://github.com/johnpapa/angular-styleguide#style-y125))
211145
212-
## Conventions
146+
### Conventions
213147
214148
Angular often provide multi ways to to something. These rules help you to define convention for your project.
215149
216-
* [di](docs/di.md) - require a consistent DI syntax
217150
* [di-order](docs/di-order.md) - require DI parameters to be sorted alphabetically
151+
* [di](docs/di.md) - require a consistent DI syntax
218152
* [dumb-inject](docs/dumb-inject.md) - unittest `inject` functions should only consist of assignments from injected values to describe block variables
219153
* [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))
220154
* [module-dependency-order](docs/module-dependency-order.md) - require a consistent order of module dependencies
@@ -223,7 +157,7 @@ Angular often provide multi ways to to something. These rules help you to define
223157
* [rest-service](docs/rest-service.md) - disallow different rest service and specify one of '$http', '$resource', 'Restangular'
224158
* [watchers-execution](docs/watchers-execution.md) - require and specify consistent use `$scope.digest()` or `$scope.apply()`
225159
226-
## Angular Wrappers
160+
### Angular Wrappers
227161
228162
These rules help you to enforce the usage of angular wrappers.
229163
@@ -245,12 +179,18 @@ These rules help you to enforce the usage of angular wrappers.
245179
* [typecheck-string](docs/typecheck-string.md) - use `angular.isString` instead of `typeof` comparisons
246180
* [window-service](docs/window-service.md) - use `$window` instead of `window` ([y180](https://github.com/johnpapa/angular-styleguide#style-y180))
247181
248-
## Deprecated rules
249182
250-
These rules will be removed in version 1.0.0
251183
252-
* [no-digest](docs/no-digest.md) - use `$apply()` instead of `$digest()` (replaced by [watchers-execution](docs/watchers-execution.md))
253-
* [typecheck-regexp](docs/typecheck-regexp.md) - use `angular.isRegexp` instead of other comparisons (no native angular method)
184+
## Environments
185+
186+
This plugin enables the use of environments targeted at AngularJS. These environments define the globals each situation respectively.
187+
188+
```yaml
189+
env:
190+
angular/angular: true
191+
angular/mocks: true
192+
angular/protractor: true
193+
```
254194
255195
256196
----
@@ -357,12 +297,10 @@ return {
357297
358298
Here is the basic configuration for the rules defined in the ESLint plugin, in order to be compatible with the guideline provided by @johnpapa :
359299
360-
```json
361-
{
362-
"rules": {
363-
"no-use-before-define": 0
364-
}
365-
}
300+
```yaml
301+
rules:
302+
no-use-before-define:
303+
- 0
366304
```
367305
368306

docs/component-limit.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
The number of AngularJS components in one file should be limited.
66
The default limit is one.
77

8+
- The acceptable number of components. (Default: 1)
9+
810
**Styleguide Reference**
911

1012
* [y001 by johnpapa - Define 1 component per file](https://github.com/johnpapa/angular-styleguide#style-y001)

docs/controller-as-route.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ The following patterns are considered problems;
1919
controller: 'MyController'
2020
}) // error: Route "/myroute" should use controllerAs syntax
2121

22+
// invalid
23+
$routeProvider.when('/myroute', {
24+
controller: 'MyController as vm',
25+
controllerAs: 'vm'
26+
}) // error: The controllerAs syntax is defined twice for the route "/myroute"
27+
2228
The following patterns are **not** considered problems;
2329

2430
/*eslint angular/controller-as-route: 2*/
@@ -29,6 +35,11 @@ The following patterns are **not** considered problems;
2935
controllerAs: 'vm'
3036
});
3137

38+
// valid
39+
$routeProvider.when('/myroute', {
40+
controller: 'MyController as vm'
41+
});
42+
3243
## Version
3344

3445
This rule was introduced in eslint-plugin-angular 0.1.0

docs/controller-as-vm.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ You should use a capture variable for 'this' when using the controllerAs syntax.
66
The second parameter specifies the capture variable you want to use in your application.
77
The third parameter can be a Regexp for identifying controller functions (when using something like Browserify)
88

9+
- The name that should be used for the view model.
10+
911
**Styleguide Reference**
1012

1113
* [y032 by johnpapa - controllerAs with vm](https://github.com/johnpapa/angular-styleguide#style-y032)

docs/module-dependency-order.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The following patterns are **not** considered problems with default config;
2424
/*eslint angular/module-dependency-order: 2*/
2525

2626
// valid
27-
angular.module('myModule', ['app', 'appFilters', 'ngAnimate', 'ngRoute', 'ui.router']);
27+
angular.module('myModule', ['ngAnimate', 'ngRoute', 'app', 'appFilters', 'ui.router']);
2828

2929
The following patterns are considered problems when configured `{"grouped":true}`:
3030

docs/no-digest.md

Lines changed: 0 additions & 19 deletions
This file was deleted.

docs/typecheck-regexp.md

Lines changed: 0 additions & 16 deletions
This file was deleted.

environments.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
module.exports = {
4+
angular: {
5+
globals: {
6+
angular: true
7+
}
8+
},
9+
// https://docs.angularjs.org/api/ngMock
10+
mocks: {
11+
globals: {
12+
angular: true,
13+
inject: true,
14+
module: true
15+
}
16+
},
17+
// http://www.protractortest.org/#/api
18+
protractor: {
19+
globals: {
20+
element: true,
21+
$: true,
22+
$$: true,
23+
browser: true,
24+
by: true,
25+
protractor: true
26+
}
27+
}
28+
};

examples/controller-as-route.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ $routeProvider.when('/myroute', {
44
controllerAs: 'vm'
55
});
66

7+
// example - valid: true
8+
$routeProvider.when('/myroute', {
9+
controller: 'MyController as vm'
10+
});
11+
712
// example - valid: false, errorMessage: "Route \"/myroute\" should use controllerAs syntax"
813
$routeProvider.when('/myroute', {
914
controller: 'MyController'
1015
})
1116

17+
// example - valid: false, errorMessage: "The controllerAs syntax is defined twice for the route \"/myroute\""
18+
$routeProvider.when('/myroute', {
19+
controller: 'MyController as vm',
20+
controllerAs: 'vm'
21+
})

0 commit comments

Comments
 (0)