From fc6ba4641a794ee820f9520b5713dff0d0dd0f33 Mon Sep 17 00:00:00 2001 From: n00o Date: Sat, 25 Nov 2023 23:21:17 -0500 Subject: [PATCH] Add Ability to ignore comments in JSON body Replace comments with spaces for the JSON linter. --- package-lock.json | 22 ++++++++++++++++-- packages/bruno-app/package.json | 1 + .../src/components/CodeEditor/index.js | 23 +++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7fdfd83c4..fc2d827f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17493,6 +17493,7 @@ "react-redux": "^7.2.6", "react-tooltip": "^5.5.2", "sass": "^1.46.0", + "strip-json-comments": "^5.0.1", "styled-components": "^5.3.3", "system": "^2.0.1", "tailwindcss": "^2.2.19", @@ -17618,6 +17619,17 @@ "node": ">=6" } }, + "packages/bruno-app/node_modules/strip-json-comments": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.1.tgz", + "integrity": "sha512-0fk9zBqO67Nq5M/m45qHCJxylV/DhBlIOVExqgOMiCCrzrhU6tCibRXNqE3jwJLftzE9SNuZtYbpzcO+i9FiKw==", + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "packages/bruno-cli": { "name": "@usebruno/cli", "version": "1.1.1", @@ -17712,7 +17724,7 @@ }, "packages/bruno-electron": { "name": "bruno", - "version": "v1.1.1", + "version": "v1.2.0", "dependencies": { "@aws-sdk/credential-providers": "^3.425.0", "@usebruno/js": "0.9.2", @@ -21767,6 +21779,7 @@ "react-redux": "^7.2.6", "react-tooltip": "^5.5.2", "sass": "^1.46.0", + "strip-json-comments": "^5.0.1", "style-loader": "^3.3.1", "styled-components": "^5.3.3", "system": "^2.0.1", @@ -21840,6 +21853,11 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/split-on-first/-/split-on-first-1.1.0.tgz", "integrity": "sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==" + }, + "strip-json-comments": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-5.0.1.tgz", + "integrity": "sha512-0fk9zBqO67Nq5M/m45qHCJxylV/DhBlIOVExqgOMiCCrzrhU6tCibRXNqE3jwJLftzE9SNuZtYbpzcO+i9FiKw==" } } }, @@ -22851,7 +22869,7 @@ "node-machine-id": "^1.1.12", "qs": "^6.11.0", "socks-proxy-agent": "^8.0.2", - "tough-cookie": "*", + "tough-cookie": "^4.1.3", "uuid": "^9.0.0", "vm2": "^3.9.13", "yup": "^0.32.11" diff --git a/packages/bruno-app/package.json b/packages/bruno-app/package.json index ed697c3c6..de53b1ef7 100644 --- a/packages/bruno-app/package.json +++ b/packages/bruno-app/package.json @@ -64,6 +64,7 @@ "react-redux": "^7.2.6", "react-tooltip": "^5.5.2", "sass": "^1.46.0", + "strip-json-comments": "^5.0.1", "styled-components": "^5.3.3", "system": "^2.0.1", "tailwindcss": "^2.2.19", diff --git a/packages/bruno-app/src/components/CodeEditor/index.js b/packages/bruno-app/src/components/CodeEditor/index.js index 565e3ec8f..53c47ce5a 100644 --- a/packages/bruno-app/src/components/CodeEditor/index.js +++ b/packages/bruno-app/src/components/CodeEditor/index.js @@ -12,6 +12,7 @@ import { defineCodeMirrorBrunoVariablesMode } from 'utils/common/codemirror'; import StyledWrapper from './StyledWrapper'; import jsonlint from 'jsonlint'; import { JSHINT } from 'jshint'; +import stripJsonComments from 'strip-json-comments'; let CodeMirror; const SERVER_RENDERED = typeof navigator === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true; @@ -183,6 +184,28 @@ export default class CodeEditor extends React.Component { } } })); + CodeMirror.registerHelper('lint', 'json', function (text) { + let found = []; + if (!window.jsonlint) { + if (window.console) { + window.console.error('Error: window.jsonlint not defined, CodeMirror JSON linting cannot run.'); + } + return found; + } + let jsonlint = window.jsonlint.parser || window.jsonlint; + jsonlint.parseError = function (str, hash) { + let loc = hash.loc; + found.push({ + from: CodeMirror.Pos(loc.first_line - 1, loc.first_column), + to: CodeMirror.Pos(loc.last_line - 1, loc.last_column), + message: str + }); + }; + try { + jsonlint.parse(stripJsonComments(text)); + } catch (e) { } + return found; + }); if (editor) { editor.setOption('lint', this.props.mode && editor.getValue().trim().length > 0 ? { esversion: 11 } : false); editor.on('change', this._onEdit);