Kentico/gatsby-source-kontent

View on GitHub

Showing 25 of 80 total issues

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

const parseKontentWebhookBody = (api: SourceNodesArgs): IWebhookDeliveryResponse | IWebhookWorkflowResponse | null => {

  if ((api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_preview" || (api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_production") {
    const parsedBody = api.webhookBody as IWebhookDeliveryResponse;
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

Consider simplifying this complex logical expression.
Open

  if ((api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_preview" || (api.webhookBody as IWebhookDeliveryResponse)?.message?.api_name === "delivery_production") {
    const parsedBody = api.webhookBody as IWebhookDeliveryResponse;

    const isCorrectStructure = parsedBody?.data?.items?.every(item => item.language && item.id)
      && parsedBody?.message?.api_name
Severity: Major
Found in packages/gatsby-source/src/webhookProcessor.ts - About 40 mins to fix

    Function Articles has a Cognitive Complexity of 7 (exceeds 5 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 35 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

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

    const getLanguageLinkExtension = (): object => ({
      name: getKontentItemLanguageLinkExtensionName(),
      extend: (): object => ({
        async resolve(
          source: { value?: string[]; modular_content?: string[]; type: string },
    Severity: Minor
    Found in packages/gatsby-source/src/createSchemaCustomization.items.ts - 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

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

    const getElementFieldsDefinitionForType = (
      type: KontentType,
    ): { [key: string]: { type: string } } => {
      const elementFields: {
        [key: string]: {
    Severity: Minor
    Found in packages/gatsby-source/src/createSchemaCustomization.items.ts - 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

    Severity
    Category
    Status
    Source
    Language