From 44743f584c285c34549453b6a32225516ab664ae Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Thu, 28 Dec 2023 23:28:14 -0500 Subject: [PATCH] Add eslint rule no-restricted-syntax --- .eslintrc.json | 11 +++++++++++ ext/js/core/json.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/.eslintrc.json b/.eslintrc.json index 3ea5d555a2..9a0402edb6 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -200,6 +200,17 @@ ], "no-implicit-globals": "error", "no-multi-spaces": "error", + "no-restricted-syntax": [ + "error", + { + "message": "Avoid using JSON.parse(), prefer parseJson.", + "selector": "MemberExpression[object.name=JSON][property.name=parse]" + }, + { + "message": "Avoid using Response.json(), prefer readResponseJson.", + "selector": "MemberExpression[property.name=json]" + } + ], "no-trailing-spaces": "error", "no-whitespace-before-property": "error", "object-curly-spacing": [ diff --git a/ext/js/core/json.js b/ext/js/core/json.js index a031f84e70..0ebe28879f 100644 --- a/ext/js/core/json.js +++ b/ext/js/core/json.js @@ -25,6 +25,7 @@ * @returns {T} */ export function parseJson(value) { + // eslint-disable-next-line no-restricted-syntax return JSON.parse(value); } @@ -36,5 +37,6 @@ export function parseJson(value) { * @returns {Promise} */ export async function readResponseJson(response) { + // eslint-disable-next-line no-restricted-syntax return await response.json(); }