Skip to content

Commit 5cefe35

Browse files
authored
Update Prettier, linting deps (#1283)
* Update Prettier, linting deps * Update Contributing docs
1 parent e2ffc74 commit 5cefe35

25 files changed

+766
-636
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module.exports = {
99
rules: {
1010
"@typescript-eslint/consistent-indexed-object-style": "off", // sometimes naming keys is more user-friendly
1111
"@typescript-eslint/no-dynamic-delete": "off", // delete is OK
12+
"@typescript-eslint/no-non-null-assertion": "off", // this is better than "as"
1213
"@typescript-eslint/no-unnecessary-condition": "off", // this gives bad advice
1314
"no-console": "error",
1415
"no-unused-vars": "off",
@@ -19,6 +20,7 @@ module.exports = {
1920
rules: {
2021
"@typescript-eslint/ban-ts-comment": "off", // allow @ts-ignore only in tests
2122
"@typescript-eslint/no-empty-function": "off", // don’t enforce this in tests
23+
"@typescript-eslint/no-explicit-any": "off", // tests sometimes need this
2224
"no-only-tests/no-only-tests": "error",
2325
"vitest/valid-title": "off", // doesn’t work?
2426
},

docs/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ See the [README](./README.md) for basic setup.
66

77
## Corrections / small edits
88

9-
Corrections are always welcome! Please go straight to [opening a PR](https://github.com/drwpow/openapi-typescript/pulls) for correcting typos or misinformation language. Small edits are also welcome, which include shortening verbose language or clarifying confusing wording.
9+
Corrections are always welcome! Please go straight to [opening a PR](https://github.com/drwpow/openapi-typescript/pulls) for correcting typos or misinformation. Small grammar edits are also welcome such as shortening verbose language or clarifying confusing statements.
1010

1111
## Styling fixes
1212

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
"devDependencies": {
2323
"@changesets/changelog-github": "^0.4.8",
2424
"@changesets/cli": "^2.26.2",
25-
"@typescript-eslint/eslint-plugin": "^5.61.0",
26-
"@typescript-eslint/parser": "^5.61.0",
25+
"@typescript-eslint/eslint-plugin": "^6.3.0",
26+
"@typescript-eslint/parser": "^6.3.0",
2727
"del-cli": "^5.0.0",
28-
"eslint": "^8.44.0",
29-
"eslint-config-prettier": "^8.8.0",
28+
"eslint": "^8.46.0",
29+
"eslint-config-prettier": "^9.0.0",
3030
"eslint-plugin-no-only-tests": "^3.1.0",
31-
"eslint-plugin-prettier": "^4.2.1",
32-
"eslint-plugin-vitest": "^0.2.6",
31+
"eslint-plugin-prettier": "^5.0.0",
32+
"eslint-plugin-vitest": "^0.2.8",
3333
"npm-run-all": "^4.1.5",
34-
"prettier": "^2.8.8",
34+
"prettier": "^3.0.1",
3535
"typescript": "^5.1.6"
3636
}
3737
}

packages/openapi-fetch/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thanks for being willing to contribute! 🙏
66

77
## Open issues
88

9-
Please check out the [the open issues](https://github.com/drwpow/openapi-fetch/issues). Issues labelled [**Help Wanted**](https://github.com/drwpow/openapi-fetch/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [**Good First Issue**](https://github.com/drwpow/openapi-fetch/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are especially good to help with.
9+
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)are especially good to start with.
1010

1111
Contributing doesn’t have to be in code! Simply answering questions in open issues, or providing workarounds, is just as important a contribution as making pull requests.
1212

@@ -26,7 +26,7 @@ However, if adding a feature or breaking change, please **open an issue first to
2626

2727
Create a new branch for your PR with `git checkout -b your-branch-name`. Add the relevant code as well as docs and tests. When you push everything up (`git push`), navigate back to your repo GitHub and you should see a prompt to open a new PR.
2828

29-
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines like [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs)
29+
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines. Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs))
3030

3131
### Writing the PR
3232

packages/openapi-fetch/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@
5959
},
6060
"devDependencies": {
6161
"del-cli": "^5.0.0",
62-
"esbuild": "^0.18.17",
62+
"esbuild": "^0.19.0",
6363
"nanostores": "^0.9.3",
64-
"openapi-typescript": "*",
65-
"prettier": "^2.8.8",
64+
"openapi-typescript": "^6.4.2",
6665
"typescript": "^5.1.6",
6766
"vitest": "^0.33.0",
6867
"vitest-fetch-mock": "^0.2.2"

packages/openapi-fetch/src/index.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe("client", () => {
318318
new Headers({
319319
...headers, // assert new header got passed
320320
"Content-Type": "application/json", // probably doesn’t need to get tested, but this was simpler than writing lots of code to ignore these
321-
})
321+
}),
322322
);
323323
});
324324

