pankod/refine

View on GitHub

Showing 812 of 823 total issues

Function OnboardingForm has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

const OnboardingForm = () => {
  const [loading, setLoading] = React.useState(false);
  const { handleSubmit, control, setValue, setError, formState } =
    useForm<MeUpdateVariables>({
      defaultValues: {
Severity: Minor
Found in packages/devtools-ui/src/pages/onboarding.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 normalizeData has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

export const normalizeData = (data: any): any => {
  if (Array.isArray(data)) {
    return data.map((item) => normalizeData(item));
  }

Severity: Minor
Found in packages/strapi-v4/src/utils/normalizeData.ts - 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 useResourceParams has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

export function useResourceParams(props?: Props): ResourceParams {
  const { select, identifier: inferredIdentifier } = useResource();
  const resourceToCheck = props?.resource ?? inferredIdentifier;
  const { identifier = undefined, resource = undefined } = resourceToCheck
    ? select(resourceToCheck, true)
Severity: Minor
Found in packages/core/src/hooks/use-resource-params/index.ts - 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 booleanFields has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  const booleanFields = (field: InferField) => {
    if (field.type === "boolean") {
      if (field.multiple) {
        return undefined;
      }
Severity: Minor
Found in packages/inferencer/src/inferencers/headless/create.tsx - About 1 hr to fix

    Function printImports has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export const printImports = (imports: Array<ImportElement>) => {
      const byModule = imports.reduce(
        (acc, [element, module, isDefault]) => {
          if (!acc[module]) {
            acc[module] = [] as Array<
    Severity: Minor
    Found in packages/inferencer/src/utilities/print-imports/index.ts - About 1 hr to fix

      Function urlFields has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        const urlFields = (field: InferField) => {
          if (field.type === "url") {
            imports.push(
              ["UrlField", "@refinedev/antd"],
              ["TagField", "@refinedev/antd"],
      Severity: Minor
      Found in packages/inferencer/src/inferencers/antd/list.tsx - About 1 hr to fix

        Function emailFields has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const emailFields = (field: InferField) => {
            if (field.type === "email") {
              imports.push(
                ["TagField", "@refinedev/antd"],
                ["EmailField", "@refinedev/antd"],
        Severity: Minor
        Found in packages/inferencer/src/inferencers/antd/list.tsx - About 1 hr to fix

          Function useGo has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export const useGo = () => {
            const routerContext = useContext(RouterContext);
            const { select: resourceSelect } = useResource();
            const getToPath = useGetToPath();
          
          
          Severity: Minor
          Found in packages/core/src/hooks/router/use-go/index.tsx - About 1 hr to fix

            Function getAllVersionsOfPackage has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export const getAllVersionsOfPackage = async (
              packageName: string,
            ): Promise<string[]> => {
              const pm = "npm";
            
            
            Severity: Minor
            Found in packages/cli/src/utils/package/index.ts - About 1 hr to fix

              Function printFiles has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                const printFiles = () => {
                  const chalks = [];
              
                  chalks.push(chalk.dim(`File${files.length > 1 ? "s" : ""} created:`));
                  chalks.push(
              Severity: Minor
              Found in packages/cli/src/components/swizzle-message/index.tsx - About 1 hr to fix

                Function useGetToPath has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export const useGetToPath = (): GetToPathFn => {
                  const routerType = useRouterType();
                  const { resource: resourceFromRoute, resources } = useResource();
                  const parsed = useParsed();
                
                
                Severity: Minor
                Found in packages/core/src/hooks/router/use-get-to-path/index.ts - About 1 hr to fix

                  Function queryKeys has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export const queryKeys = (
                    resource?: string,
                    dataProviderName?: string,
                    meta?: MetaQuery,
                    /**
                  Severity: Minor
                  Found in packages/core/src/definitions/helpers/queryKeys/index.ts - About 1 hr to fix

                    Function useResourceParams has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export function useResourceParams(props?: Props): ResourceParams {
                      const { select, identifier: inferredIdentifier } = useResource();
                      const resourceToCheck = props?.resource ?? inferredIdentifier;
                      const { identifier = undefined, resource = undefined } = resourceToCheck
                        ? select(resourceToCheck, true)
                    Severity: Minor
                    Found in packages/core/src/hooks/use-resource-params/index.ts - About 1 hr to fix

                      Function assertDocumentTitle has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      export const assertDocumentTitle = (resource: string, action?: IAction) => {
                        switch (action) {
                          case "list":
                            cy.document()
                              .its("title")
                      Severity: Minor
                      Found in cypress/support/commands/document-title-handler.ts - About 1 hr to fix

                        Function textFields has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          const textFields = (field: InferField) => {
                            if (
                              field.type === "text" ||
                              field.type === "email" ||
                              field.type === "date" ||
                        Severity: Minor
                        Found in packages/inferencer/src/inferencers/mantine/create.tsx - About 1 hr to fix

                          Function relationHooksCode has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              .map((field) => {
                                if (field?.relation && !field.fieldable && field.resource) {
                                  imports.push(["useAutocomplete", "@refinedev/mui"]);
                                  let val = accessor(recordName, field.key, field.accessor, false);
                          
                          
                          Severity: Minor
                          Found in packages/inferencer/src/inferencers/mui/edit.tsx - About 1 hr to fix

                            Function useRefreshButton has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            export function useRefreshButton(
                              props: RefreshButtonProps,
                            ): RefreshButtonValues {
                              const translate = useTranslate();
                              const { keys, preferLegacyKeys } = useKeys();
                            Severity: Minor
                            Found in packages/core/src/hooks/button/refresh-button/index.tsx - About 1 hr to fix

                              Function useRedirectionAfterSubmission has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                () => {
                                  const { show, edit, list, create } = useNavigation();
                              
                                  const handleSubmitWithRedirect = useCallback(
                                    ({
                              Severity: Minor
                              Found in packages/core/src/hooks/redirection/index.ts - About 1 hr to fix

                                Function UnsavedPrompt has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                const UnsavedPrompt: React.FC = () => {
                                  const { Prompt } = useRouterContext();
                                
                                  const translate = useTranslate();
                                
                                
                                Severity: Minor
                                Found in packages/core/src/components/layoutWrapper/index.tsx - About 1 hr to fix

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

                                  export type UseSiderVisibleType = {
                                    siderVisible: boolean;
                                    drawerSiderVisible: boolean;
                                    setSiderVisible: (visible: boolean) => void;
                                    setDrawerSiderVisible: (visible: boolean) => void;
                                  Severity: Major
                                  Found in packages/antd/src/hooks/useSiderVisible/index.ts and 3 other locations - About 1 hr to fix
                                  packages/chakra-ui/src/hooks/useSiderVisible/index.ts on lines 5..10
                                  packages/mantine/src/hooks/useSiderVisible/index.ts on lines 5..10
                                  packages/mui/src/hooks/useSiderVisible/index.ts on lines 5..10

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

                                  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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language