Skip to content
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
8 changes: 6 additions & 2 deletions src/commands/ext-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import { marked } from "marked";
import { markedTerminal } from "marked-terminal";
import { ExtensionSpec } from "../extensions/types";
import { ExtensionSpec, ExtensionVersion } from "../extensions/types";

const FUNCTION_TYPE_REGEX = /\..+\.function/;

Expand All @@ -21,10 +21,11 @@
)
.option("--markdown", "output info in Markdown suitable for constructing a README file")
.before(checkMinRequiredVersion, "extMinVersion")
.action(async (extensionName: string, options: any) => {

Check warning on line 24 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
let spec: ExtensionSpec;
let version: ExtensionVersion | undefined;
if (isLocalExtension(extensionName)) {
if (!options.markdown) {

Check warning on line 28 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .markdown on an `any` value
utils.logLabeledBullet(logPrefix, `reading extension from directory: ${extensionName}`);
}
spec = await getLocalExtensionSpec(extensionName);
Expand All @@ -41,25 +42,28 @@
const [name, version] = extensionName.split("@");
extensionName = `firebase/${name}@${version || "latest"}`;
}
const version = await extensionsApi.getExtensionVersion(extensionName);
version = await extensionsApi.getExtensionVersion(extensionName);
spec = version.spec;
}

if (!options.markdown) {

Check warning on line 49 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .markdown on an `any` value
utils.logLabeledBullet(logPrefix, `information about ${extensionName}:\n`);
}

const lines: string[] = [];
if (options.markdown) {

Check warning on line 54 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .markdown on an `any` value
lines.push(`# ${spec.displayName}`);

Check warning on line 55 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
} else {
lines.push(`**Name**: ${spec.displayName}`);

Check warning on line 57 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
}

const authorName = spec.author?.authorName;
const url = spec.author?.url;
const urlMarkdown = url ? `(**[${url}](${url})**)` : "";
lines.push(`**Author**: ${authorName} ${urlMarkdown}`);

Check warning on line 63 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Invalid type "string | undefined" of template literal expression
if (version?.sourceDownloadUri) {
lines.push(`**Download URL**: ${version.sourceDownloadUri}`);
}

if (spec.description) {
lines.push(`**Description**: ${spec.description}`);
Expand All @@ -75,11 +79,11 @@
}
}

const functions: any = [];

Check warning on line 82 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
const otherResources: any = [];

Check warning on line 83 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unexpected any. Specify a different type
for (const resource of spec.resources) {
if (FUNCTION_TYPE_REGEX.test(resource.type)) {
functions.push(resource);

Check warning on line 86 in src/commands/ext-info.ts

View workflow job for this annotation

GitHub Actions / lint (20)

Unsafe member access .push on an `any` value
} else {
otherResources.push(resource);
}
Expand Down
32 changes: 32 additions & 0 deletions src/extensions/listExtensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ const MOCK_INSTANCES = [
extensionRef: "firebase/image-resizer",
name: "projects/my-test-proj/instances/image-resizer/configurations/95355951-397f-4821-a5c2-9c9788b2cc63",
createTime: "2019-05-19T00:20:10.416947Z",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "200x200,400x400",
DELETE_ORIGINAL_FILE: "false",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
source: {
state: "ACTIVE",
spec: {
Expand All @@ -35,6 +43,14 @@ const MOCK_INSTANCES = [
extensionRef: "firebase/image-resizer",
name: "projects/my-test-proj/instances/image-resizer-1/configurations/5b1fb749-764d-4bd1-af60-bb7f22d27860",
createTime: "2019-06-19T00:21:06.722782Z",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "300x300",
DELETE_ORIGINAL_FILE: "true",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
source: {
spec: {
version: "0.1.0",
Expand Down Expand Up @@ -78,6 +94,14 @@ describe("listExtensions", () => {
state: "ACTIVE",
updateTime: "2019-06-19 00:21:06",
version: "0.1.0",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "300x300",
DELETE_ORIGINAL_FILE: "true",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
},
{
extension: "firebase/image-resizer",
Expand All @@ -86,6 +110,14 @@ describe("listExtensions", () => {
state: "ACTIVE",
updateTime: "2019-05-19 00:20:10",
version: "0.1.0",
params: {
IMG_BUCKET: "my-test-proj.firebasestorage.app",
IMG_SIZES: "200x200,400x400",
DELETE_ORIGINAL_FILE: "false",
},
systemParams: {
"firebaseextensions.v1beta.function/location": "us-central1",
},
},
];
expect(result).to.eql(expected);
Expand Down
6 changes: 4 additions & 2 deletions src/extensions/listExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as extensionsUtils from "./utils";
* @param projectId ID of the project we're querying
* @return mapping that contains a list of instances under the "instances" key
*/
export async function listExtensions(projectId: string): Promise<Record<string, string>[]> {
export async function listExtensions(projectId: string): Promise<Record<string, any>[]> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The use of any violates the repository style guide (GEMINI.md, line 38). Please define a proper interface or use a specific type literal for the return value to ensure type safety.

Suggested change
export async function listExtensions(projectId: string): Promise<Record<string, any>[]> {
export async function listExtensions(projectId: string): Promise<Array<{
extension: string;
publisher: string;
instanceId: string;
state: string;
version: string | undefined;
updateTime: string;
params: Record<string, string>;
systemParams: Record<string, string>;
}>> {
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

const instances = await listInstances(projectId);
if (instances.length < 1) {
logLabeledBullet(
Expand All @@ -30,7 +30,7 @@ export async function listExtensions(projectId: string): Promise<Record<string,
const sorted = instances.sort(
(a, b) => new Date(b.createTime).valueOf() - new Date(a.createTime).valueOf(),
);
const formatted: Record<string, string>[] = [];
const formatted: Record<string, any>[] = [];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Avoid using any here to comply with the repository style guide. Explicitly typing the formatted array improves code clarity and maintainability.

  const formatted: Array<{
    extension: string;
    publisher: string;
    instanceId: string;
    state: string;
    version: string | undefined;
    updateTime: string;
    params: Record<string, string>;
    systemParams: Record<string, string>;
  }> = [];
References
  1. Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)

sorted.forEach((instance) => {
let extension = instance.config.extensionRef || "";
let publisher;
Expand All @@ -54,6 +54,8 @@ export async function listExtensions(projectId: string): Promise<Record<string,
state,
version,
updateTime,
params: instance.config.params,
systemParams: instance.config.systemParams,
});
});

Expand Down
Loading