CocoonIO/cocoon-xml-sugar

View on GitHub

Showing 43 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

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

            public getCocoonPlatform(platform: Platform): Element {
                const filter = {
                    attributes: [
                        {name: "name", value: platform},
                    ],
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 542..550

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

        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

            public getCocoonEngine(platform: Platform): Element {
                const filter = {
                    attributes: [
                        {name: "name", value: platform},
                    ],
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 508..516

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

        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

            private static encode(str: string): string {
                if (!str) {
                    return str;
                }
                return str.replace(/&/g, "&amp;")
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 28..37

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

        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

            private static decode(str: string): string {
                if (!str) {
                    return str;
                }
                return str.replace(/&apos;/g, "\"")
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 17..26

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

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

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

                    } else if (value === Environment.WEBVIEW_PLUS) {
                        info = webviewplusPlugins[name];
                        if (info) {
                            this.addPlugin(info.plugin);
                            this.removePlugin(canvasplusPlugins[name].plugin);
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 676..697

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

        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

                    if (value === Environment.CANVAS_PLUS) {
                        info = canvasplusPlugins[name];
                        if (info) {
                            this.addPlugin(info.plugin);
                            this.removePlugin(webviewplusPlugins[name].plugin);
        Severity: Major
        Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
        src/lib/xml-sugar.ts on lines 682..697

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

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

            Severity
            Category
            Status
            Source
            Language