digitalheir/rechtspraak-js

View on GitHub

Showing 24 of 24 total issues

Function xmlToJson has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

export function xmlToJson(parent: Node, depth: number = 0): any {
    // Create the return object
    let obj: any = {}; // TODO formalize type?

    if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
Severity: Minor
Found in src/model/json-ld/to-json-ld.ts - About 7 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

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

export function throwIfNotDateTime(str: any, extra?: string, ...extras: string[]): DateTime {
    if (typeof str === "string") {
        const trimmed = str.trim();
        if (isDateTime(trimmed))
            return trimmed;
Severity: Major
Found in src/util/validations.ts and 1 other location - About 4 hrs to fix
src/util/validations.ts on lines 63..70

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

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

export function throwIfNotDate(str: any, extra?: string, ...extras: string[]): Date {
    if (typeof str === "string") {
        const trimmed = str.trim();
        if (isDate(trimmed)) return trimmed;
    }
Severity: Major
Found in src/util/validations.ts and 1 other location - About 4 hrs to fix
src/util/validations.ts on lines 85..92

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

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 refineMetadata2 has 107 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function refineMetadata2(meta: any): RechtspraakMetadata {
    if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");


    const _id = throwIfNotString(meta["dcterms:identifier"]);
Severity: Major
Found in src/model/convert-to-typed.ts - About 4 hrs to fix

    Function xmlToJson has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function xmlToJson(parent: Node, depth: number = 0): any {
        // Create the return object
        let obj: any = {}; // TODO formalize type?
    
        if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
    Severity: Major
    Found in src/model/json-ld/to-json-ld.ts - About 3 hrs to fix

      Function mergeDescriptionTags has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function mergeDescriptionTags(rdf: any) {
          let description = rdf["rdf:Description"];
          if (Object.prototype.toString.call(description) !== "[object Array]") description = [description, {}];
          if (description.length !== 2) throw new Error("Expected 2 descriptions");
          const description0 = description[0];
      Severity: Major
      Found in src/model/convert-to-typed.ts - About 3 hrs to fix

        Function refineMetadata2 has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        function refineMetadata2(meta: any): RechtspraakMetadata {
            if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");
        
        
            const _id = throwIfNotString(meta["dcterms:identifier"]);
        Severity: Minor
        Found in src/model/convert-to-typed.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

        File convert-to-typed.ts has 260 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import {
            Creator,
            Date,
            RechtspraakMetadata,
            UriWithProtocol
        Severity: Minor
        Found in src/model/convert-to-typed.ts - About 2 hrs to fix

          Function resourceObject has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function resourceObject(idIsUri = true,
                                  hasLabels = true,
                                  extraMandatoryProperties: any = {}, // todo
                                  extraOptionalProperties: any = {} // todo
          ): SchemaTypeDefinition {
          Severity: Minor
          Found in src/model/json-ld/schema/resource-object.ts - About 1 hr to fix

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

                    if (isGevolg(id)) {
                        const id0: Gevolg = id;
                        const contextLabel: string = gevolgTypes[id0]["rdfs:label"][0]["@value"];
                        if (!contextLabel) throw new Error("Expected label for " + id);
            
            
            Severity: Major
            Found in src/model/fields/relation.ts and 1 other location - About 1 hr to fix
            src/model/fields/relation.ts on lines 60..69

            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

                if (isRelationType(shortId)) {
                    const type: RelationType = shortId;
            
                    const contextLabel: string = _context[type]["rdfs:label"][0]["@value"];
                    if (!contextLabel) throw new Error("Expected label for " + type);
            Severity: Major
            Found in src/model/fields/relation.ts and 1 other location - About 1 hr to fix
            src/model/fields/relation.ts on lines 41..47

            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 getResourceId has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

            export function getResourceId(attrz: any/*todo*/, key?: string): string {
                if (!attrz)
                    throw new Error("No attributes found!" + (key ? " (" + key + ")" : ""));
                if (attrz["resourceIdentifier"])
                    if (!!attrz["psi:resourceIdentifier"])
            Severity: Minor
            Found in src/model/convert-to-typed.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 getGevolg has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function getGevolg(gevolgUri?: string, label?: string): Gevolg | undefined {
                if (!gevolgUri)
                    return undefined;
                else {
                    const id = gevolgUri.replace(/^http:\/\/psi\.rechtspraak\.nl\//, "");
            Severity: Minor
            Found in src/model/fields/relation.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

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

                if (typeof str === "string") return str.trim();
                else throw new Error("Expected " + JSON.stringify(str) + " to be a string. (" + extra + ")" + (extras.length ? " " + extras : ""));
            Severity: Minor
            Found in src/util/validations.ts and 1 other location - About 45 mins to fix
            src/util/validations.ts on lines 95..96

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

            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

            Avoid deeply nested control flow statements.
            Open

                                    if (typeof(obj[childNodeName]) === "undefined") {
                                        // child doesn't exist yet
                                        obj[childNodeName] = xmlToJson(item, depth + 1);
                                    } else {
                                        // Add child to array
            Severity: Major
            Found in src/model/json-ld/to-json-ld.ts - About 45 mins to fix

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

              export const getRelation = (arr: any[]): Relation[] | undefined => arr ? arr.map((rel: any) => {
                  const attrs = [
                      "rdfs:label",
                      ["ecli:resourceIdentifier"/*, "bwb:resourceIdentifier"*/],
                      "psi:type",
              Severity: Minor
              Found in src/model/fields/relation.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

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

                  if (isUriWithProtocol(str)) return str.trim();
                  else throw new Error("Expected " + JSON.stringify(str) + " to be a uri. (" + extra + ")" + (extras.length ? " " + extras : ""));
              Severity: Minor
              Found in src/util/validations.ts and 1 other location - About 45 mins to fix
              src/util/validations.ts on lines 59..60

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

              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

              Avoid deeply nested control flow statements.
              Open

                                      if (!!item.textContent)
                                          obj.textContent = item.textContent.trim().replace(/\s\s+/g, " ");
              Severity: Major
              Found in src/model/json-ld/to-json-ld.ts - About 45 mins to fix

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

                export function idResourceNoUriCheck(id: string, ...labels: Label[]): StandardResourceObject {
                    return makeIdResourceFunction(false)(id, ...labels);
                }
                Severity: Minor
                Found in src/model/fields/standard-resource-object.ts and 1 other location - About 35 mins to fix
                src/model/fields/standard-resource-object.ts on lines 16..18

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

                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

                export function idResource(id: string, ...labels: Label[]): StandardResourceObject {
                    return makeIdResourceFunction(true)(id, ...labels);
                }
                Severity: Minor
                Found in src/model/fields/standard-resource-object.ts and 1 other location - About 35 mins to fix
                src/model/fields/standard-resource-object.ts on lines 13..15

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

                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

                Severity
                Category
                Status
                Source
                Language