NatLibFi/marc-record-validators-melinda

View on GitHub
src/removeInferiorDataFields.js

Summary

Maintainability
D
2 days
Test Coverage

Function deriveIndividualDeletables has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

function deriveIndividualDeletables(record) {
  const todoList = record.fields.map(f => fieldToString(f));
  //const finishedRecord = encodingLevelIsBetterThanPrepublication(getEncodingLevel(record));

  const deletableStringsArray = processTodoList(todoList);
Severity: Minor
Found in src/removeInferiorDataFields.js - About 5 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 deriveIndividualDeletables has 65 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function deriveIndividualDeletables(record) {
  const todoList = record.fields.map(f => fieldToString(f));
  //const finishedRecord = encodingLevelIsBetterThanPrepublication(getEncodingLevel(record));

  const deletableStringsArray = processTodoList(todoList);
Severity: Major
Found in src/removeInferiorDataFields.js - About 2 hrs to fix

    File removeInferiorDataFields.js has 266 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import createDebugLogger from 'debug';
    import {fieldToChain, sameField} from './removeDuplicateDataFields';
    import {fieldGetOccurrenceNumberPairs, fieldHasValidSubfield6, fieldSevenToOneOccurrenceNumber, fieldsToNormalizedString} from './subfield6Utils';
    import {fieldHasSubfield, fieldsToString, fieldToString, nvdebug, uniqArray} from './utils';
    import {fieldHasValidSubfield8} from './subfield8Utils';
    Severity: Minor
    Found in src/removeInferiorDataFields.js - About 2 hrs to fix

      Function processTodoList has 50 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function processTodoList(thingsToDo, deletables = []) {
          const [currString, ...stillToDo] = thingsToDo;
      
          if (currString === undefined) {
            return deletables;
      Severity: Minor
      Found in src/removeInferiorDataFields.js - About 2 hrs to fix

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

        export function removeInferiorChains(record, fix = true) {
          const fields = record.fields.filter(f => isRelevantChain6(f, record));
          //nvdebug(`WP2.0: GOT ${fields.length} chain(s)`);
        
          const deletableChainsAsKeys = deriveInferiorChains(fields, record);
        Severity: Minor
        Found in src/removeInferiorDataFields.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 removeInferiorChains has 43 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export function removeInferiorChains(record, fix = true) {
          const fields = record.fields.filter(f => isRelevantChain6(f, record));
          //nvdebug(`WP2.0: GOT ${fields.length} chain(s)`);
        
          const deletableChainsAsKeys = deriveInferiorChains(fields, record);
        Severity: Minor
        Found in src/removeInferiorDataFields.js - About 1 hr to fix

          Function deriveInferiorChains has 30 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function deriveInferiorChains(fields, record) {
            //nvdebug(`======= GOT ${fields.length} FIELDS TO CHAINIFY`);
            const hash = {};
          
            fields.forEach(f => fieldToChainToDeletables(f));
          Severity: Minor
          Found in src/removeInferiorDataFields.js - About 1 hr to fix

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

            function deriveIndividualNormalizedDeletables(record) { //  MET-461:
              const encodingLevel = getEncodingLevel(record);
              const recordIsFinished = encodingLevelIsBetterThanPrepublication(encodingLevel);
              const met495 = encodingLevel === '2' && record.fields.some(f => f.tag === '500' && fieldRefersToKoneellisestiTuotettuTietue(f));
              if (!recordIsFinished || met495) {
            Severity: Minor
            Found in src/removeInferiorDataFields.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 processTodoList([...stillToDo, ...moreToDo], [...deletables, tmp, tmp2]);
            Severity: Major
            Found in src/removeInferiorDataFields.js - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                    return processTodoList([...stillToDo, ...moreToDo], [...deletables, tmp]);
              Severity: Major
              Found in src/removeInferiorDataFields.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return processTodoList([...stillToDo, ...moreToDo], newDeletables);
                Severity: Major
                Found in src/removeInferiorDataFields.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return processTodoList([tmp, ...stillToDo, ...moreToDo], [...deletables, tmp]);
                  Severity: Major
                  Found in src/removeInferiorDataFields.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                          return processTodoList([...stillToDo, ...moreToDo], newDeletables);
                    Severity: Major
                    Found in src/removeInferiorDataFields.js - About 30 mins to fix

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

                      function deriveInferiorChains(fields, record) {
                        //nvdebug(`======= GOT ${fields.length} FIELDS TO CHAINIFY`);
                        const hash = {};
                      
                        fields.forEach(f => fieldToChainToDeletables(f));
                      Severity: Minor
                      Found in src/removeInferiorDataFields.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

                      There are no issues that match your filters.

                      Category
                      Status