Skip to content

Commit

Permalink
chore: more straightforward type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Sep 11, 2023
1 parent 2a91415 commit 69ed44c
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/cmds/docs/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export default class DocsEditCommand extends Command {
];
}

// @ts-expect-error this command is weird in that it can return `undefined` but we plan on removing this command in a future release.
async run(opts: AuthenticatedCommandOptions<Options>): Promise<undefined> {
async run(opts: AuthenticatedCommandOptions<Options>): Promise<string> {
Command.warn('`rdme docs:edit` is now deprecated and will be removed in a future release.');
await super.run(opts);

Expand Down Expand Up @@ -104,7 +103,7 @@ export default class DocsEditCommand extends Command {
// Normally we should resolve with a value that is logged to the console,
// but since we need to wait for the temporary file to be removed,
// it's okay to resolve the promise with no value.
return resolve(undefined);
return resolve('');
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/cmds/openapi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default class OpenAPICommand extends Command {
Command.debug('no id parameter, retrieving list of API specs');
const apiSettings = await getSpecs('/api/v1/api-specification');

const totalPages = Math.ceil(parseInt(apiSettings.headers.get('x-total-count'), 10) / 10);
const totalPages = Math.ceil(parseInt(apiSettings.headers.get('x-total-count') || '0', 10) / 10);
const parsedDocs = parse(apiSettings.headers.get('link'));
Command.debug(`total pages: ${totalPages}`);
Command.debug(`pagination result: ${JSON.stringify(parsedDocs)}`);
Expand Down
8 changes: 4 additions & 4 deletions src/cmds/openapi/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface Options {
}

export default class OpenAPIInspectCommand extends Command {
definitionVersion: string;
definitionVersion!: string;

tableBorder: Record<string, string>;

Expand Down Expand Up @@ -57,7 +57,7 @@ export default class OpenAPIInspectCommand extends Command {
.reduce((prev, next) => Object.assign(prev, next));
}

getFeatureDocsURL(feature: AnalyzedFeature): string {
getFeatureDocsURL(feature: AnalyzedFeature): string | undefined {
if (!feature.url) {
return undefined;
}
Expand Down Expand Up @@ -178,12 +178,12 @@ export default class OpenAPIInspectCommand extends Command {
[
{ component: 'openapi', header: 'OpenAPI Features' },
{ component: 'readme', header: 'ReadMe-Specific Features and Extensions' },
].forEach(({ component, header }: { component: 'openapi' | 'readme'; header: string }) => {
].forEach(({ component, header }: { component: string; header: string }) => {
const tableData: string[][] = [
[chalk.bold.green('Feature'), chalk.bold.green('Used?'), chalk.bold.green('Description')],
];

Object.entries(analysis[component]).forEach(([feature, info]) => {
Object.entries(analysis[component as 'openapi' | 'readme']).forEach(([feature, info]) => {
const descriptions: string[] = [];
if (info.description) {
descriptions.push(info.description);
Expand Down
4 changes: 2 additions & 2 deletions src/cmds/openapi/reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export default class OpenAPIReduceCommand extends Command {
message: 'Choose which paths to reduce by:',
min: 1,
choices: () => {
return Object.keys(parsedPreparedSpec.paths).map(p => ({
return Object.keys(parsedPreparedSpec.paths || []).map(p => ({
title: p,
value: p,
}));
Expand All @@ -144,7 +144,7 @@ export default class OpenAPIReduceCommand extends Command {
choices: (prev, values) => {
const paths: string[] = values.paths;
let methods = paths
.map((p: string) => Object.keys(parsedPreparedSpec.paths[p] || {}))
.map((p: string) => Object.keys(parsedPreparedSpec.paths?.[p] || {}))
.flat()
.filter((method: string) => method.toLowerCase() !== 'parameters');

Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import * as help from './lib/help';
import { debug } from './lib/logger';
import createGHA from './lib/createGHA';
import type Command from './lib/baseCommand';
import type { CommandOptions } from './lib/baseCommand';
import type { AuthenticatedCommandOptions, CommandOptions } from './lib/baseCommand';
import getCurrentConfig from './lib/getCurrentConfig';

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ export default function rdme(rawProcessArgv: NodeJS.Process['argv']) {
}

try {
let cmdArgv: CommandOptions<{}>;
let cmdArgv: CommandOptions<{}> | AuthenticatedCommandOptions<{}>;
let bin: Command;

// Handling for `rdme help` and `rdme help <command>` cases.
Expand All @@ -105,7 +105,7 @@ export default function rdme(rawProcessArgv: NodeJS.Process['argv']) {
return Promise.resolve(help.globalUsage(mainArgs));
}

if (argv._unknown.indexOf('-H') !== -1) {
if (argv._unknown?.indexOf('-H') !== -1) {
return Promise.resolve(help.globalUsage(mainArgs));
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/baseCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import loginFlow from './loginFlow';

export type CommandOptions<T> = T & {
github?: boolean;
} & CommandLineOptions & { key: never };
} & CommandLineOptions & { key?: never };

export type AuthenticatedCommandOptions<T> = Omit<CommandOptions<T>, 'key'> & {
key: string;
Expand Down
6 changes: 3 additions & 3 deletions src/lib/createGHA/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const getGHAFileName = (fileName: string) => {
*/
function getKey(args: OptionDefinition[], opts: CommandOptions<{}> | AuthenticatedCommandOptions<{}>): string | false {
if (args.some(arg => arg.name === 'key')) {
return `••••••••••••${opts.key.slice(-5)}`;
return `••••••••••••${opts.key?.slice(-5) || ''}`;
}
return false;
}
Expand Down Expand Up @@ -271,8 +271,8 @@ export default async function createGHA(

let output = yamlBase;

Object.keys(data).forEach((key: keyof typeof data) => {
output = output.replace(new RegExp(`{{${key}}}`, 'g'), data[key]);
Object.keys(data).forEach(key => {
output = output.replace(new RegExp(`{{${key}}}`, 'g'), data[key as keyof typeof data]);
});

if (!fs.existsSync(GITHUB_WORKFLOW_DIR)) {
Expand Down
6 changes: 5 additions & 1 deletion src/lib/getPkgVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ type npmDistTag = 'latest';
*/
export function getNodeVersion() {
const { node } = pkg.engines;
return semver.minVersion(node).major;
const parsedVersion = semver.minVersion(node);
if (!parsedVersion) {
throw new Error('`version` value in package.json is invalid');
}
return parsedVersion.major;
}

/**
Expand Down

0 comments on commit 69ed44c

Please sign in to comment.