mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 21:19:43 -08:00
6a1838d8c1
* 👕 Create rule `no-json-parse-json-stringify` * 🧪 Add tests * 👕 Enable new rule * 👕 FIx unrelated lint issue
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
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' }],
|
|
},
|
|
],
|
|
});
|
|
|
|
ruleTester.run('no-json-parse-json-stringify', rules['no-json-parse-json-stringify'], {
|
|
valid: [
|
|
{
|
|
code: 'deepCopy(foo)',
|
|
},
|
|
],
|
|
invalid: [
|
|
{
|
|
code: 'JSON.parse(JSON.stringify(foo))',
|
|
errors: [{ messageId: 'noJsonParseJsonStringify' }],
|
|
output: 'deepCopy(foo)',
|
|
},
|
|
{
|
|
code: 'JSON.parse(JSON.stringify(foo.bar))',
|
|
errors: [{ messageId: 'noJsonParseJsonStringify' }],
|
|
output: 'deepCopy(foo.bar)',
|
|
},
|
|
{
|
|
code: 'JSON.parse(JSON.stringify(foo.bar.baz))',
|
|
errors: [{ messageId: 'noJsonParseJsonStringify' }],
|
|
output: 'deepCopy(foo.bar.baz)',
|
|
},
|
|
{
|
|
code: 'JSON.parse(JSON.stringify(foo.bar[baz]))',
|
|
errors: [{ messageId: 'noJsonParseJsonStringify' }],
|
|
output: 'deepCopy(foo.bar[baz])',
|
|
},
|
|
],
|
|
});
|