feat(eslint-config): add custom eslint rule 'no-uncaught-json-parse' (#4087)

feat(eslint-config): add custom eslint rule 'no-uncaugh-json-parse'

Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
This commit is contained in:
Mike Arvela
2022-09-26 11:08:59 +03:00
committed by GitHub
parent 7aa40bf95d
commit 31391a5b19
5 changed files with 2753 additions and 5 deletions

View File

@@ -0,0 +1,23 @@
'use strict';
const rules = require('./local-rules'),
RuleTester = require('eslint').RuleTester;
const ruleTester = new RuleTester();
ruleTester.run('no-uncaught-json-parse', rules['no-uncaught-json-parse'], {
valid: [
{
code: 'try { JSON.parse(foo) } catch (e) {}',
},
{
code: 'JSON.parse(JSON.stringify(foo))',
},
],
invalid: [
{
code: 'JSON.parse(foo)',
errors: [{ messageId: 'noUncaughtJsonParse' }],
},
],
});