Bug WikiCode Quality & RedundancyIncorrect string interpolation
1 example

Incorrect string interpolation

Variables incorrectly formatted within strings.

[ FAQ1 ]

What is incorrect string interpolation?

Incorrect string interpolation occurs when placeholders or syntax used for injecting variables or expressions into strings are improperly structured or misused, resulting in incorrect, unintended, or literal outputs. This often happens due to mistakes in template literals (JavaScript), f-strings (Python), or other string formatting methods. Errors can include variables displaying as literal placeholders (e.g., ${variable}) rather than their intended values, concatenation issues, or incorrect formatting, all of which complicate debugging and produce unreliable outputs.
[ FAQ2 ]

How to fix incorrect string interpolation

To fix incorrect string interpolation, verify correct syntax for the interpolation method used—for example, template literals (${variable} in JavaScript) or f-strings (f"{variable}" in Python)—ensuring proper formatting and variable injection. Replace incorrect concatenation or manual string joining with proper interpolation syntax for clarity and reliability. Utilize IDE features, linters, or static analyzers to detect and flag interpolation issues proactively. Regularly test string outputs thoroughly, especially in conditional or dynamic contexts, maintaining consistency and correctness in string generation throughout your codebase.
diff block
+import { Controller, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useNavigate } from "@tanstack/react-router";
+import { z } from "zod";
+
+import { createNotification } from "@app/components/notifications";
+import { Button, FormControl, Input, Modal, ModalContent, Spinner } from "@app/components/v2";
+import { useWorkspace } from "@app/context";
+import { useCreateProjectRole, useGetProjectRoleBySlug } from "@app/hooks/api";
+import { TProjectRole } from "@app/hooks/api/roles/types";
+import { slugSchema } from "@app/lib/schemas";
+
+type Props = {
+ isOpen: boolean;
+ onOpenChange: (isOpen: boolean) => void;
+ roleSlug?: string;
+};
+
+const schema = z
+ .object({
+ name: z.string(),
+ description: z.string(),
+ slug: slugSchema({ min: 1 })
+ })
+ .required();
+
+export type FormData = z.infer<typeof schema>;
+
+type ContentProps = {
+ role: TProjectRole;
+ onClose: () => void;
+};
+
+const Content = ({ role, onClose }: ContentProps) => {
+ const {
+ control,
+ handleSubmit,
+ formState: { isSubmitting }
+ } = useForm<FormData>({
+ defaultValues: {
+ name: `${role.name} Duplicate`
+ },
+ resolver: zodResolver(schema)
+ });
+
+ const { currentWorkspace } = useWorkspace();
+
+ const createRole = useCreateProjectRole();
+ const navigate = useNavigate();
+
+ const handleDuplicateRole = async (form: FormData) => {
+ try {
+ const newRole = await createRole.mutateAsync({
+ projectId: role.projectId,
+ permissions: role.permissions,
+ ...form
+ });
+
+ createNotification({
+ type: "success",
+ text: "Role duplicated successfully"
+ });
+
+ navigate({
+ to: `/${currentWorkspace.type}/$projectId/roles/$roleSlug` as const,
+ params: {
Greptile
greptile
logic: Navigation URL template uses incorrect string interpolation. Should be `${currentWorkspace.type}/${projectId}/roles/${roleSlug}` instead of using $ directly ```suggestion navigate({ + to: `/${currentWorkspace.type}/${projectId}/roles/${roleSlug}` as const, params: { ```