'mockData' was used before it was defined
4
5export const mockOrgNameSearch = (input: SearchInput): ApiOutput['organization']['searchName'] => {
6 const searchRegex = new RegExp(`.*${input.search}.*`, 'i')
7 const results = mockData.filter(({ name }) => searchRegex.test(name)) 8 return results
9}
10
'locationSearchMockData' was used before it was defined
4 input: ApiInput['geo']['autocomplete']
5): ApiOutput['geo']['autocomplete'] => {
6 const searchRegex = new RegExp(`.*${input.search}.*`, 'i')
7 const results = locationSearchMockData.names 8 .filter(({ searchValue }) => searchRegex.test(searchValue))
9 .map(({ searchValue, ...data }) => ({ ...data }))
10
'locationSearchMockData' was used before it was defined
13
14export const mockGeocode = (input: ApiInput['geo']['geoByPlaceId']): ApiOutput['geo']['geoByPlaceId'] => {
15 // const searchRegex = new RegExp(`.*${input.search}.*`, 'i')
16 const results = locationSearchMockData.locations 17 .filter(({ placeId }) => placeId === input)
18 .map(({ geometry, ...data }) => ({ geometry, ...data }))
19 const result = results[0]
'userListSelect' was used before it was defined
228 reviews: reviewIds,
229 phones: orgPhoneInclude,
230 emails: orgEmailInclude,
231 userLists: userListSelect(ctx),232 id: true,
233 },
234 } satisfies Prisma.Organization$servicesArgs)
'reject' was used before it was defined
5
6export const isAuthed = t.middleware(({ ctx, meta, next }) => {
7 if (!ctx.session || !ctx.session.user || !checkPermissions(meta, ctx)) {
8 return reject() 9 }
10 return next({
11 ctx: {
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
}