NatLibFi/marc-record-validators-melinda

View on GitHub
src/merge-fields/counterpartField.js

Summary

Maintainability
D
2 days
Test Coverage

File counterpartField.js has 457 lines of code (exceeds 250 allowed). Consider refactoring.
Open

// For each incoming field that

import createDebugLogger from 'debug';
import {fieldHasSubfield, fieldHasNSubfields, fieldHasMultipleSubfields, fieldToString, nvdebug, removeCopyright} from '../utils';
import {cloneAndNormalizeFieldForComparison, cloneAndRemovePunctuation} from '../normalizeFieldForComparison';
Severity: Minor
Found in src/merge-fields/counterpartField.js - About 7 hrs to fix

    Function splitToNameAndQualifierAndProcessName has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function splitToNameAndQualifierAndProcessName(name) {
      //const nameOnly = name.replace(/(?: \([^)]+\)| abp?| Kustannus| Kustannus Oy|, kustannusosakeyhtiö| oyj?| ry)$/ugi, '');
      const [qualifierlessName, qualifier] = splitToNameAndQualifier(name);
    
      const [prefix, basename, suffix] = stripPrefixAndSuffix(qualifierlessName);
    Severity: Minor
    Found in src/merge-fields/counterpartField.js - About 1 hr to fix

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

      function optionalSubfieldComparison(originalBaseField, originalSourceField, keySubfieldsAsString) {
        // Here "optional subfield" means a subfield, that needs not to be present, but if present, it must be identical...
        // (Think of a better name...)
        // We use clones here, since these changes done below are not intented to appear on the actual records.
        const field1 = cloneAndNormalizeFieldForComparison(originalBaseField);
      Severity: Minor
      Found in src/merge-fields/counterpartField.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

      Function optionalSubfieldComparison has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function optionalSubfieldComparison(originalBaseField, originalSourceField, keySubfieldsAsString) {
        // Here "optional subfield" means a subfield, that needs not to be present, but if present, it must be identical...
        // (Think of a better name...)
        // We use clones here, since these changes done below are not intented to appear on the actual records.
        const field1 = cloneAndNormalizeFieldForComparison(originalBaseField);
      Severity: Minor
      Found in src/merge-fields/counterpartField.js - About 1 hr to fix

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

        export function splitToNameAndQualifierAndProcessName(name) {
          //const nameOnly = name.replace(/(?: \([^)]+\)| abp?| Kustannus| Kustannus Oy|, kustannusosakeyhtiö| oyj?| ry)$/ugi, '');
          const [qualifierlessName, qualifier] = splitToNameAndQualifier(name);
        
          const [prefix, basename, suffix] = stripPrefixAndSuffix(qualifierlessName);
        Severity: Minor
        Found in src/merge-fields/counterpartField.js - 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 getCounterpart has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

        export function getCounterpart(baseRecord, sourceRecord, field, config) {
          // First get relevant candidate fields. Note that 1XX and corresponding 7XX are considered equal, and tags 260 and 264 are lumped together.
          // (<= Note that self-merge behaves differently from two records here.)
          // Hacks: 973 can merge with 773, 940 can merge with 240 (but not the other way around)
          //nvdebug(`COUNTERPART FOR '${fieldToString(field)}'?`, debugDev);
        Severity: Minor
        Found in src/merge-fields/counterpartField.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 false;
        Severity: Major
        Found in src/merge-fields/counterpartField.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

            return true;
          Severity: Major
          Found in src/merge-fields/counterpartField.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return false;
            Severity: Major
            Found in src/merge-fields/counterpartField.js - About 30 mins to fix

              Function getAlternativeNamesFrom9XX has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function getAlternativeNamesFrom9XX(record, field) {
                // Should we support 6XX and 8XX as well? Prolly not...
                if (!field.tag.match(/^(?:100|110|111|600|610|611|700|710|711)$/u)) {
                  return [];
                }
              Severity: Minor
              Found in src/merge-fields/counterpartField.js - About 25 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 syntacticallyMergablePair has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function syntacticallyMergablePair(baseField, sourceField, config) {
                // Indicators must typically be equal (there are exceptions such as non-filing characters though):
                if (!mergableIndicator1(baseField, sourceField, config)) {
                  nvdebug(`non-mergable (reason: indicator1): ${JSON.stringify(config)}`, debugDev);
                  return false;
              Severity: Minor
              Found in src/merge-fields/counterpartField.js - About 25 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 4 locations. Consider refactoring.
              Open

                  const subfields2 = field2.subfields.filter(subfield => subfield.code === subfieldCode && valueCarriesMeaning(field2.tag, subfield.code, subfield.value));
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 3 other locations - About 50 mins to fix
              src/merge-fields/counterpartField.js on lines 250..250
              src/merge-fields/counterpartField.js on lines 258..258
              src/merge-fields/counterpartField.js on lines 259..259

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

              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 4 locations. Consider refactoring.
              Open

                  const subfields2 = field2.subfields.filter(subfield => subfield.code === subfieldCode && valueCarriesMeaning(field2.tag, subfield.code, subfield.value));
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 3 other locations - About 50 mins to fix
              src/merge-fields/counterpartField.js on lines 250..250
              src/merge-fields/counterpartField.js on lines 251..251
              src/merge-fields/counterpartField.js on lines 258..258

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

              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 4 locations. Consider refactoring.
              Open

                  const subfields1 = field1.subfields.filter(subfield => subfield.code === subfieldCode && valueCarriesMeaning(field1.tag, subfield.code, subfield.value));
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 3 other locations - About 50 mins to fix
              src/merge-fields/counterpartField.js on lines 250..250
              src/merge-fields/counterpartField.js on lines 251..251
              src/merge-fields/counterpartField.js on lines 259..259

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

              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 4 locations. Consider refactoring.
              Open

                  const subfields1 = field1.subfields.filter(subfield => subfield.code === subfieldCode && valueCarriesMeaning(field1.tag, subfield.code, subfield.value));
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 3 other locations - About 50 mins to fix
              src/merge-fields/counterpartField.js on lines 251..251
              src/merge-fields/counterpartField.js on lines 258..258
              src/merge-fields/counterpartField.js on lines 259..259

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

              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 3 locations. Consider refactoring.
              Open

                const [name] = punctuationlessField.subfields.filter(sf => sf.code === 'a').map(sf => sf.value);
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 2 other locations - About 40 mins to fix
              src/merge-fields/counterpartField.js on lines 605..605
              src/merge-fields/counterpartField.js on lines 606..606

              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 3 locations. Consider refactoring.
              Open

                  const [altY] = altField.subfields.filter(sf => sf.code === 'y').map(sf => sf.value);
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 2 other locations - About 40 mins to fix
              src/merge-fields/counterpartField.js on lines 599..599
              src/merge-fields/counterpartField.js on lines 605..605

              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 3 locations. Consider refactoring.
              Open

                  const [altA] = altField.subfields.filter(sf => sf.code === 'a').map(sf => sf.value);
              Severity: Major
              Found in src/merge-fields/counterpartField.js and 2 other locations - About 40 mins to fix
              src/merge-fields/counterpartField.js on lines 599..599
              src/merge-fields/counterpartField.js on lines 606..606

              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 subfieldValues2 = field2.subfields.filter(subfield => subfield.code === subfieldCode).map(sf => sf.value);
              Severity: Minor
              Found in src/merge-fields/counterpartField.js and 1 other location - About 35 mins to fix
              src/merge-fields/counterpartField.js on lines 310..310

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

              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 subfieldValues1 = field1.subfields.filter(subfield => subfield.code === subfieldCode).map(sf => sf.value);
              Severity: Minor
              Found in src/merge-fields/counterpartField.js and 1 other location - About 35 mins to fix
              src/merge-fields/counterpartField.js on lines 311..311

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

              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

              There are no issues that match your filters.

              Category
              Status