UNPKG

1.01 kBJavaScriptView Raw
1/**
2 * enforce use of`angular.fromJson` and 'angular.toJson'
3 *
4 * You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify
5 *
6 * @linkDescription use `angular.fromJson` and 'angular.toJson' instead of `JSON.parse` and `JSON.stringify`
7 * @version 0.1.0
8 * @category angularWrapper
9 * @sinceAngularVersion 1.x
10 */
11'use strict';
12
13module.exports = {
14 meta: {
15 schema: []
16 },
17 create: function(context) {
18 return {
19
20 MemberExpression: function(node) {
21 if (node.object.name === 'JSON') {
22 if (node.property.name === 'stringify') {
23 context.report(node, 'You should use the angular.toJson method instead of JSON.stringify', {});
24 } else if (node.property.name === 'parse') {
25 context.report(node, 'You should use the angular.fromJson method instead of JSON.parse', {});
26 }
27 }
28 }
29 };
30 }
31};