CocoonIO/cocoon-xml-sugar

View on GitHub

Showing 22 of 43 total issues

File xml-sugar.ts has 548 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

import * as detectNode from "detect-node";
import * as xmldom from "xmldom";

Severity: Major
Found in src/lib/xml-sugar.ts - About 1 day to fix

    XMLSugar has 55 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class XMLSugar {
        private static encode(str: string): string {
            if (!str) {
                return str;
            }
    Severity: Major
    Found in src/lib/xml-sugar.ts - About 7 hrs to fix

      Function setEnvironment has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public setEnvironment(value: Environment, platform?: Platform) {
              const names = platform ? [platform] : ["android", "ios"];
      
              for (const name of names) {
                  let info: any;
      Severity: Minor
      Found in src/lib/xml-sugar.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 formatXml has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public static formatXml(xml: string): string {
              const reg: RegExp = /(>)\s*(<)(\/*)/g;
              const wsexp: RegExp = / *(.*) +\n/g;
              const contexp: RegExp = /(<.+>)(.+\n)/g;
              xml = xml.replace(reg, "$1\n$2$3").replace(wsexp, "$1\n").replace(contexp, "$1\n$2");
      Severity: Minor
      Found in src/lib/utils.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 formatXml has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static formatXml(xml: string): string {
              const reg: RegExp = /(>)\s*(<)(\/*)/g;
              const wsexp: RegExp = / *(.*) +\n/g;
              const contexp: RegExp = /(<.+>)(.+\n)/g;
              xml = xml.replace(reg, "$1\n$2$3").replace(wsexp, "$1\n").replace(contexp, "$1\n$2");
      Severity: Minor
      Found in src/lib/utils.ts - About 1 hr to fix

        Function getEnvironment has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

            public getEnvironment(platform?: Platform): Environment {
                if (!platform) {
                    const environments = [this.getEnvironment(Platform.IOS), this.getEnvironment(Platform.Android)];
                    for (let j = 1; j < environments.length; ++j) {
                        if (environments[j] !== environments[j - 1]) {
        Severity: Minor
        Found in src/lib/xml-sugar.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 matchesFilter has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            private static matchesFilter(sugar: XMLSugar, node: Element, filter: any) {
                const parent = node.parentNode as Element;
                if (filter.parent) {
                    if (parent.getAttribute && parent.getAttribute("name") !== filter.parent) {
                        return false;
        Severity: Minor
        Found in src/lib/xml-dom.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 removeNode has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            public static removeNode(sugar: XMLSugar, filter: any) {
                const node = XMLDOM.findNode(sugar, filter);
                if (node && node.parentNode) {
                    const parent = node.parentNode as Element;
                    parent.removeChild(node);
        Severity: Minor
        Found in src/lib/xml-dom.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 replaceOldPluginSyntax has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            private static replaceOldPluginSyntax(doc: Document): Document {
                const plugins = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "plugin"));
        
                for (const plugin of plugins) {
                    const pluginEle = doc.createElementNS(null, "plugin");
        Severity: Minor
        Found in src/lib/xml-sugar.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 replaceOldPlatformSyntax has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            private static replaceOldPlatformSyntax(doc: Document): Document {
                const platforms = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "platform"));
        
                for (const platform of platforms) {
                    const platformEle: Element = doc.createElementNS(null, "platform");
        Severity: Minor
        Found in src/lib/xml-sugar.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 updateOrAddNode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            public static updateOrAddNode(sugar: XMLSugar, filter: any, data: any) {
                let found = XMLDOM.findNode(sugar, filter);
                if (!found) {
                    const parent = XMLDOM.parentNodeForPlatform(sugar, filter.parent);
                    found = sugar.doc.createElementNS(null, filter.tag);
        Severity: Minor
        Found in src/lib/xml-dom.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 replaceOldPlatformSyntax has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static replaceOldPlatformSyntax(doc: Document): Document {
                const platforms = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "platform"));
        
                for (const platform of platforms) {
                    const platformEle: Element = doc.createElementNS(null, "platform");
        Severity: Minor
        Found in src/lib/xml-sugar.ts - About 1 hr to fix

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

              public setEnvironment(value: Environment, platform?: Platform) {
                  const names = platform ? [platform] : ["android", "ios"];
          
                  for (const name of names) {
                      let info: any;
          Severity: Minor
          Found in src/lib/xml-sugar.ts - About 1 hr to fix

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

                public setBundleId(value: string, platform?: Platform) {
                    if (platform) {
                        const name = BundleIdAlias[platform];
                        if (name) {
                            if (value) {
            Severity: Minor
            Found in src/lib/xml-sugar.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

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

                public getVersionCode(platform?: Platform, fallback: boolean = true): string {
                    if (platform) {
                        const name = VersionCodeAlias[platform];
                        if (name) {
                            const version = this.root.getAttribute(name);
            Severity: Minor
            Found in src/lib/xml-sugar.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

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

                public addPluginVariable(pluginName: string, varName: string, varValue: string) {
                    this.addPlugin(pluginName);
                    const plugin = this.findPlugin(pluginName);
                    if (plugin) {
                        const nodes = Array.prototype.slice.call(plugin.childNodes);
            Severity: Minor
            Found in src/lib/xml-sugar.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

            Avoid deeply nested control flow statements.
            Open

                                if (!info) {
                                    continue;
                                }
            Severity: Major
            Found in src/lib/xml-sugar.ts - About 45 mins to fix

              Function setVersionCode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public setVersionCode(value: string, platform?: Platform) {
                      if (platform) {
                          const name = VersionCodeAlias[platform];
                          if (name) {
                              if (value) {
              Severity: Minor
              Found in src/lib/xml-sugar.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

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

                  public setVersion(value: string, platform?: Platform) {
                      if (platform) {
                          const name = platform + "-version";
                          if (name) {
                              if (value) {
              Severity: Minor
              Found in src/lib/xml-sugar.ts - 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 findPluginVariable has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public findPluginVariable(pluginName: string, varName: string): string {
                      const plugin = this.findPlugin(pluginName);
                      let result: string;
                      if (plugin) {
                          const nodes = Array.prototype.slice.call(plugin.childNodes);
              Severity: Minor
              Found in src/lib/xml-sugar.ts - 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

              Severity
              Category
              Status
              Source
              Language