eslint-plugin-angular
Version:
ESLint rules for AngularJS projects
33 lines (28 loc) • 1.46 kB
JavaScript
'use strict';
// ------------------------------------------------------------------------------
// Requirements
// ------------------------------------------------------------------------------
var rule = require('../rules/json-functions');
var RuleTester = require('eslint').RuleTester;
var commonFalsePositives = require('./utils/commonFalsePositives');
// ------------------------------------------------------------------------------
// Tests
// ------------------------------------------------------------------------------
var eslintTester = new RuleTester();
eslintTester.run('json-functions', rule, {
valid: [
'angular.toJson({})',
'angular.toJson({}, true)',
'angular.toJson({}, 2)',
'angular.toJson([])',
'angular.toJson([], true)',
'angular.toJson([], 2)',
'angular.fromJson("{}")'
].concat(commonFalsePositives),
invalid: [
{code: 'JSON.parse("{}")', errors: [{message: 'You should use the angular.fromJson method instead of JSON.parse'}]},
{code: 'JSON.stringify({})', errors: [{message: 'You should use the angular.toJson method instead of JSON.stringify'}]},
{code: 'JSON.stringify({}, function() {})', errors: [{message: 'You should use the angular.toJson method instead of JSON.stringify'}]},
{code: 'JSON.stringify({}, function() {}, 2)', errors: [{message: 'You should use the angular.toJson method instead of JSON.stringify'}]}
]
});