'submitSubstitution' was used before it was defined
124 };
125
126 useEffect(() => {
127 submitSubstitution();128 }, []);
129
130 // const changeCurrentPlanModal = (plan_id: string) => {
'submitSubstitution' was used before it was defined
120 };
121 const closeplanNewModal = () => {
122 setNewPlanVisible(false);
123 submitSubstitution();124 };
125
126 useEffect(() => {
'submitSubstitution' was used before it was defined
112 };
113 const closeplanCurrentModal = () => {
114 setReplacePlanVisible(false);
115 submitSubstitution();116 };
117
118 const openplanNewModal = () => {
'submitSubstitution' was used before it was defined
86 const runBacktest = () => {
87 var singlesubscription: Substitution[];
88 if (currentPlan && replacementPlan) {
89 submitSubstitution(); 90 } else if (substitutions.length === 0) {
91 toast.error("Please select a few plans");
92 return null;
'plan' was used before it was defined
65 return;
66 }
67 const data: CreatePlanExternalLinkType = {
68 plan_id: plan.plan_id, 69 source: "stripe",
70 external_plan_id: link,
71 };
'plan' was used before it was defined
59
60 const createPlanExternalLink = (link: string) => {
61 if (plan.external_links.find((links) => links.external_plan_id === link)) {
62 toast.error(`Duplicate external link for ${plan.plan_name}`, { 63 position: toast.POSITION.TOP_CENTER,
64 });
65 return;
'plan' was used before it was defined
58 );
59
60 const createPlanExternalLink = (link: string) => {
61 if (plan.external_links.find((links) => links.external_plan_id === link)) { 62 toast.error(`Duplicate external link for ${plan.plan_name}`, {
63 position: toast.POSITION.TOP_CENTER,
64 });
'changeMetric' was used before it was defined
38 if (data?.metrics && Object.keys(data.metrics).length > 0) {
39 setMetricList(Object.keys(data.metrics));
40 setSelectedMetric(Object.keys(data.metrics)[0]);
41 changeMetric(Object.keys(data.metrics)[0]); 42 }
43 }, [data]);
44
Description
Variables, functions and types should always be used after they've been defined. This issue will flag any code snippets that use variables or types before definition.
Sometimes, the code will run just fine even when the variable is declared after use. Consider the following example:
const ram: Resource = { type: "memory", limit: 1024 ** 3 }
type Resource = {
type: string;
limit: number;
}
Here, Resource
is used in the annotation before it has been defined.
Similarly, it is possible to hoist function declarations and variables declared with the var
keyword:
const four = twice(2);
function twice(n: number) {
return n * 2;
}
However, it makes the code harder to follow when variables or types are declared after being used.
Bad Practice
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}
interface Radiant {
order: string;
strength: number;
}
Recommended
interface Radiant {
order: string;
strength: number;
}
const knight: Radiant = {
order: "SurgeBinder"
strength: 30
}