Skip to content

Commit

Permalink
perf: spec lint
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed May 6, 2024
1 parent c62decc commit 355304c
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 261 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@
"@seald-io/nedb": "^4.0.4",
"@segment/analytics-node": "2.1.0",
"@sentry/electron": "^3.0.7",
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-formats": "^1.6.0",
"@stoplight/spectral-ruleset-bundler": "1.5.2",
"@stoplight/spectral-rulesets": "^1.18.1",
"apiconnect-wsdl": "1.8.31",
"aws4": "^1.12.0",
"axios": "^1.6.8",
Expand Down Expand Up @@ -89,6 +85,10 @@
"yaml-source-map": "^2.1.1"
},
"devDependencies": {
"@stoplight/spectral-ruleset-bundler": "1.5.2",
"@stoplight/spectral-core": "^1.18.3",
"@stoplight/spectral-formats": "^1.6.0",
"@stoplight/spectral-rulesets": "^1.18.1",
"@develohpanda/fluent-builder": "^2.1.2",
"@fortawesome/fontawesome-svg-core": "^6.5.2",
"@fortawesome/free-brands-svg-icons": "^6.5.2",
Expand Down
36 changes: 0 additions & 36 deletions packages/insomnia/src/main/ipc/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import type { ISpectralDiagnostic } from '@stoplight/spectral-core';
import type { RulesetDefinition } from '@stoplight/spectral-core';
import { Spectral } from '@stoplight/spectral-core';
// @ts-expect-error - This is a bundled file not sure why it's not found
import { bundleAndLoadRuleset } from '@stoplight/spectral-ruleset-bundler/with-loader';
import { oas } from '@stoplight/spectral-rulesets';
import { app, BrowserWindow, ipcMain, IpcRendererEvent, shell } from 'electron';
import fs from 'fs';

Expand All @@ -28,7 +22,6 @@ export interface RendererToMainBridgeAPI {
manualUpdateCheck: () => void;
backup: () => Promise<void>;
restoreBackup: (version: string) => Promise<void>;
spectralRun: (options: { contents: string; rulesetPath: string }) => Promise<ISpectralDiagnostic[]>;
authorizeUserInWindow: typeof authorizeUserInWindow;
setMenuBarVisibility: (visible: boolean) => void;
installPlugin: typeof installPlugin;
Expand Down Expand Up @@ -117,33 +110,4 @@ export function registerMainHandlers() {
shell.openExternal(href);
}
});

ipcMain.handle('spectralRun', async (_, { contents, rulesetPath }: {
contents: string;
rulesetPath?: string;
}) => {
const spectral = new Spectral();

if (rulesetPath) {
try {
const ruleset = await bundleAndLoadRuleset(rulesetPath, {
fs,
fetch: (url: string) => {
return axiosRequest({ url, method: 'GET' });
},
});

spectral.setRuleset(ruleset);
} catch (err) {
console.log('Error while parsing ruleset:', err);
spectral.setRuleset(oas as RulesetDefinition);
}
} else {
spectral.setRuleset(oas as RulesetDefinition);
}

const diagnostics = await spectral.run(contents);

return diagnostics;
});
}
1 change: 1 addition & 0 deletions packages/insomnia/src/main/window-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export function createWindow(): ElectronBrowserWindow {
preload: path.join(__dirname, 'preload.js'),
zoomFactor: getZoomFactor(),
nodeIntegration: true,
nodeIntegrationInWorker: true,
webviewTag: true,
// TODO: enable context isolation
contextIsolation: false,
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const main: Window['main'] = {
backup: () => ipcRenderer.invoke('backup'),
restoreBackup: options => ipcRenderer.invoke('restoreBackup', options),
authorizeUserInWindow: options => ipcRenderer.invoke('authorizeUserInWindow', options),
spectralRun: options => ipcRenderer.invoke('spectralRun', options),
setMenuBarVisibility: options => ipcRenderer.send('setMenuBarVisibility', options),
installPlugin: options => ipcRenderer.invoke('installPlugin', options),
curlRequest: options => ipcRenderer.invoke('curlRequest', options),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GraphQLInfoOptions } from 'codemirror-graphql/info';
import { ModifiedGraphQLJumpOptions } from 'codemirror-graphql/jump';
import deepEqual from 'deep-equal';
import { JSONPath } from 'jsonpath-plus';
import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import React, { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
import { Button, Menu, MenuItem, MenuTrigger, Popover } from 'react-aria-components';
import { useMount, useUnmount } from 'react-use';
import vkBeautify from 'vkbeautify';
Expand Down Expand Up @@ -137,8 +137,9 @@ export interface CodeEditorHandle {
focusEnd: () => void;
getCursor: () => CodeMirror.Position | undefined;
setCursorLine: (lineNumber: number) => void;
tryToSetOption: (key: keyof EditorConfiguration, value: any) => void;
}
export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
export const CodeEditor = memo(forwardRef<CodeEditorHandle, CodeEditorProps>(({
autoPrettify,
className,
defaultValue,
Expand Down Expand Up @@ -526,6 +527,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
useEffect(() => tryToSetOption('hintOptions', hintOptions), [hintOptions]);
useEffect(() => tryToSetOption('info', infoOptions), [infoOptions]);
useEffect(() => tryToSetOption('jump', jumpOptions), [jumpOptions]);
// This line will trigger codeMirror lint
useEffect(() => tryToSetOption('lint', lintOptions), [lintOptions]);
useEffect(() => tryToSetOption('mode', !handleRender ? normalizeMimeType(mode) : { name: 'nunjucks', baseMode: normalizeMimeType(mode) }), [handleRender, mode]);

Expand All @@ -551,6 +553,7 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
setCursorLine: (lineNumber: number) => {
codeMirror.current?.setCursor(lineNumber);
},
tryToSetOption,
}), []);

const showFilter = readOnly && (mode?.includes('json') || mode?.includes('xml'));
Expand Down Expand Up @@ -715,5 +718,5 @@ export const CodeEditor = forwardRef<CodeEditorHandle, CodeEditorProps>(({
}
</div >
);
});
}));
CodeEditor.displayName = 'CodeEditor';
Loading

0 comments on commit 355304c

Please sign in to comment.