RocketChat/Rocket.Chat

View on GitHub
apps/meteor/app/oembed/server/server.ts

Summary

Maintainability
D
2 days
Test Coverage

File server.ts has 293 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import type {
    OEmbedUrlContentResult,
    OEmbedUrlWithMetadata,
    IMessage,
    MessageAttachment,
Severity: Minor
Found in apps/meteor/app/oembed/server/server.ts - About 3 hrs to fix

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

    const getUrlMeta = async function (
        url: string,
        withFragment?: boolean,
    ): Promise<OEmbedUrlWithMetadata | OEmbedUrlContentResult | undefined> {
        log.debug('Obtaining metadata for URL', url);
    Severity: Major
    Found in apps/meteor/app/oembed/server/server.ts - About 2 hrs to fix

      Function getUrlContent has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      const getUrlContent = async (urlObj: URL, redirectCount = 5): Promise<OEmbedUrlContentResult> => {
          const portsProtocol = new Map<string, string>(
              Object.entries({
                  80: 'http:',
                  8080: 'http:',
      Severity: Major
      Found in apps/meteor/app/oembed/server/server.ts - About 2 hrs to fix

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

        const getUrlMeta = async function (
            url: string,
            withFragment?: boolean,
        ): Promise<OEmbedUrlWithMetadata | OEmbedUrlContentResult | undefined> {
            log.debug('Obtaining metadata for URL', url);
        Severity: Minor
        Found in apps/meteor/app/oembed/server/server.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 rocketUrlParser has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const rocketUrlParser = async function (message: IMessage): Promise<IMessage> {
            log.debug('Parsing message URLs');
        
            if (!Array.isArray(message.urls)) {
                return message;
        Severity: Minor
        Found in apps/meteor/app/oembed/server/server.ts - About 1 hr to fix

          Function parseUrl has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const parseUrl = async function (url: string): Promise<{ urlPreview: MessageUrl; foundMeta: boolean }> {
              const parsedUrlObject: MessageUrl = { url, meta: {} };
              let foundMeta = false;
              if (!isURL(url)) {
                  return { urlPreview: parsedUrlObject, foundMeta };
          Severity: Minor
          Found in apps/meteor/app/oembed/server/server.ts - About 1 hr to fix

            Function getCharset has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const getCharset = function (contentType: string, body: Buffer): string {
                let detectedCharset;
                let httpHeaderCharset;
                let htmlMetaCharset;
                let result;
            Severity: Minor
            Found in apps/meteor/app/oembed/server/server.ts - About 1 hr to fix

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

              const getCharset = function (contentType: string, body: Buffer): string {
                  let detectedCharset;
                  let httpHeaderCharset;
                  let htmlMetaCharset;
                  let result;
              Severity: Minor
              Found in apps/meteor/app/oembed/server/server.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 getUrlContent has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              const getUrlContent = async (urlObj: URL, redirectCount = 5): Promise<OEmbedUrlContentResult> => {
                  const portsProtocol = new Map<string, string>(
                      Object.entries({
                          80: 'http:',
                          8080: 'http:',
              Severity: Minor
              Found in apps/meteor/app/oembed/server/server.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 rocketUrlParser has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

              const rocketUrlParser = async function (message: IMessage): Promise<IMessage> {
                  log.debug('Parsing message URLs');
              
                  if (!Array.isArray(message.urls)) {
                      return message;
              Severity: Minor
              Found in apps/meteor/app/oembed/server/server.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 parseUrl has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              const parseUrl = async function (url: string): Promise<{ urlPreview: MessageUrl; foundMeta: boolean }> {
                  const parsedUrlObject: MessageUrl = { url, meta: {} };
                  let foundMeta = false;
                  if (!isURL(url)) {
                      return { urlPreview: parsedUrlObject, foundMeta };
              Severity: Minor
              Found in apps/meteor/app/oembed/server/server.ts - About 45 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

              There are no issues that match your filters.

              Category
              Status