From e9a79a32da520ba1cec36cf4faa81de4c3cde5c0 Mon Sep 17 00:00:00 2001 From: lohit Date: Thu, 8 May 2025 18:12:16 +0530 Subject: [PATCH] lint error fixes (#4623) Co-authored-by: lohit --- .../Auth/OAuth2/Oauth2TokenViewer/index.js | 2 +- .../Collection/CollectionItem/index.js | 2 +- .../ReduxStore/slices/collections/actions.js | 24 +++++++++++++++---- .../ReduxStore/slices/global-environments.js | 9 ++++++- .../src/utils/codemirror/javascript-lint.js | 2 ++ packages/bruno-app/src/utils/common/cache.js | 10 -------- packages/bruno-app/src/utils/common/index.js | 2 +- 7 files changed, 32 insertions(+), 19 deletions(-) delete mode 100644 packages/bruno-app/src/utils/common/cache.js diff --git a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2TokenViewer/index.js b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2TokenViewer/index.js index 9439a0bea..7692b5891 100644 --- a/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2TokenViewer/index.js +++ b/packages/bruno-app/src/components/RequestPane/Auth/OAuth2/Oauth2TokenViewer/index.js @@ -1,6 +1,6 @@ +import { useState, useEffect, useMemo } from "react"; import { find } from "lodash"; import StyledWrapper from "./StyledWrapper"; -import { useState, useEffect } from "react"; import { IconChevronDown, IconChevronRight, IconCopy, IconCheck } from '@tabler/icons'; import { getAllVariables } from 'utils/collections/index'; import { interpolate } from '@usebruno/common'; diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index 232d35e7a..6c34dcaa3 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -278,7 +278,7 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText }) const viewFolderSettings = () => { if (isItemAFolder(item)) { - if (itemIsOpenedInTabs(item, tabs)) { + if (isTabForItemPresent) { dispatch(focusTab({ uid: item.uid })); return; } diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js index 8c1878342..6aa890d8b 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/actions.js @@ -56,7 +56,7 @@ export const renameCollection = (newName, collectionUid) => (dispatch, getState) if (!collection) { return reject(new Error('Collection not found')); } - + const { ipcRenderer } = window; ipcRenderer.invoke('renderer:rename-collection', newName, collection.pathname).then(resolve).catch(reject); }); }; @@ -333,6 +333,7 @@ export const runCollectionFolder = (collectionUid, folderUid, recursive, delay) }) ); + const { ipcRenderer } = window; ipcRenderer .invoke( 'renderer:run-collection-folder', @@ -531,6 +532,8 @@ export const cloneItem = (newName, newFilename, itemUid, collectionUid) => (disp set(item, 'root.meta.seq', parentFolder?.items?.length + 1); const collectionPath = path.join(parentFolder.pathname, newFilename); + + const { ipcRenderer } = window; ipcRenderer.invoke('renderer:clone-folder', item, collectionPath).then(resolve).catch(reject); return; } @@ -857,6 +860,7 @@ export const addEnvironment = (name, collectionUid) => (dispatch, getState) => { return reject(new Error('Collection not found')); } + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:create-environment', collection.pathname, name) .then( @@ -885,6 +889,7 @@ export const importEnvironment = (name, variables, collectionUid) => (dispatch, const sanitizedName = sanitizeName(name); + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:create-environment', collection.pathname, sanitizedName, variables) .then( @@ -918,6 +923,7 @@ export const copyEnvironment = (name, baseEnvUid, collectionUid) => (dispatch, g const sanitizedName = sanitizeName(name); + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:create-environment', collection.pathname, sanitizedName, baseEnv.variables) .then( @@ -954,6 +960,7 @@ export const renameEnvironment = (newName, environmentUid, collectionUid) => (di const oldName = environment.name; environment.name = sanitizedName; + const { ipcRenderer } = window; environmentSchema .validate(environment) .then(() => ipcRenderer.invoke('renderer:rename-environment', collection.pathname, oldName, sanitizedName)) @@ -977,6 +984,7 @@ export const deleteEnvironment = (environmentUid, collectionUid) => (dispatch, g return reject(new Error('Environment not found')); } + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:delete-environment', collection.pathname, environment.name) .then(resolve) @@ -1000,6 +1008,7 @@ export const saveEnvironment = (variables, environmentUid, collectionUid) => (di environment.variables = variables; + const { ipcRenderer } = window; environmentSchema .validate(environment) .then(() => ipcRenderer.invoke('renderer:save-environment', collection.pathname, environment)) @@ -1025,7 +1034,8 @@ export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, g if (environmentUid && !environmentName) { return reject(new Error('Environment not found')); } - + + const { ipcRenderer } = window; ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName }}); dispatch(_selectEnvironment({ environmentUid, collectionUid })); @@ -1084,11 +1094,13 @@ export const updateBrunoConfig = (brunoConfig, collectionUid) => (dispatch, getS const state = getState(); const collection = findCollectionByUid(state.collections.collections, collectionUid); - if (!collection) { - return reject(new Error('Collection not found')); - } return new Promise((resolve, reject) => { + if (!collection) { + return reject(new Error('Collection not found')); + } + + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:update-bruno-config', brunoConfig, collection.pathname, collectionUid) .then(resolve) @@ -1107,6 +1119,8 @@ export const openCollectionEvent = (uid, pathname, brunoConfig) => (dispatch, ge brunoConfig: brunoConfig }; + const { ipcRenderer } = window; + return new Promise((resolve, reject) => { ipcRenderer.invoke('renderer:get-collection-security-config', pathname).then((securityConfig) => { collectionSchema diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js index def88f2b6..b208f14fd 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/global-environments.js @@ -1,5 +1,5 @@ import { createSlice } from '@reduxjs/toolkit'; -import { stringifyIfNot, uuid } from 'utils/common/index'; +import { uuid } from 'utils/common/index'; import { environmentSchema } from '@usebruno/schema'; import { cloneDeep } from 'lodash'; @@ -90,6 +90,7 @@ export const { export const addGlobalEnvironment = ({ name, variables = [] }) => (dispatch, getState) => { return new Promise((resolve, reject) => { const uid = uuid(); + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:create-global-environment', { name, uid, variables }) .then(() => dispatch(_addGlobalEnvironment({ name, uid, variables }))) @@ -104,6 +105,7 @@ export const copyGlobalEnvironment = ({ name, environmentUid: baseEnvUid }) => ( const globalEnvironments = state.globalEnvironments.globalEnvironments; const baseEnv = globalEnvironments?.find(env => env?.uid == baseEnvUid) const uid = uuid(); + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:create-global-environment', { uid, name, variables: baseEnv.variables }) .then(() => dispatch(_copyGlobalEnvironment({ name, uid, variables: baseEnv.variables }))) @@ -114,6 +116,7 @@ export const copyGlobalEnvironment = ({ name, environmentUid: baseEnvUid }) => ( export const renameGlobalEnvironment = ({ name: newName, environmentUid }) => (dispatch, getState) => { return new Promise((resolve, reject) => { + const { ipcRenderer } = window; const state = getState(); const globalEnvironments = state.globalEnvironments.globalEnvironments; const environment = globalEnvironments?.find(env => env?.uid == environmentUid) @@ -139,6 +142,7 @@ export const saveGlobalEnvironment = ({ variables, environmentUid }) => (dispatc return reject(new Error('Environment not found')); } + const { ipcRenderer } = window; environmentSchema .validate(environment) .then(() => ipcRenderer.invoke('renderer:save-global-environment', { @@ -155,6 +159,7 @@ export const saveGlobalEnvironment = ({ variables, environmentUid }) => (dispatc export const selectGlobalEnvironment = ({ environmentUid }) => (dispatch, getState) => { return new Promise((resolve, reject) => { + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:select-global-environment', { environmentUid }) .then(() => dispatch(_selectGlobalEnvironment({ environmentUid }))) @@ -165,6 +170,7 @@ export const selectGlobalEnvironment = ({ environmentUid }) => (dispatch, getSta export const deleteGlobalEnvironment = ({ environmentUid }) => (dispatch, getState) => { return new Promise((resolve, reject) => { + const { ipcRenderer } = window; ipcRenderer .invoke('renderer:delete-global-environment', { environmentUid }) .then(() => dispatch(_deleteGlobalEnvironment({ environmentUid }))) @@ -175,6 +181,7 @@ export const deleteGlobalEnvironment = ({ environmentUid }) => (dispatch, getSta export const globalEnvironmentsUpdateEvent = ({ globalEnvironmentVariables }) => (dispatch, getState) => { return new Promise((resolve, reject) => { + const { ipcRenderer } = window; if (!globalEnvironmentVariables) resolve(); const state = getState(); diff --git a/packages/bruno-app/src/utils/codemirror/javascript-lint.js b/packages/bruno-app/src/utils/codemirror/javascript-lint.js index 88829322e..0038406aa 100644 --- a/packages/bruno-app/src/utils/codemirror/javascript-lint.js +++ b/packages/bruno-app/src/utils/codemirror/javascript-lint.js @@ -5,6 +5,8 @@ * Copyright (C) 2017 by Marijn Haverbeke and others */ +import { JSHINT } from 'jshint'; + let CodeMirror; const SERVER_RENDERED = typeof window === 'undefined' || global['PREVENT_CODEMIRROR_RENDER'] === true; diff --git a/packages/bruno-app/src/utils/common/cache.js b/packages/bruno-app/src/utils/common/cache.js deleted file mode 100644 index d8cee9e50..000000000 --- a/packages/bruno-app/src/utils/common/cache.js +++ /dev/null @@ -1,10 +0,0 @@ -class Cache { - get(key) { - return window.localStorage.getItem(key); - } - set(key, val) { - window.localStorage.setItem(key, val); - } -} - -module.exports = new Cache(); diff --git a/packages/bruno-app/src/utils/common/index.js b/packages/bruno-app/src/utils/common/index.js index 8bafbb8f9..47055cbb7 100644 --- a/packages/bruno-app/src/utils/common/index.js +++ b/packages/bruno-app/src/utils/common/index.js @@ -53,7 +53,7 @@ export const safeStringifyJSON = (obj, indent = false) => { export const convertToCodeMirrorJson = (obj) => { try { - return JSON5.stringify(obj).slice(1, -1); + return JSON.stringify(obj, null, 2).slice(1, -1); } catch (e) { return obj; }