all files / eslint-plugin-angular/rules/ json-functions.js

100% Statements 8/8
83.33% Branches 5/6
100% Functions 2/2
100% Lines 8/8
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                      19×     17×                  
/**
 * 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
 */
'use strict';
 
module.exports = 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 Eif (node.property.name === 'parse') {
                    context.report(node, 'You should use the angular.fromJson method instead of JSON.parse', {});
                }
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];