Skip to content

Commit afba377

Browse files
committed
refactor: cleaner length syntax
1 parent 5399f76 commit afba377

137 files changed

Lines changed: 236 additions & 237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/openapi-ts-axios/src/client/client/utils.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const buildUrl: Client['buildUrl'] = (options) => {
130130
const instanceBaseUrl = options.axios?.defaults?.baseURL;
131131

132132
const baseUrl =
133-
!!options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
133+
options.baseURL && typeof options.baseURL === 'string' ? options.baseURL : instanceBaseUrl;
134134

135135
return getUrl({
136136
baseUrl: baseUrl as string,

packages/codegen-core/src/config/load.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export async function loadConfigFile<T extends AnyObject>({
2828

2929
const fileConfigs = fileConfig instanceof Array ? fileConfig : [fileConfig];
3030
const mergedConfigs = fileConfigs.map((config) => mergeConfigs<T>(config, userConfig));
31-
const foundConfig = fileConfigs.some((config) => Object.keys(config).length > 0);
31+
const foundConfig = fileConfigs.some((config) => Object.keys(config).length);
3232

3333
return { configFile: loadedConfigFile, configs: mergedConfigs, foundConfig };
3434
}

packages/codegen-core/src/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class Logger {
7777
if (!event.end) {
7878
event.end = performance.mark(idEnd(event.id));
7979
}
80-
if (event.events.length > 0) {
80+
if (event.events.length) {
8181
this.endAllEvents(event.events);
8282
}
8383
}

packages/json-schema-ref-parser/src/bundle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,8 @@ function remap(parser: $RefParser, inventory: Array<InventoryEntry>) {
445445
const ensureContainer = (
446446
type: 'schemas' | 'parameters' | 'requestBodies' | 'responses' | 'headers',
447447
) => {
448-
const isOas3 = !!(root && typeof root === 'object' && typeof root.openapi === 'string');
449-
const isOas2 = !!(root && typeof root === 'object' && typeof root.swagger === 'string');
448+
const isOas3 = Boolean(root && typeof root === 'object' && typeof root.openapi === 'string');
449+
const isOas2 = Boolean(root && typeof root === 'object' && typeof root.swagger === 'string');
450450

451451
if (isOas3) {
452452
if (!root.components || typeof root.components !== 'object') {

packages/json-schema-ref-parser/src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@ export class $RefParser {
117117

118118
await resolveExternal(this, this.options);
119119
const errors = JSONParserErrorGroup.getParserErrors(this);
120-
if (errors.length > 0) {
120+
if (errors.length) {
121121
throw new JSONParserErrorGroup(this);
122122
}
123123
_bundle(this, this.options);
124124
const errors2 = JSONParserErrorGroup.getParserErrors(this);
125-
if (errors2.length > 0) {
125+
if (errors2.length) {
126126
throw new JSONParserErrorGroup(this);
127127
}
128128
return this.schema!;
@@ -148,14 +148,14 @@ export class $RefParser {
148148

149149
await resolveExternal(this, this.options);
150150
const errors = JSONParserErrorGroup.getParserErrors(this);
151-
if (errors.length > 0) {
151+
if (errors.length) {
152152
throw new JSONParserErrorGroup(this);
153153
}
154154
_bundle(this, this.options);
155155
// Merged root is ready for bundling
156156

157157
const errors2 = JSONParserErrorGroup.getParserErrors(this);
158-
if (errors2.length > 0) {
158+
if (errors2.length) {
159159
throw new JSONParserErrorGroup(this);
160160
}
161161
return this.schema!;
@@ -297,7 +297,7 @@ export class $RefParser {
297297

298298
public mergeMany(): JSONSchema {
299299
const schemas = this.schemaMany || [];
300-
if (schemas.length === 0) {
300+
if (!schemas.length) {
301301
throw ono('mergeMany called with no schemas. Did you run parseMany?');
302302
}
303303

@@ -335,7 +335,7 @@ export class $RefParser {
335335
}
336336
}
337337
}
338-
if (Object.keys(infoAccumulator).length > 0) {
338+
if (Object.keys(infoAccumulator).length) {
339339
merged.info = infoAccumulator;
340340
}
341341

@@ -356,7 +356,7 @@ export class $RefParser {
356356
}
357357
}
358358
}
359-
if (servers.length > 0) {
359+
if (servers.length) {
360360
merged.servers = servers;
361361
}
362362

@@ -568,7 +568,7 @@ export class $RefParser {
568568
}
569569
}
570570

571-
if (tags.length > 0) {
571+
if (tags.length) {
572572
merged.tags = tags;
573573
}
574574

packages/json-schema-ref-parser/src/pointer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class Pointer<S extends object = JSONSchema> {
140140
}
141141
}
142142

143-
if (errors.length > 0) {
143+
if (errors.length) {
144144
throw errors.length === 1
145145
? errors[0]
146146
: new AggregateError(errors, 'Multiple missing pointer errors');
@@ -171,7 +171,7 @@ class Pointer<S extends object = JSONSchema> {
171171
const tokens = Pointer.parse(this.path);
172172
let token;
173173

174-
if (tokens.length === 0) {
174+
if (!tokens.length) {
175175
// There are no tokens, replace the entire object with the new value
176176
this.value = value;
177177
return value;

packages/json-schema-ref-parser/src/ref.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class $Ref<S extends object = JSONSchema> {
152152
value !== null &&
153153
'$ref' in value &&
154154
typeof value.$ref === 'string' &&
155-
value.$ref.length > 0
155+
Boolean(value.$ref.length)
156156
);
157157
}
158158

packages/json-schema-ref-parser/src/refs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function getPaths<S extends object = JSONSchema>($refs: $RefsMap<S>, types: stri
224224

225225
// Filter the paths by type
226226
types = Array.isArray(types[0]) ? types[0] : Array.prototype.slice.call(types);
227-
if (types.length > 0 && types[0]) {
227+
if (types.length && types[0]) {
228228
paths = paths.filter((key) => types.includes($refs[key]!.pathType as string));
229229
}
230230

packages/openapi-python/src/cli/adapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export const cliToConfig = (cli: CliOptions): Partial<UserConfig> => {
1212
if (cli.dryRun !== undefined) config.dryRun = cli.dryRun;
1313

1414
const plugins: ToArray<UserConfig['plugins']> = [];
15-
if (cli.plugins instanceof Array && cli.plugins.length > 0) {
15+
if (cli.plugins instanceof Array && cli.plugins.length) {
1616
plugins.push(...cli.plugins);
1717
}
1818
// if (cli.client) plugins.push(cli.client);
19-
if (plugins.length > 0) config.plugins = plugins;
19+
if (plugins.length) config.plugins = plugins;
2020

2121
if (cli.debug || cli.silent || cli.logs || cli.logFile !== undefined) {
2222
config.logs = {

packages/openapi-python/src/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function createClient(
6363
const configErrors = jobs.flatMap((job) =>
6464
job.errors.map((error) => ({ error, jobIndex: job.index })),
6565
);
66-
if (configErrors.length > 0) {
66+
if (configErrors.length) {
6767
throw new ConfigValidationError(configErrors);
6868
}
6969

0 commit comments

Comments
 (0)