orlowdev/gatsby-source-notion-api

View on GitHub

Showing 22 of 22 total issues

Function notionBlockToMarkdown has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

exports.notionBlockToMarkdown = (block, lowerTitleLevel) => {
    // Get the child content of the block.
    let childMarkdown = (block.children ?? [])
        .map((block) => this.notionBlockToMarkdown(block, lowerTitleLevel))
        .join("")
Severity: Minor
Found in src/transformers/notion-block-to-markdown.js - 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 notionBlockToMarkdown has 102 lines of code (exceeds 25 allowed). Consider refactoring.
Open

exports.notionBlockToMarkdown = (block, lowerTitleLevel) => {
    // Get the child content of the block.
    let childMarkdown = (block.children ?? [])
        .map((block) => this.notionBlockToMarkdown(block, lowerTitleLevel))
        .join("")
Severity: Major
Found in src/transformers/notion-block-to-markdown.js - About 4 hrs to fix

    Function blockToString has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.blockToString = (textBlocks) =>
        textBlocks.reduce((text, textBlock) => {
            const data = {
                ...textBlock.text,
                ...textBlock.annotations,
    Severity: Minor
    Found in src/block-to-string.js - 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 getBlocks has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.getBlocks = async ({ id, notionVersion, token }, reporter) => {
        let hasMore = true
        let blockContent = []
        let startCursor = ""
    
    
    Severity: Minor
    Found in src/notion-api/get-blocks.js - 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

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

            const audioUrl = block.audio.type == "external" ? block.audio.external.url : block.audio.file.url
    Severity: Minor
    Found in src/transformers/notion-block-to-markdown.js and 1 other location - About 40 mins to fix
    src/transformers/notion-block-to-markdown.js on lines 99..99

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

    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 imageUrl = block.image.type == "external" ? block.image.external.url : block.image.file.url
    Severity: Minor
    Found in src/transformers/notion-block-to-markdown.js and 1 other location - About 40 mins to fix
    src/transformers/notion-block-to-markdown.js on lines 105..105

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

    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

    Function getPages has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

    exports.getPages = async ({ token, databaseId, notionVersion = "2021-05-13" }, reporter, cache) => {
        let hasMore = true
        let startCursor = ""
        const url = `https://api.notion.com/v1/databases/${databaseId}/query`
        const body = {
    Severity: Minor
    Found in src/notion-api/get-pages.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

    Avoid too many return statements within this function.
    Open

            return prependToLines(markdown, "1.").concat(EOL_MD)
    Severity: Major
    Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return [
                  EOL_MD,
                  "<details><summary>",
                  blockMarkdown,
                  "</summary>",
      Severity: Major
      Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return prependToLines(markdown, symbol).concat(EOL_MD)
        Severity: Major
        Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

                  return [
                      EOL_MD,
                      `\`\`\` ${block.code.language}${EOL_MD}`,
                      blockMarkdown,
                      EOL_MD,
          Severity: Major
          Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return [EOL_MD, block.embed.url, EOL_MD].join("")
            Severity: Major
            Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return `${EOL_MD}---${EOL_MD}`
              Severity: Major
              Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                        return [
                            EOL_MD,
                            "<ColumnList>",
                            EOL_MD,
                            markdown,
                Severity: Major
                Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return `${EOL_MD}![${blockToString(block.image.caption)}](${imageUrl})${EOL_MD}`
                  Severity: Major
                  Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return [EOL_MD, "<audio controls>", `<source src="${audioUrl}" />`, "</audio>", EOL_MD].join("")
                    Severity: Major
                    Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                          return [EOL_MD, `<!-- This block type '${block.type}' is not supported yet. -->`, EOL_MD].join("")
                      Severity: Major
                      Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                return [EOL_MD, block.video.external.url, EOL_MD].join("")
                        Severity: Major
                        Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return `${EOL_MD}[${bookmarkCaption}](${bookmarkUrl})${EOL_MD}`
                          Severity: Major
                          Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix

                            Avoid too many return statements within this function.
                            Open

                                    return prependToLines(markdown, "*").concat(EOL_MD)
                            Severity: Major
                            Found in src/transformers/notion-block-to-markdown.js - About 30 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language