RocketChat/Rocket.Chat

View on GitHub
packages/mock-providers/src/MockedAppRootBuilder.tsx

Summary

Maintainability
F
3 days
Test Coverage

File MockedAppRootBuilder.tsx has 427 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type { ISetting, Serialized, SettingValue } from '@rocket.chat/core-typings';
import type { ServerMethodName, ServerMethodParameters, ServerMethodReturn } from '@rocket.chat/ddp-client';
import { Emitter } from '@rocket.chat/emitter';
import languages from '@rocket.chat/i18n/dist/languages';
import type { Method, OperationParams, OperationResult, PathPattern, UrlParams } from '@rocket.chat/rest-typings';
Severity: Minor
Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 6 hrs to fix

    Function build has 124 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        build(): JSXElementConstructor<{ children: ReactNode }> {
            const queryClient = new QueryClient({
                defaultOptions: {
                    queries: { retry: false },
                    mutations: { retry: false },
    Severity: Major
    Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 4 hrs to fix

      Function build has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          build(): JSXElementConstructor<{ children: ReactNode }> {
              const queryClient = new QueryClient({
                  defaultOptions: {
                      queries: { retry: false },
                      mutations: { retry: false },
      Severity: Minor
      Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 1 hr 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

      Function withPermission has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          withPermission(permission: string): this {
              const innerFn = this.authorization.queryPermission;
      
              const outerFn = (
                  innerPermission: string | ObjectId,
      Severity: Minor
      Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 1 hr to fix

        Function reduceTranslation has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                const reduceTranslation = (translation?: ContextType<typeof TranslationContext>): ContextType<typeof TranslationContext> => {
                    return {
                        ...translation,
                        language: i18n.isInitialized ? i18n.language : 'en',
                        languages: [
        Severity: Minor
        Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 1 hr to fix

          Function withPermission has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              withPermission(permission: string): this {
                  const innerFn = this.authorization.queryPermission;
          
                  const outerFn = (
                      innerPermission: string | ObjectId,
          Severity: Minor
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx - About 25 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

                  const outerFn2 = (
                      innerPermissions: Array<string | ObjectId>,
                      innerScope?: string | ObjectId | undefined,
                      innerScopedRoles?: string[] | undefined,
                  ): [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => boolean] => {
          Severity: Major
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 4 hrs to fix
          packages/mock-providers/src/MockedAppRootBuilder.tsx on lines 219..229

          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 128.

          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

                  const outerFn3 = (
                      innerPermissions: Array<string | ObjectId>,
                      innerScope?: string | ObjectId | undefined,
                      innerScopedRoles?: string[] | undefined,
                  ): [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => boolean] => {
          Severity: Major
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 4 hrs to fix
          packages/mock-providers/src/MockedAppRootBuilder.tsx on lines 203..213

          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 128.

          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

              private settings: Mutable<ContextType<typeof SettingsContext>> = {
                  hasPrivateAccess: true,
                  isLoading: false,
                  querySetting: (_id: string) => [() => () => undefined, () => undefined],
                  querySettings: () => [() => () => undefined, () => []],
          Severity: Major
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 1 hr to fix
          packages/mock-providers/src/MockedSettingsContext.tsx on lines 6..12

          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 66.

          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

                  const outerFn = <TMethod extends Method, TPathPattern extends PathPattern>(args: {
                      method: TMethod;
                      pathPattern: TPathPattern;
                      keys: UrlParams<TPathPattern>;
                      params: OperationParams<TMethod, TPathPattern>;
          Severity: Major
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 1 hr to fix
          packages/mock-providers/src/MockedServerContext.tsx on lines 38..53

          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 58.

          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

                  const outerFn = (
                      innerSetting: string,
                  ): [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => ISetting | undefined] => {
                      if (innerSetting === id) {
                          return [() => () => undefined, () => setting];
          Severity: Minor
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 30 mins to fix
          packages/mock-providers/src/MockedAppRootBuilder.tsx on lines 312..321

          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

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

                  const outerFn = <T,>(
                      key: string | ObjectId,
                      defaultValue?: T | undefined,
                  ): [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => T | undefined] => {
                      if (key === id) {
          Severity: Minor
          Found in packages/mock-providers/src/MockedAppRootBuilder.tsx and 1 other location - About 30 mins to fix
          packages/mock-providers/src/MockedAppRootBuilder.tsx on lines 294..302

          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