Skip to content

Commit e9c1af2

Browse files
authored
Tighten lint rules (#947)
* tighten lint rules * update Ubuntu runner
1 parent f32fab7 commit e9c1af2

20 files changed

+32
-35
lines changed

.eslintrc.cjs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
module.exports = {
22
parser: "@typescript-eslint/parser",
3-
extends: ["plugin:@typescript-eslint/recommended", "prettier"],
4-
plugins: ["@typescript-eslint", "prettier"],
5-
rules: {
6-
"@typescript-eslint/camelcase": "off",
7-
"@typescript-eslint/explicit-module-boundary-types": "off",
8-
"@typescript-eslint/no-explicit-any": "off", // in a foreign schema, sometimes we need “any”
9-
"@typescript-eslint/no-use-before-define": "off",
10-
"@typescript-eslint/no-var-requires": "off",
11-
"prettier/prettier": "error",
12-
"prefer-const": "off",
13-
},
3+
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
4+
plugins: ["@typescript-eslint"],
145
};

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55

66
jobs:
77
lint:
8-
runs-on: ubuntu-latest
8+
runs-on: ubuntu-22.04
99
steps:
1010
- uses: actions/checkout@v3
1111
- uses: pnpm/action-setup@v2
@@ -18,7 +18,7 @@ jobs:
1818
strategy:
1919
matrix:
2020
node-version: [16.x, 18.x]
21-
os: [macos-12, ubuntu-latest, windows-latest]
21+
os: [macos-12, ubuntu-22.04, windows-2022]
2222
runs-on: ${{ matrix.os }}
2323
steps:
2424
- uses: actions/checkout@v3

package.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
"name": "openapi-typescript",
33
"description": "Generate TypeScript types from Swagger OpenAPI specs",
44
"version": "5.4.0",
5-
"engines": {
6-
"node": ">= 14.0.0",
7-
"npm": ">= 7.0.0"
8-
},
95
"author": "[email protected]",
106
"license": "MIT",
117
"bin": {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function openapiTS(
5757

5858
// 1. load schema
5959
let rootSchema: Record<string, any> = {};
60-
let external: Record<string, Record<string, any>> = {};
60+
const external: Record<string, Record<string, any>> = {};
6161
const allSchemas: Record<string, Record<string, any>> = {};
6262
const schemaURL: URL = typeof schema === "string" ? resolveSchema(schema) : (schema as URL);
6363

src/load.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export default async function load(
103103

104104
// if this is dynamically-passed-in JSON, we’ll have to change a few things
105105
const isJSON = schema instanceof URL == false && schema instanceof Readable == false;
106-
let schemaID = isJSON || schema instanceof Readable ? new URL(VIRTUAL_JSON_URL).href : (schema.href as string);
106+
const schemaID = isJSON || schema instanceof Readable ? new URL(VIRTUAL_JSON_URL).href : (schema.href as string);
107107

108108
const schemas = options.schemas;
109109

src/transform/index.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import { transformSchemaObjMap } from "./schema.js";
99

1010
export function transformAll(schema: any, ctx: GlobalContext): Record<string, string> {
1111
const readonly = tsReadonly(ctx.immutableTypes);
12-
13-
let output: Record<string, string> = {};
14-
15-
let operations: Record<string, { operation: OperationObject; pathItem: PathItemObject }> = {};
12+
const output: Record<string, string> = {};
13+
const operations: Record<string, { operation: OperationObject; pathItem: PathItemObject }> = {};
1614

1715
// --raw-schema mode
1816
if (ctx.rawSchema) {

src/transform/parameters.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function transformParametersArray(
1818
let output = "";
1919

2020
// sort into map
21-
let mappedParams: Record<string, Record<string, ParameterObject>> = {};
21+
const mappedParams: Record<string, Record<string, ParameterObject>> = {};
2222
for (const paramObj of parameters as any[]) {
2323
if (paramObj.$ref && globalParameters) {
2424
const paramName = paramObj.$ref.split('["').pop().replace(PARAM_END_RE, ""); // take last segment

src/transform/schema.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface TransformSchemaObjOptions extends GlobalContext {
1818
const EOF_RE = /\n+$/;
1919

2020
function hasDefaultValue(node: any): boolean {
21-
if (node.hasOwnProperty("default")) return true;
21+
if ("default" in node) return true;
2222
// if (node.hasOwnProperty("$ref")) return true; // TODO: resolve remote $refs?
2323
return false;
2424
}
@@ -161,7 +161,7 @@ export function transformSchemaObj(node: any, options: TransformSchemaObjOptions
161161
break;
162162
}
163163

164-
let properties = transformSchemaObjMap(node.properties || {}, {
164+
const properties = transformSchemaObjMap(node.properties || {}, {
165165
...options,
166166
required: new Set(node.required || []),
167167
});

src/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ const COMMENT_RE = /\*\//g;
1717
const LB_RE = /\r?\n/g;
1818
const DOUBLE_QUOTE_RE = /"/g;
1919
const SINGLE_QUOTE_RE = /'/g;
20-
const ESC_0_RE = /\~0/g;
21-
const ESC_1_RE = /\~1/g;
22-
const TILDE_RE = /\~/g;
20+
const ESC_0_RE = /~0/g;
21+
const ESC_1_RE = /~1/g;
22+
const TILDE_RE = /~/g;
2323
const FS_RE = /\//g;
2424

2525
/**
@@ -155,7 +155,7 @@ export function nodeType(obj: any): SchemaObjectType {
155155
}
156156

157157
// Treat any node with allOf/ anyOf/ oneOf as object
158-
if (obj.hasOwnProperty("allOf") || obj.hasOwnProperty("anyOf") || obj.hasOwnProperty("oneOf")) {
158+
if ("allOf" in obj || "anyOf" in obj || "oneOf" in obj) {
159159
return "object";
160160
}
161161

@@ -196,7 +196,7 @@ export function nodeType(obj: any): SchemaObjectType {
196196
}
197197

198198
// object
199-
if (obj.type === "object" || obj.hasOwnProperty("properties") || obj.hasOwnProperty("additionalProperties")) {
199+
if (obj.type === "object" || "properties" in obj || "additionalProperties" in obj) {
200200
return "object";
201201
}
202202

test/core/operation.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect } from "chai";
2+
import { describe, it } from "mocha";
23
import { transformOperationObj } from "../../dist/transform/operation.js";
34

45
const defaults = {

0 commit comments

Comments
 (0)