TryGhost/Ghost

View on GitHub
apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts

Summary

Maintainability
F
3 days
Test Coverage

Function useUnlikeMutationForUser has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function useUnlikeMutationForUser(handle: string) {
    const queryClient = useQueryClient();
    const siteUrl = useSiteUrl();
    const api = createActivityPubAPI(handle, siteUrl);
    return useMutation({
Severity: Minor
Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts - About 1 hr to fix

    Function useLikeMutationForUser has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function useLikeMutationForUser(handle: string) {
        const queryClient = useQueryClient();
        const siteUrl = useSiteUrl();
        const api = createActivityPubAPI(handle, siteUrl);
        return useMutation({
    Severity: Minor
    Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts - About 1 hr to fix

      Function useUnlikeMutationForUser has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      export function useUnlikeMutationForUser(handle: string) {
          const queryClient = useQueryClient();
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useMutation({
      Severity: Minor
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts - About 45 mins to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                  if (previousInbox) {
                      // eslint-disable-next-line @typescript-eslint/no-explicit-any
                      queryClient.setQueryData([`inbox:${handle}`], (old?: any[]) => {
                          // eslint-disable-next-line @typescript-eslint/no-explicit-any
                          return old?.map((item: any) => {
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 3 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 95..112

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                  if (previousInbox) {
                      // eslint-disable-next-line @typescript-eslint/no-explicit-any
                      queryClient.setQueryData([`inbox:${handle}`], (old?: any[]) => {
                          // eslint-disable-next-line @typescript-eslint/no-explicit-any
                          return old?.map((item: any) => {
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 3 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 50..67

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 111.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

      export function useActivitiesForUser({
          handle,
          includeOwn = false,
          includeReplies = false,
          filter = null
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 190..209

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

      export function useAllActivitiesForUser({
          handle,
          includeOwn = false,
          includeReplies = false,
          filter = null
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 211..233

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 81.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useFollowersCountForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`followersCount:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 19..28
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 135..144
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 157..166
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 168..177
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 179..188

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useFollowingForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`following:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 19..28
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 135..144
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 146..155
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 157..166
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 179..188

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useFollowersForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`followers:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 19..28
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 135..144
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 146..155
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 157..166
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 168..177

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useLikedForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`liked:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 135..144
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 146..155
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 157..166
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 168..177
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 179..188

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useFollowingCountForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`followingCount:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 19..28
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 135..144
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 146..155
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 168..177
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 179..188

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 6 locations. Consider refactoring.
      Open

      export function useUserDataForUser(handle: string) {
          const siteUrl = useSiteUrl();
          const api = createActivityPubAPI(handle, siteUrl);
          return useQuery({
              queryKey: [`user:${handle}`],
      Severity: Major
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 5 other locations - About 2 hrs to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 19..28
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 146..155
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 157..166
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 168..177
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 179..188

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 80.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              queryKey: [`activities:${JSON.stringify({handle, includeOwn, includeReplies, filter})}`],
      Severity: Minor
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 30 mins to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 225..225

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 45.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              queryKey: [`activities:${JSON.stringify({handle, includeOwn, includeReplies, filter})}`],
      Severity: Minor
      Found in apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts and 1 other location - About 30 mins to fix
      apps/admin-x-activitypub/src/hooks/useActivityPubQueries.ts on lines 204..204

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 45.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status