@@ -333,7 +333,7 @@ describe("client", () => {
333333
new Headers({
334334
"Cache-Control": "no-cache",
335335
"Content-Type": "application/json",
336-
})
336+
}),
337337
);
338338
});
339339

@@ -372,7 +372,7 @@ describe("client", () => {
372372
it("multipart/form-data", async () => {
373373
const client = createClient<paths>();
374374
mockFetchOnce({ status: 200, body: "{}" });
375-
const { data } = await client.PUT("/contact", {
375+
await client.PUT("/contact", {
376376
body: {
377377
name: "John Doe",
378378
@@ -445,6 +445,7 @@ describe("client", () => {
445445
const client = createClient<paths>();
446446
mockFetchOnce({ status: 200, body: "{}" });
447447
const { data } = await client.GET("/anyMethod", { parseAs: "blob" });
448+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
448449
expect((data as any).constructor.name).toBe("Blob");
449450
});
450451

@@ -681,7 +682,7 @@ describe("examples", () => {
681682
setTimeout(() => {
682683
token.set(tokenVal); // simulate promise-like token setting
683684
resolve();
684-
}, 0)
685+
}, 0),
685686
);
686687
await client.get().GET("/blogposts/{post_id}", { params: { path: { post_id: "1234" } } });
687688
expect(fetchMocker.mock.calls[1][1].headers.get("authorization")).toBe(`Bearer ${tokenVal}`);
@@ -710,7 +711,7 @@ describe("examples", () => {
710711
setTimeout(() => {
711712
token = tokenVal; // simulate promise-like token setting
712713
resolve();
713-
}, 0)
714+
}, 0),
714715
);
715716
await client.GET("/blogposts/{post_id}", { params: { path: { post_id: "1234" } } });
716717
expect(fetchMocker.mock.calls[1][1].headers.get("authorization")).toBe(`Bearer ${tokenVal}`);

packages/openapi-fetch/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ const DEFAULT_HEADERS = {
44
};
55
const TRAILING_SLASH_RE = /\/*$/;
66

7+
// Note: though "any" is considered bad practice in general, this library relies
8+
// on "any" for type inference only it can give. Same goes for the "{}" type.
9+
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types */
10+
711
/** options for each client instance */
812
interface ClientOptions extends RequestInit {
913
/** set the common root URL for all API requests */

packages/openapi-typescript/CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Thanks for being willing to contribute! 🙏
66

77
## Open issues
88

9-
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Help Wanted**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22) and [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) are especially good to help with.
9+
Please check out the [the open issues](https://github.com/drwpow/openapi-typescript/issues). Issues labelled [**Good First Issue**](https://github.com/drwpow/openapi-typescript/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22)are especially good to start with.
1010

1111
Contributing doesn’t have to be in code! Simply answering questions in open issues, or providing workarounds, is just as important a contribution as making pull requests.
1212

@@ -26,7 +26,7 @@ However, if adding a feature or breaking change, please **open an issue first to
2626

2727
Create a new branch for your PR with `git checkout -b your-branch-name`. Add the relevant code as well as docs and tests. When you push everything up (`git push`), navigate back to your repo GitHub and you should see a prompt to open a new PR.
2828

29-
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines like [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs)
29+
While best practices for commit messages are encouraged (e.g. start with an imperative verb, keep it short, use the body if needed), this repo doesn’t follow any specific guidelines. Clarity is favored over strict rules. Changelogs are generated separately from git (see [the Changelogs section](#changelogs))
3030

3131
When working locally, run:
3232

packages/openapi-typescript/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@
5959
},
6060
"dependencies": {
6161
"ansi-colors": "^4.1.3",
62-
"fast-glob": "^3.3.0",
62+
"fast-glob": "^3.3.1",
6363
"js-yaml": "^4.1.0",
6464
"supports-color": "^9.4.0",
65-
"undici": "^5.22.1",
65+
"undici": "^5.23.0",
6666
"yargs-parser": "^21.1.1"
6767
},
6868
"devDependencies": {
6969
"@types/degit": "^2.8.3",
7070
"@types/js-yaml": "^4.0.5",
71-
"@types/node": "^20.4.0",
71+
"@types/node": "^20.4.9",
7272
"degit": "^2.8.4",
7373
"del-cli": "^5.0.0",
74-
"esbuild": "^0.18.17",
74+
"esbuild": "^0.19.0",
7575
"execa": "^6.1.0",
76-
"vite": "^4.4.1",
76+
"vite": "^4.4.9",
7777
"vite-node": "^0.33.0",
7878
"vitest": "^0.33.0"
7979
}

packages/openapi-typescript/src/index.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { GlobalContext, OpenAPI3, OpenAPITSOptions, Subschema } from "./types.js";
1+
import type { GlobalContext, OpenAPI3, OpenAPITSOptions, SchemaObject, Subschema } from "./types.js";
22
import type { Readable } from "node:stream";
33
import { URL } from "node:url";
44
import load, { resolveSchema, VIRTUAL_JSON_URL } from "./load.js";
@@ -75,6 +75,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
7575
// 1. basic validation
7676
for (const k of Object.keys(allSchemas)) {
7777
const subschema = allSchemas[k];
78+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
7879
if (typeof (subschema.schema as any).swagger === "string") {
7980
error("Swagger 2.0 and older no longer supported. Please use v5.");
8081
process.exit(1);
@@ -156,7 +157,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
156157
// hack: sometimes subschemas contain only a single SchemaObject or ParameterObject and get incorrectly hinted
157158
// currently unknown what the real fix is, but this is a bandaid
158159
if (typeof subschema.schema === "object" && ("schema" in subschema.schema || "type" in subschema.schema)) {
159-
subschemaOutput = transformSchemaObject(subschema.schema as any, { path, ctx: { ...ctx, indentLv } });
160+
subschemaOutput = transformSchemaObject(subschema.schema as SchemaObject, { path, ctx: { ...ctx, indentLv } });
160161
} else {
161162
subschemaOutput += "{\n";
162163
indentLv++;
@@ -181,14 +182,14 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
181182

182183
outer: for (const [name, schemaObject] of getEntries(subschema.schema!)) {
183184
if (!schemaObject || typeof schemaObject !== "object") continue;
184-
const c = getSchemaObjectComment(schemaObject as any, indentLv);
185+
const c = getSchemaObjectComment(schemaObject as SchemaObject, indentLv);
185186
if (c) subschemaOutput += indent(c, indentLv);
186187

187188
// This might be a Path Item Object; only way to test is if top-level contains a method (not allowed on Schema Object)
188189
if (!("type" in schemaObject) && !("$ref" in schemaObject)) {
189190
for (const method of ["get", "put", "post", "delete", "options", "head", "patch", "trace"] as Method[]) {
190191
if (method in schemaObject) {
191-
subschemaOutput += indent(`${escObjKey(name)}: ${transformPathItemObject(schemaObject as any, { path: `${path}${name}`, ctx: { ...ctx, indentLv } })};\n`, indentLv);
192+
subschemaOutput += indent(`${escObjKey(name)}: ${transformPathItemObject(schemaObject, { path: `${path}${name}`, ctx: { ...ctx, indentLv } })};\n`, indentLv);
192193
continue outer;
193194
}
194195
}
@@ -207,7 +208,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
207208
break;
208209
}
209210
default: {
210-
error(`Could not resolve subschema ${subschemaID}. Unknown type "${(subschema as any).hint}".`);
211+
error(`Could not resolve subschema ${subschemaID}. Unknown type "${subschema.hint}".`);
211212
process.exit(1);
212213
}
213214
}
@@ -244,7 +245,7 @@ async function openapiTS(schema: string | URL | OpenAPI3 | Readable, options: Op
244245
"type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };",
245246
"type XOR<T, U> = (T | U) extends object ? (Without<T, U> & U) | (Without<U, T> & T) : T | U;",
246247
"type OneOf<T extends any[]> = T extends [infer Only] ? Only : T extends [infer A, infer B, ...infer Rest] ? OneOf<[XOR<A, B>, ...Rest]> : never;",
247-
""
248+
"",
248249
);
249250
}
250251

0 commit comments

Comments
 (0)