-
Notifications
You must be signed in to change notification settings - Fork 131
/
json-functions.js
34 lines (32 loc) · 1.12 KB
/
json-functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* enforce use of`angular.fromJson` and 'angular.toJson'
*
* You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify
*
* @linkDescription use `angular.fromJson` and 'angular.toJson' instead of `JSON.parse` and `JSON.stringify`
* @version 0.1.0
* @category angularWrapper
* @sinceAngularVersion 1.x
*/
'use strict';
module.exports = {
meta: {
docs: {
url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/json-functions.md'
},
schema: []
},
create: function(context) {
return {
MemberExpression: function(node) {
if (node.object.name === 'JSON') {
if (node.property.name === 'stringify') {
context.report(node, 'You should use the angular.toJson method instead of JSON.stringify', {});
} else if (node.property.name === 'parse') {
context.report(node, 'You should use the angular.fromJson method instead of JSON.parse', {});
}
}
}
};
}
};