Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier pass 3 #8586

Merged
merged 11 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ColumnLimit: 100
ColumnLimit: 120
10 changes: 10 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
build
coverage
node_modules
bin
# Ignore generated files in insomnia
packages/insomnia/src/**.js
packages/insomnia/src/**.js.map
# Ignore fixture files for tests since we need to keep them in a specific format
__fixtures__
fixtures
17 changes: 17 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"trailingComma": "all",
"printWidth": 120,
"arrowParens": "avoid",
"singleQuote": true,
"quoteProps": "consistent",
"overrides": [
{
"files": "packages/insomnia/**/*",
"options": {
"plugins": [
"prettier-plugin-tailwindcss"
]
}
}
]
}
9 changes: 4 additions & 5 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"yzhang.markdown-all-in-one",
"DavidAnson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"adrieankhisbe.vscode-ndjson",
"ms-playwright.playwright",
"bradlc.vscode-tailwindcss"
"bradlc.vscode-tailwindcss",
"esbenp.prettier-vscode",
"llvm-vs-code-extensions.vscode-clangd"
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
"unwantedRecommendations": []
}
12 changes: 6 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[typescriptreact]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"cSpell.words": [
"apikey",
"Dismissable",
Expand All @@ -35,12 +41,6 @@
"upsert",
"xmark"
],
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
"[cpp]": {
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd"
},
Expand Down
112 changes: 106 additions & 6 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
"eslint-plugin-react": "^7.37.4",
"eslint-plugin-react-hooks": "^5.2.0",
"eslint-plugin-simple-import-sort": "^12.1.1",
"prettier": "3.5.3",
"prettier-plugin-tailwindcss": "^0.6.11",
"tslib": "2.0.1",
"type-fest": "^4.15.0",
"typescript": "5.6.2",
Expand Down
9 changes: 3 additions & 6 deletions packages/insomnia-smoke-test/tests/smoke/graphql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ test('can render schema and send GraphQL requests', async ({ app, page }) => {
await page.getByText('GraphQL request with number').click();
await page.getByTestId('Dropdown-GraphQL-request-with-number').click();

await page.getByText('Copy as cURL').click();
const handle = await page.evaluateHandle(() => navigator.clipboard.readText());
const clipboardContent = await handle.jsonValue();
const exepctResult = JSON.stringify({ query: 'query($inputVar:Int){echoNum(intVar:$inputVar)}', variables: { inputVar: 3 } });
// expect exported curl body to be JSON string
expect(clipboardContent.split('--data ')[1]?.replace(/[\n\s\']/g, '')).toContain(exepctResult);
await page.getByRole('menuitemradio', { name: 'Generate Code' }).click();
await page.getByText('"query": "query($inputVar: Int) { echoNum(intVar: $inputVar)}",').click();
await page.getByRole('button', { name: 'Done' }).click();

await page.getByRole('button', { name: 'Send' }).click();

Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"node-forge": "^1.3.1",
"oauth-1.0a": "^2.2.6",
"papaparse": "^5.4.1",
"prettier": "2.4.1",
"shell-quote": "^1.8.1",
"swagger-ui-dist": "^5.17.14",
"tough-cookie": "^4.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type { Request } from '../../../../models/request';
import { fetchRequestData, responseTransform, sendCurlAndWriteTimeline, tryToInterpolateRequest, tryToTransformRequestWithPlugins } from '../../../../network/network';
import { invariant } from '../../../../utils/invariant';
import { jsonPrettify } from '../../../../utils/prettify/json';
import { useRootLoaderData } from '../../../routes/root';
import { Dropdown, DropdownItem, DropdownSection, ItemContent } from '../../base/dropdown';
import { CodeEditor, type CodeEditorHandle } from '../../codemirror/code-editor';
import { GraphQLExplorer } from '../../graph-ql-explorer/graph-ql-explorer';
Expand All @@ -31,6 +30,7 @@ import { HelpTooltip } from '../../help-tooltip';
import { Icon } from '../../icon';
import { useDocBodyKeyboardShortcuts } from '../../keydown-binder';
import { TimeFromNow } from '../../time-from-now';
import { prettifyGraphql } from './prettify-graphql.mjs';

// Type guard to ensure loc is non-nullable
const hasLocation = (def: OperationDefinitionNode): def is OperationDefinitionNode & { loc: NonNullable<OperationDefinitionNode['loc']> } => {
Expand Down Expand Up @@ -279,17 +279,10 @@ export const GraphQLEditor: FC<Props> = ({
isMounted = false;
};
}, [automaticFetch, environmentId, includeInputValueDeprecation, request._id, request.url, workspaceId]);
const {
settings,
} = useRootLoaderData();
const { editorIndentWithTabs, editorIndentSize } = settings;
const beautifyRequestBody = async () => {
const { body } = state;
const prettyQuery = await (await import('prettier')).format(body.query, {
parser: 'graphql',
useTabs: editorIndentWithTabs,
tabWidth: editorIndentSize,
});

const prettyQuery = prettifyGraphql(body.query);
changeQuery(prettyQuery);
// Update editor contents
if (editorRef.current) {
Expand Down
Loading
Loading