Skip to content

Commit

Permalink
enable promise rules
Browse files Browse the repository at this point in the history
  • Loading branch information
going-confetti committed Dec 18, 2024
1 parent 11514bc commit 3195bcd
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 67 deletions.
12 changes: 10 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ module.exports = {
argsIgnorePattern: '^_',
},
],
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-misused-promises': 'off',
'@typescript-eslint/no-floating-promises': [
'error',
{
ignoreIIFE: true,
},
],
'@typescript-eslint/no-misused-promises': [
'error',
{ checksVoidReturn: false },
],
},

parserOptions: {
Expand Down
3 changes: 1 addition & 2 deletions src/ErrorElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import { css } from '@emotion/react'
import GrotCrashed from '@/assets/grot-crashed.svg'
import { ArrowLeftIcon } from '@radix-ui/react-icons'

const handleCreateIssue = () => {
const handleCreateIssue = () =>
window.studio.browser.openExternalLink(
'https://github.com/grafana/k6-studio/issues'
)
}

const handleOpenLogs = () => {
window.studio.log.openLogFolder()
Expand Down
3 changes: 1 addition & 2 deletions src/components/ExperimentalBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { ExclamationTriangleIcon } from '@radix-ui/react-icons'
import { Flex, Text, Link } from '@radix-ui/themes'

const handleLinkClick = () => {
const handleLinkClick = () =>
window.studio.browser.openExternalLink(
'https://github.com/grafana/k6-studio/issues'
)
}

export function ExperimentalBanner() {
return (
Expand Down
6 changes: 2 additions & 4 deletions src/components/Layout/ActivityBar/HelpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { QuestionMarkCircledIcon } from '@radix-ui/react-icons'
import { DropdownMenu, IconButton, Tooltip } from '@radix-ui/themes'

export function HelpButton() {
const handleOpenDocs = () => {
const handleOpenDocs = () =>
window.studio.browser.openExternalLink(
'https://grafana.com/docs/k6-studio/'
)
}

const handleReportIssue = () => {
const handleReportIssue = () =>
window.studio.browser.openExternalLink(
'https://github.com/grafana/k6-studio/issues'
)
}

const handleOpenApplicationLogs = () => {
window.studio.log.openLogFolder()
Expand Down
5 changes: 2 additions & 3 deletions src/components/Layout/ActivityBar/ProxyStatusIndicator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ export function ProxyStatusIndicator() {
const setProxyStatus = useStudioUIStore((state) => state.setProxyStatus)

useEffect(() => {
async function fetchProxyStatus() {
;(async function fetchProxyStatus() {
const status = await window.studio.proxy.getProxyStatus()
setProxyStatus(status)
}
fetchProxyStatus()
})()

return window.studio.proxy.onProxyStatusChange((status) =>
setProxyStatus(status)
Expand Down
5 changes: 3 additions & 2 deletions src/components/Layout/Sidebar/Sidebar.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ function useFolderContent() {
const setFolderContent = useStudioUIStore((s) => s.setFolderContent)

useEffect(() => {
window.studio.ui.getFiles().then((files) => {
;(async () => {
const files = await window.studio.ui.getFiles()
setFolderContent({
recordings: toFileMap(files.recordings),
generators: toFileMap(files.generators),
scripts: toFileMap(files.scripts),
})
})
})()
}, [setFolderContent])

useEffect(
Expand Down
6 changes: 2 additions & 4 deletions src/components/Settings/LogsSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ export function LogsSettings() {

// retrieve the current content of the log file
useEffect(() => {
async function fetchLogContent() {
;(async function fetchLogContent() {
const content = await window.studio.log.getLogContent()
setLogContent(content)
scrollToLastLine()
}

fetchLogContent()
})()
}, [scrollToLastLine])

// subscribe to log changes
Expand Down
5 changes: 2 additions & 3 deletions src/components/Settings/SettingsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ export const SettingsDialog = ({ open, onOpenChange }: SettingsDialogProps) => {
const [selectedTab, setSelectedTab] = useState('proxy')

useEffect(() => {
async function fetchSettings() {
;(async function fetchSettings() {
const data = await window.studio.settings.getSettings()
setSettings(data)
}
fetchSettings()
})()
}, [])

const formMethods = useForm<AppSettings>({
Expand Down
3 changes: 1 addition & 2 deletions src/components/Settings/UsageReportSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import { AppSettings } from '@/types/settings'
export const UsageReportSettings = () => {
const { control, register } = useFormContext<AppSettings>()

const handleLinkClick = () => {
const handleLinkClick = () =>
window.studio.browser.openExternalLink(
'https://grafana.com/docs/k6-studio/set-up/usage-collection/'
)
}

return (
<SettingsSection>
Expand Down
2 changes: 1 addition & 1 deletion src/components/WebLogView/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export function Group({
useClickAway(headerRef, () => {
if (!group.isEditing) return

handleSubmit(submit)()
return handleSubmit(submit)()
})

const isValidName = (value: string) => {
Expand Down
22 changes: 10 additions & 12 deletions src/components/WebLogView/ResponseDetails/Font.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@ export function Font({ url }: { url: string }) {
const [isReady, setIsReady] = useState(false)
const [name, setName] = useState('')

async function addFontFace(url: string) {
const name = uniqueId('font-')
const font = new FontFace(name, `url(${url})`)

await font.load()
document.fonts.add(font)
setIsReady(true)
setName(name)
}

useEffect(() => {
setIsReady(false)
addFontFace(url)
;(async function addFontFace(url: string) {
setIsReady(false)
const name = uniqueId('font-')
const font = new FontFace(name, `url(${url})`)

await font.load()
document.fonts.add(font)
setIsReady(true)
setName(name)
})(url)
}, [url])

if (!isReady) {
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/useScriptPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export function useScriptPreview() {
}, 100)

// Initial preview generation
// TODO: https://github.com/grafana/k6-studio/issues/277
// eslint-disable-next-line @typescript-eslint/no-floating-promises
updatePreview(useGeneratorStore.getState())

const unsubscribe = useGeneratorStore.subscribe((state) =>
Expand Down
43 changes: 24 additions & 19 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ const createWindow = async () => {

// and load the index.html of the app.
if (MAIN_WINDOW_VITE_DEV_SERVER_URL) {
mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL)
await mainWindow.loadURL(MAIN_WINDOW_VITE_DEV_SERVER_URL)
} else {
mainWindow.loadFile(
await mainWindow.loadFile(
path.join(__dirname, `../renderer/${MAIN_WINDOW_VITE_NAME}/index.html`)
)
}
Expand Down Expand Up @@ -195,16 +195,21 @@ const createWindow = async () => {
return mainWindow
}

app.whenReady().then(async () => {
await initSettings()
appSettings = await getSettings()
nativeTheme.themeSource = appSettings.appearance.theme
app.whenReady().then(
async () => {
await initSettings()
appSettings = await getSettings()
nativeTheme.themeSource = appSettings.appearance.theme

await sendReport(appSettings.usageReport)
await createSplashWindow()
await setupProjectStructure()
await createWindow()
})
await sendReport(appSettings.usageReport)
await createSplashWindow()
await setupProjectStructure()
await createWindow()
},
(error) => {
log.error(error)
}
)

// Quit when all windows are closed, except on macOS. There, it's common
// for applications and their menu bar to stay active until the user quits
Expand All @@ -228,14 +233,14 @@ app.on('before-quit', async () => {
// stop watching files to avoid crash on exit
appShuttingDown = true
await watcher.close()
stopProxyProcess()
return stopProxyProcess()
})

ipcMain.handle('app:change-route', (_, route: string) => {
ipcMain.on('app:change-route', (_, route: string) => {
currentClientRoute = route
})

ipcMain.handle('app:close', (event) => {
ipcMain.on('app:close', (event) => {
console.log('app:close event received')

wasAppClosedByClient = true
Expand Down Expand Up @@ -567,10 +572,10 @@ ipcMain.on('splashscreen:close', (event) => {

ipcMain.handle('browser:open:external:link', (_, url: string) => {
console.info('browser:open:external:link event received')
shell.openExternal(url)
return shell.openExternal(url)
})

ipcMain.handle('log:open', () => {
ipcMain.on('log:open', () => {
console.info('log:open event received')
openLogFolder()
})
Expand All @@ -593,7 +598,7 @@ ipcMain.handle('settings:save', async (event, data: AppSettings) => {
// don't pass fields that are not submitted by the form
const { windowState: _, ...settings } = data
const modifiedSettings = await saveSettings(settings)
applySettings(modifiedSettings, browserWindow)
await applySettings(modifiedSettings, browserWindow)

sendToast(browserWindow.webContents, {
title: 'Settings saved successfully',
Expand Down Expand Up @@ -714,7 +719,7 @@ function showWindow(browserWindow: BrowserWindow) {
browserWindow.focus()
}

function trackWindowState(browserWindow: BrowserWindow) {
async function trackWindowState(browserWindow: BrowserWindow) {
const { width, height, x, y } = browserWindow.getBounds()
const isMaximized = browserWindow.isMaximized()
appSettings.windowState = {
Expand All @@ -725,7 +730,7 @@ function trackWindowState(browserWindow: BrowserWindow) {
isMaximized,
}
try {
saveSettings(appSettings)
await saveSettings(appSettings)
} catch (error) {
log.error(error)
}
Expand Down
6 changes: 3 additions & 3 deletions src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ const app = {
return createListener('app:close', callback)
},
closeApplication: () => {
ipcRenderer.invoke('app:close')
ipcRenderer.send('app:close')
},
changeRoute: (route: string) => {
return ipcRenderer.invoke('app:change-route', route)
return ipcRenderer.send('app:change-route', route)
},
} as const

const log = {
openLogFolder: () => {
ipcRenderer.invoke('log:open')
ipcRenderer.send('log:open')
},
getLogContent: (): Promise<string> => {
return ipcRenderer.invoke('log:read')
Expand Down
2 changes: 1 addition & 1 deletion src/views/Generator/Generator.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function useSaveGeneratorFile(fileName: string) {
return useMutation({
mutationFn: async (generator: GeneratorFileData) => {
await writeGeneratorToFile(fileName, generator)
queryClient.invalidateQueries({ queryKey: ['generator', fileName] })
await queryClient.invalidateQueries({ queryKey: ['generator', fileName] })
},

onSuccess: () => {
Expand Down
6 changes: 1 addition & 5 deletions src/views/Generator/Generator.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,13 @@ export async function generateScriptPreview(
return prettify(script)
}

export function saveScript(script: string, fileName: string) {
window.studio.script.saveScript(script, fileName)
}

export async function exportScript(fileName: string) {
const generator = selectGeneratorData(useGeneratorStore.getState())
const filteredRequests = selectFilteredRequests(useGeneratorStore.getState())

const script = await generateScriptPreview(generator, filteredRequests)

saveScript(script, fileName)
await window.studio.script.saveScript(script, fileName)
}

export const scriptExists = async (fileName: string) => {
Expand Down
2 changes: 2 additions & 0 deletions src/views/Generator/ValidatorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ export function ValidatorDialog({
useEffect(() => {
if (!open) return

// TODO: https://github.com/grafana/k6-studio/issues/277
// eslint-disable-next-line @typescript-eslint/no-floating-promises
handleRunScript()
}, [open, handleRunScript])

Expand Down
4 changes: 2 additions & 2 deletions src/views/Validator/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ export function Validator() {
navigate(getRoutePath('home'))
}

function handleRunScript() {
async function handleRunScript() {
if (!scriptPath) {
return
}

resetProxyData()
resetLogs()
resetChecks()
window.studio.script.runScript(scriptPath, isExternal)
setIsRunning(true)
await window.studio.script.runScript(scriptPath, isExternal)
}

function handleStopScript() {
Expand Down

0 comments on commit 3195bcd

Please sign in to comment.