Skip to content

Commit a28ed71

Browse files
committed
chore: apply review suggestions
1 parent c3712b3 commit a28ed71

6 files changed

Lines changed: 31 additions & 37 deletions

File tree

.eslintrc.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@
77
module.exports = {
88
extends: ['eslint-config-salesforce-typescript', 'eslint-config-salesforce-license'],
99
rules: {
10-
// '@typescript-eslint/restrict-template-expressions': 'off',
11-
// '@typescript-eslint/explicit-function-return-type': 'off',
12-
// '@typescript-eslint/no-unsafe-assignment': 'off',
13-
// '@typescript-eslint/no-unsafe-member-access': 'off',
14-
// '@typescript-eslint/no-unsafe-call': 'off',
15-
// '@typescript-eslint/no-unsafe-return': 'off',
16-
// '@typescript-eslint/member-ordering': 'off',
1710
'no-underscore-dangle': 'off',
18-
// '@typescript-eslint/explicit-module-boundary-types': 'off',
19-
// 'no-empty': 'off',
20-
// '@typescript-eslint/no-explicit-any': 'off',
2111
'jsdoc/newline-after-description': 'off',
2212
},
2313
};

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package-lock.json
1010
npm-error.log
1111
yarn-error.log
1212
lerna-debug.log
13-
*.tsbuildinfo
1413

1514
# compile source
1615
lib
@@ -26,6 +25,7 @@ coverage
2625
docs
2726

2827
# -- CLEAN ALL
28+
*.tsbuildinfo
2929
.eslintcache
3030
.wireit
3131
node_modules

src/commands/commandreference/generate.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import * as fs from 'fs/promises';
9+
import { existsSync } from 'fs';
910
import * as os from 'os';
1011
import * as path from 'path';
1112
import { SfCommand } from '@salesforce/sf-plugins-core';
@@ -22,12 +23,6 @@ import { CommandClass, events } from '../../utils';
2223
Messages.importMessagesDirectory(__dirname);
2324
const messages = Messages.loadMessages('@salesforce/plugin-command-reference', 'main');
2425

25-
const fileExists = async (filePath: string): Promise<boolean> =>
26-
fs
27-
.stat(filePath)
28-
.then(() => true)
29-
.catch(() => false);
30-
3126
export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
3227
public static description = messages.getMessage('commandDescription');
3328

