Skip to content

Fix biome errors (round 2) #785

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

Merged
merged 2 commits into from
Jun 20, 2024
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 src/code-formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CodeFormatter {
{ newLineCharacter: ts.sys.newLine },
)[0];

if (fileTextChanges && fileTextChanges.textChanges.length) {
if (fileTextChanges?.textChanges.length) {
return _.reduceRight(
fileTextChanges.textChanges,
(content, { span, newText }) =>
Expand Down
2 changes: 1 addition & 1 deletion src/code-gen-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class CodeGenProcess {

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

Expand Down
2 changes: 1 addition & 1 deletion src/schema-parser/base-schema-parsers/enum.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class EnumSchemaParser extends MonoSchemaParser {
}

const refType = this.schemaUtils.getSchemaRefType(this.schema);
const $ref = (refType && refType.$ref) || null;
const $ref = refType?.$ref || null;

// fix schema when enum has length 1+ but value is []
if (Array.isArray(this.schema.enum)) {
Expand Down
2 changes: 1 addition & 1 deletion src/schema-parser/schema-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class SchemaFormatters {
_.get(parsedSchema, ["schemaType"]) ||
_.get(parsedSchema, ["$parsed", "schemaType"]);
const formatterFn = _.get(this, [formatType, schemaType]);
return (formatterFn && formatterFn(parsedSchema)) || parsedSchema;
return formatterFn?.(parsedSchema) || parsedSchema;
};

formatDescription = (description, inline) => {
Expand Down
5 changes: 1 addition & 4 deletions src/schema-parser/schema-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ class SchemaParser {
this.schema = { type: this.config.Ts.Keyword.Null };
}
// schema is response schema
if (
"content" in this.schema &&
typeof this.schema["content"] === "object"
) {
if ("content" in this.schema && typeof this.schema.content === "object") {
const schema = this.extractSchemaFromResponseStruct(this.schema);
const schemaParser = this.schemaParserFabric.createSchemaParser({
schema,
Expand Down
8 changes: 3 additions & 5 deletions src/schema-parser/schema-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class SchemaUtils {
};

isRefSchema = (schema) => {
return !!(schema && schema["$ref"]);
return !!schema?.$ref;
};

getEnumNames = (schema) => {
return (
schema["x-enumNames"] ||
schema["xEnumNames"] ||
schema.xEnumNames ||
schema["x-enumnames"] ||
schema["x-enum-varnames"]
);
Expand Down Expand Up @@ -143,9 +143,7 @@ class SchemaUtils {
const refData = this.getSchemaRefType(childSchema);

if (refData) {
const refObjectProperties = _.keys(
(refData.rawTypeData && refData.rawTypeData.properties) || {},
);
const refObjectProperties = _.keys(refData.rawTypeData?.properties || {});
const existedRequiredKeys = refObjectProperties.filter((key) =>
required.includes(key),
);
Expand Down
21 changes: 6 additions & 15 deletions src/schema-routes/schema-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class SchemaRoutes {
const queryParamMatches = fixedRoute.match(/(\{\?.*\})/g);
const queryParams = [];

if (queryParamMatches && queryParamMatches.length) {
if (queryParamMatches?.length) {
queryParamMatches.forEach((match) => {
fixedRoute = fixedRoute.replace(match, "");
});
Expand Down Expand Up @@ -220,11 +220,7 @@ class SchemaRoutes {
this.schemaParserFabric.schemaUtils.getSchemaRefType(parameter);
let routeParam = null;

if (
refTypeInfo &&
refTypeInfo.rawTypeData.in &&
refTypeInfo.rawTypeData
) {
if (refTypeInfo?.rawTypeData.in && refTypeInfo.rawTypeData) {
if (!routeParams[refTypeInfo.rawTypeData.in]) {
routeParams[refTypeInfo.rawTypeData.in] = [];
}
Expand Down Expand Up @@ -345,7 +341,7 @@ class SchemaRoutes {

/* for example: dataType = "multipart/form-data" */
for (const dataType in content) {
if (content[dataType] && content[dataType].schema) {
if (content[dataType]?.schema) {
return {
...content[dataType].schema,
dataType,
Expand Down Expand Up @@ -510,9 +506,7 @@ class SchemaRoutes {
responses: responseInfos,
success: {
schema: successResponse,
type:
(successResponse && successResponse.type) ||
this.config.Ts.Keyword.Any,
type: successResponse?.type || this.config.Ts.Keyword.Any,
},
error: {
schemas: errorResponses,
Expand Down Expand Up @@ -640,10 +634,7 @@ class SchemaRoutes {
}

return {
paramName:
requestBodyName ||
(requestBody && requestBody.name) ||
DEFAULT_BODY_ARG_NAME,
paramName: requestBodyName || requestBody?.name || DEFAULT_BODY_ARG_NAME,
contentTypes,
contentKind,
schema,
Expand Down Expand Up @@ -892,7 +883,7 @@ class SchemaRoutes {
moduleNameFirstTag && firstTag
? _.camelCase(firstTag)
: _.camelCase(_.compact(_.split(route, "/"))[moduleNameIndex]);
let hasSecurity = !!(globalSecurity && globalSecurity.length);
let hasSecurity = !!globalSecurity?.length;
if (security) {
hasSecurity = security.length > 0;
}
Expand Down
Loading