Skip to content

Latest commit

 

History

History
42 lines (26 loc) · 1.12 KB

json-functions.md

File metadata and controls

42 lines (26 loc) · 1.12 KB

json-functions - enforce use ofangular.fromJson and 'angular.toJson'

You should use angular.fromJson or angular.toJson instead of JSON.parse and JSON.stringify

Rule based on Angular 1.x

Examples

The following patterns are considered problems;

/*eslint angular/json-functions: 2*/

// invalid
JSON.stringify({
    // ...
}); // error: You should use the angular.toJson method instead of JSON.stringify

// invalid
var data = JSON.parse('{"message": "Hello World!"}'); // error: You should use the angular.fromJson method instead of JSON.parse

The following patterns are not considered problems;

/*eslint angular/json-functions: 2*/

// valid
angular.toJson({
    // ...
});

// valid
var data = angular.fromJson('{"message": "Hello World!"}');

Version

This rule was introduced in eslint-plugin-angular 0.1.0

Links