@@ -65,7 +60,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
6560
let pluginNames: string[];
6661
if (!flags.plugins && !flags.all) {
6762
const pJsonPath = path.join(process.cwd(), 'package.json');
68-
if (await fileExists(pJsonPath)) {
63+
if (existsSync(pJsonPath)) {
6964
const packageJson = parseJsonMap(await fs.readFile(pJsonPath, 'utf-8'));
7065
pluginNames = [ensureString(packageJson.name)];
7166
} else {
@@ -125,8 +120,7 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
125120
this.loadCliMeta()
126121
);
127122

128-
events.on('topic', ({ topic }) => {
129-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
123+
events.on('topic', ({ topic }: { topic: string }) => {
130124
this.log(chalk.green(`Generating topic '${topic}'`));
131125
});
132126

@@ -148,8 +142,8 @@ export default class CommandReferenceGenerate extends SfCommand<AnyJson> {
148142
return { warnings };
149143
}
150144

151-
private pluginMap(plugins: string[]): JsonMap {
152-
const pluginToParentPlugin: JsonMap = {};
145+
private pluginMap(plugins: string[]): Record<string, unknown> {
146+
const pluginToParentPlugin: Record<string, unknown> = {};
153147

154148
const resolveChildPlugins = (parentPlugin: Interfaces.Plugin): void => {
155149
for (const childPlugin of parentPlugin.pjson.oclif.plugins ?? []) {

src/ditamap/command.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ const getDefault = async (flag?: CommandHelpInfo): Promise<string> => {
4040
export class Command extends Ditamap {
4141
private flags: Dictionary<CommandHelpInfo>;
4242

43-
public constructor(topic: string, subtopic: string | null, command: CommandClass, commandMeta: JsonMap = {}) {
43+
public constructor(
44+
topic: string,
45+
subtopic: string | null,
46+
command: CommandClass,
47+
commandMeta: Record<string, unknown> = {}
48+
) {
4449
const commandWithUnderscores = ensureString(command.id).replace(/:/g, '_');
4550
const filename = Ditamap.file(`cli_reference_${commandWithUnderscores}`, 'xml');
4651

@@ -69,8 +74,8 @@ export class Command extends Ditamap {
6974
const commandName = command.id.replace(/:/g, asString(commandMeta.topicSeparator, ':'));
7075

7176
const examples = (command.examples ?? []).map((example) => {
72-
let desc: string | null = null;
73-
let commands: string[] = [];
77+
let desc: string | null;
78+
let commands: string[];
7479
if (typeof example === 'string') {
7580
const parts = example.split('\n');
7681
desc = parts.length > 1 ? parts[0] : null;

src/ditamap/ditamap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export abstract class Ditamap {
4646

4747
public static cliVersion: string;
4848

49-
public static plugins: JsonMap;
49+
public static plugins: Record<string, unknown>;
5050

5151
public static pluginVersions: Array<{
5252
name: string;

src/docs.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ensure,
1414
ensureArray,
1515
ensureJsonMap,
16+
ensureObject,
1617
ensureString,
1718
isArray,
1819
JsonMap,
@@ -38,10 +39,10 @@ function emitNoTopicMetadataWarning(topic: string): void {
3839
export class Docs {
3940
public constructor(
4041
private outputDir: string,
41-
private plugins: JsonMap,
42+
private plugins: Record<string, unknown>,
4243
private hidden: boolean,
43-
private topicMeta: JsonMap,
44-
private cliMeta: JsonMap
44+
private topicMeta: Record<string, unknown>,
45+
private cliMeta: Record<string, unknown>
4546
) {}
4647

4748
public async build(commands: CommandClass[]): Promise<void> {
@@ -164,8 +165,8 @@ export class Docs {
164165
const subtopic = commandParts[1];
165166

166167
try {
167-
const topicMeta = ensureJsonMap(this.topicMeta[topLevelTopic]);
168-
const subTopicsMeta = ensureJsonMap(topicMeta.subtopics);
168+
const topicMeta = ensureObject<Record<string, unknown>>(this.topicMeta[topLevelTopic]);
169+
const subTopicsMeta = ensureObject<Record<string, unknown>>(topicMeta.subtopics);
169170
if (subTopicsMeta.hidden && !this.hidden) {
170171
continue;
171172
}
@@ -210,19 +211,23 @@ export class Docs {
210211
}
211212
}
212213

213-
private resolveCommandMeta(commandId: string, command: CommandClass, commandsInTopic: number): JsonMap {
214+
private resolveCommandMeta(
215+
commandId: string,
216+
command: CommandClass,
217+
commandsInTopic: number
218+
): Record<string, unknown> {
214219
const commandMeta = Object.assign({}, this.cliMeta);
215220
// Remove top level topic, since the topic meta is already for that topic
216221
const commandParts = commandId.split(':');
217222
let part;
218223
try {
219-
let currentMeta: JsonMap | undefined;
224+
let currentMeta: Record<string, unknown> | undefined;
220225
for (part of commandParts) {
221226
if (currentMeta) {
222-
const subtopics = ensureJsonMap(currentMeta.subtopics);
223-
currentMeta = ensureJsonMap(subtopics[part]);
227+
const subtopics = ensureObject<Record<string, unknown>>(currentMeta.subtopics);
228+
currentMeta = ensureObject<Record<string, unknown>>(subtopics[part]);
224229
} else {
225-
currentMeta = ensureJsonMap(this.topicMeta[part]);
230+
currentMeta = ensureObject<Record<string, unknown>>(this.topicMeta[part]);
226231
}
227232

228233
// Collect all tiers of the meta, so the command will also pick up the topic state (isPilot, etc) if applicable
@@ -249,7 +254,7 @@ export class Docs {
249254
topic: string,
250255
subtopic: string | null,
251256
command: CommandClass,
252-
commandMeta: JsonMap
257+
commandMeta: Record<string, unknown>
253258
): Promise<string> {
254259
// If it is a hidden command - abort
255260
if (command.hidden && !this.hidden) {

0 commit comments

Comments
 (0)