Skip to content

Commit 05e63ea

Browse files
authored
Merge pull request #785 from acacode/fix-lint
Fix biome errors (round 2)
2 parents a7f2d84 + a6e8c84 commit 05e63ea

File tree

7 files changed

+14
-28
lines changed

7 files changed

+14
-28
lines changed

src/code-formatter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CodeFormatter {
2323
{ newLineCharacter: ts.sys.newLine },
2424
)[0];
2525

26-
if (fileTextChanges && fileTextChanges.textChanges.length) {
26+
if (fileTextChanges?.textChanges.length) {
2727
return _.reduceRight(
2828
fileTextChanges.textChanges,
2929
(content, { span, newText }) =>

src/code-gen-process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ class CodeGenProcess {
533533

534534
createApiConfig = (swaggerSchema) => {
535535
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
536-
const server = (servers && servers[0]) || { url: "" };
536+
const server = servers?.[0] || { url: "" };
537537
const { title = "No title", version } = info || {};
538538
const { url: serverUrl } = server;
539539

src/schema-parser/base-schema-parsers/enum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class EnumSchemaParser extends MonoSchemaParser {
3838
}
3939

4040
const refType = this.schemaUtils.getSchemaRefType(this.schema);
41-
const $ref = (refType && refType.$ref) || null;
41+
const $ref = refType?.$ref || null;
4242

4343
// fix schema when enum has length 1+ but value is []
4444
if (Array.isArray(this.schema.enum)) {

src/schema-parser/schema-formatters.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class SchemaFormatters {
105105
_.get(parsedSchema, ["schemaType"]) ||
106106
_.get(parsedSchema, ["$parsed", "schemaType"]);
107107
const formatterFn = _.get(this, [formatType, schemaType]);
108-
return (formatterFn && formatterFn(parsedSchema)) || parsedSchema;
108+
return formatterFn?.(parsedSchema) || parsedSchema;
109109
};
110110

111111
formatDescription = (description, inline) => {

src/schema-parser/schema-parser.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,7 @@ class SchemaParser {
213213
this.schema = { type: this.config.Ts.Keyword.Null };
214214
}
215215
// schema is response schema
216-
if (
217-
"content" in this.schema &&
218-
typeof this.schema["content"] === "object"
219-
) {
216+
if ("content" in this.schema && typeof this.schema.content === "object") {
220217
const schema = this.extractSchemaFromResponseStruct(this.schema);
221218
const schemaParser = this.schemaParserFabric.createSchemaParser({
222219
schema,

src/schema-parser/schema-utils.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class SchemaUtils {
3333
};
3434

3535
isRefSchema = (schema) => {
36-
return !!(schema && schema["$ref"]);
36+
return !!schema?.$ref;
3737
};
3838

3939
getEnumNames = (schema) => {
4040
return (
4141
schema["x-enumNames"] ||
42-
schema["xEnumNames"] ||
42+
schema.xEnumNames ||
4343
schema["x-enumnames"] ||
4444
schema["x-enum-varnames"]
4545
);
@@ -143,9 +143,7 @@ class SchemaUtils {
143143
const refData = this.getSchemaRefType(childSchema);
144144

145145
if (refData) {
146-
const refObjectProperties = _.keys(
147-
(refData.rawTypeData && refData.rawTypeData.properties) || {},
148-
);
146+
const refObjectProperties = _.keys(refData.rawTypeData?.properties || {});
149147
const existedRequiredKeys = refObjectProperties.filter((key) =>
150148
required.includes(key),
151149
);

src/schema-routes/schema-routes.js

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class SchemaRoutes {
160160
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
161161
const queryParams = [];
162162

163-
if (queryParamMatches && queryParamMatches.length) {
163+
if (queryParamMatches?.length) {
164164
queryParamMatches.forEach((match) => {
165165
fixedRoute = fixedRoute.replace(match, "");
166166
});
@@ -220,11 +220,7 @@ class SchemaRoutes {
220220
this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
221221
let routeParam = null;
222222

223-
if (
224-
refTypeInfo &&
225-
refTypeInfo.rawTypeData.in &&
226-
refTypeInfo.rawTypeData
227-
) {
223+
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
228224
if (!routeParams[refTypeInfo.rawTypeData.in]) {
229225
routeParams[refTypeInfo.rawTypeData.in] = [];
230226
}
@@ -345,7 +341,7 @@ class SchemaRoutes {
345341

346342
/* for example: dataType = "multipart/form-data" */
347343
for (const dataType in content) {
348-
if (content[dataType] && content[dataType].schema) {
344+
if (content[dataType]?.schema) {
349345
return {
350346
...content[dataType].schema,
351347
dataType,
@@ -510,9 +506,7 @@ class SchemaRoutes {
510506
responses: responseInfos,
511507
success: {
512508
schema: successResponse,
513-
type:
514-
(successResponse && successResponse.type) ||
515-
this.config.Ts.Keyword.Any,
509+
type: successResponse?.type || this.config.Ts.Keyword.Any,
516510
},
517511
error: {
518512
schemas: errorResponses,
@@ -640,10 +634,7 @@ class SchemaRoutes {
640634
}
641635

642636
return {
643-
paramName:
644-
requestBodyName ||
645-
(requestBody && requestBody.name) ||
646-
DEFAULT_BODY_ARG_NAME,
637+
paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
647638
contentTypes,
648639
contentKind,
649640
schema,
@@ -892,7 +883,7 @@ class SchemaRoutes {
892883
moduleNameFirstTag && firstTag
893884
? _.camelCase(firstTag)
894885
: _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
895-
let hasSecurity = !!(globalSecurity && globalSecurity.length);
886+
let hasSecurity = !!globalSecurity?.length;
896887
if (security) {
897888
hasSecurity = security.length > 0;
898889
}

0 commit comments

Comments
 (0)