Skip to content

Commit

Permalink
Add eslint rule no-restricted-syntax (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
toasted-nutbread authored Dec 29, 2023
1 parent 59961b6 commit 42c3b0d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 2 additions & 0 deletions ext/js/core/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @returns {T}
*/
export function parseJson(value) {
// eslint-disable-next-line no-restricted-syntax
return JSON.parse(value);
}

Expand All @@ -36,5 +37,6 @@ export function parseJson(value) {
* @returns {Promise<T>}
*/
export async function readResponseJson(response) {
// eslint-disable-next-line no-restricted-syntax
return await response.json();
}

0 comments on commit 42c3b0d

Please sign in to comment.