n8n/packages/@n8n_io/eslint-config/local-rules.test.js
Mike Arvela 31391a5b19
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 <[email protected]>
2022-09-26 11:08:59 +03:00

24 lines
447 B
JavaScript

'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' }],
},
],
});