Kentico/gatsby-source-kontent

View on GitHub

Showing 25 of 80 total issues

Function handleIncomingWebhook has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
Open

const handleIncomingWebhook = async (
  api: SourceNodesArgs,
  pluginConfig: CustomPluginOptions,
  itemTypes: string[],
): Promise<void> => {
Severity: Minor
Found in packages/gatsby-source/src/webhookProcessor.ts - About 4 hrs 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 getKontentItemsSchemaNamingConfiguration has 85 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const getKontentItemsSchemaNamingConfiguration = (
  config: PluginNamingConfiguration = defaultPluginNamingConfiguration,
): string => {
  return (
    ItemsSchemaTemplate
Severity: Major
Found in packages/gatsby-source/src/naming.ts - About 3 hrs to fix

    Function ComplexMenu has 73 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const ComplexMenu = () => {
      const data = useStaticQuery(graphql`
        {
          kontentItemNavigationItem(
            system: { codename: { eq: "website_root_navigation" } }
    Severity: Major
    Found in examples/navigation/src/components/complex-menu.js - About 2 hrs to fix

      Function handleDeleteItem has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

      const handleDeleteItem = async (
        api: SourceNodesArgs,
        pluginConfig: CustomPluginOptions
      ): Promise<string[]> => {
      
      Severity: Minor
      Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs 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 handleIncomingWebhook has 70 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const handleIncomingWebhook = async (
        api: SourceNodesArgs,
        pluginConfig: CustomPluginOptions,
        itemTypes: string[],
      ): Promise<void> => {
      Severity: Major
      Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs to fix

        Function handleDeleteItem has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const handleDeleteItem = async (
          api: SourceNodesArgs,
          pluginConfig: CustomPluginOptions
        ): Promise<string[]> => {
        
        Severity: Major
        Found in packages/gatsby-source/src/webhookProcessor.ts - About 2 hrs to fix

          Function linkLanguageVariants has 57 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const linkLanguageVariants = (api, typeCodename) => {
            const {
              actions: { createTypes },
              schema,
            } = api
          Severity: Major
          Found in examples/relationships/example-languages-variants.js - About 2 hrs to fix

            Function createSchemaCustomization has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            exports.createSchemaCustomization = async api => {
              const {
                actions: { createTypes },
                schema,
              } = api
            Severity: Minor
            Found in examples/navigation/gatsby-node.js - About 1 hr to fix

              Function Articles has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const Articles = (props) => {
                const { data } = props;
                const articles = data.allKontentItemArticle.group.map(articleItem => {
                  const variants = articleItem
                    .nodes
              Severity: Minor
              Found in site/src/pages/articles.js - About 1 hr to fix

                Function createSchemaCustomization has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                const createSchemaCustomization = async (
                  api: CreateSchemaCustomizationArgs,
                  pluginConfig: CustomPluginOptions,
                ): Promise<void> => {
                  // TODO check https://github.com/gatsbyjs/gatsby/pull/14610/files/5c50c435ab49884b6d854cd07f20efd95d1e5f52#diff-29de3acf9ce1010435f2b2f0043dba8cR252
                Severity: Minor
                Found in packages/gatsby-source/src/createSchemaCustomization.items.ts - About 1 hr to fix

                  Function resolve has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          resolve: async (source, _args, context, _info) => {
                            const pluginInfo = await context.nodeModel.findOne({
                              query: {
                                filter: {
                                  name: {
                  Severity: Minor
                  Found in examples/relationships/example-languages-variants.js - About 1 hr to fix

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

                    export async function getServerData(context) {
                      try {
                        const response = await fetch(`https://graphql.kontent.ai/${projectId}`, {
                          method: "POST",
                    

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

                        const articles = data.allKontentItemArticle.group.map(articleItem => {
                          const variants = articleItem
                            .nodes
                            .sort((a, b) => a.preferred_language < b.preferred_language ? 1 : -1)
                            .map(variant => {
                      Severity: Minor
                      Found in site/src/pages/articles.js - About 1 hr to fix

                        Function resolve has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            async resolve(
                              source: { value?: string[]; modular_content?: string[]; type: string },
                              _args: unknown,
                              // eslint-disable-next-line @typescript-eslint/no-explicit-any
                              context: any,
                        Severity: Minor
                        Found in packages/gatsby-source/src/createSchemaCustomization.items.ts - About 1 hr to fix

                          Function linkUsedByContentItems has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          const linkUsedByContentItems = (
                            api,
                            parentTypeCodename,
                            childTypeCodename,
                            linkedElementCodename,
                          Severity: Minor
                          Found in examples/relationships/example-used-by-content-item-link.js - About 1 hr to fix

                            Function replaceNode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                            const replaceNode = (
                              domNode: Element,
                              linkedItems: any[] | undefined,
                              resolveLinkedItem: Function | undefined,
                              images: any[] | undefined,
                            Severity: Minor
                            Found in packages/gatsby-components/src/rich-text-element/index.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 replaceNode has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            const replaceNode = (
                              domNode: Element,
                              linkedItems: any[] | undefined,
                              resolveLinkedItem: Function | undefined,
                              images: any[] | undefined,
                            Severity: Minor
                            Found in packages/gatsby-components/src/rich-text-element/index.tsx - About 1 hr to fix

                              Function loadAllKontentItems has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              const loadAllKontentItems = async (
                                config: CustomPluginOptions,
                                language: string,
                              ): Promise<KontentItemInput[]> => {
                                let continuationToken = '';
                              Severity: Minor
                              Found in packages/gatsby-source/src/client.ts - About 1 hr to fix

                                Consider simplifying this complex logical expression.
                                Open

                                  else if ((api.webhookBody as IWebhookWorkflowResponse)?.message?.api_name === "content_management") {
                                    const parsedBody = api.webhookBody as IWebhookWorkflowResponse;
                                
                                    const isCorrectStructure = parsedBody?.data?.items?.every(item => item.language && item.transition_from && item.transition_to && item.item.id)
                                      && parsedBody?.message?.api_name
                                Severity: Major
                                Found in packages/gatsby-source/src/webhookProcessor.ts - About 1 hr to fix

                                  Function handleUpsertItem has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                  const handleUpsertItem = async (
                                    api: SourceNodesArgs,
                                    pluginConfig: CustomPluginOptions,
                                    itemId: string,
                                    itemLanguage?: string,
                                  Severity: Minor
                                  Found in packages/gatsby-source/src/webhookProcessor.ts - About 55 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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language