NatLibFi/marc-record-serializers

View on GitHub
src/aleph-sequential.js

Summary

Maintainability
F
1 wk
Test Coverage

Function to has a Cognitive Complexity of 186 (exceeds 5 allowed). Consider refactoring.
Open

export function to(record, useCrForContinuingResource = false) {

  const MAX_FIELD_LENGTH = 2000;
  const SPLIT_MAX_FIELD_LENGTH = 1000;

Severity: Minor
Found in src/aleph-sequential.js - About 3 days 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 to has 261 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function to(record, useCrForContinuingResource = false) {

  const MAX_FIELD_LENGTH = 2000;
  const SPLIT_MAX_FIELD_LENGTH = 1000;

Severity: Major
Found in src/aleph-sequential.js - About 1 day to fix

    File aleph-sequential.js has 466 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* eslint-disable max-lines */
    /**
    *
    * @licstart  The following is the entire license notice for the JavaScript code in this file.
    *
    Severity: Minor
    Found in src/aleph-sequential.js - About 7 hrs to fix

      Function formatDatafield has 168 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        function formatDatafield(field) {
          let subfieldLines; // eslint-disable-line functional/no-let
          const ind1 = field.ind1 && field.ind1.length > 0 ? field.ind1 : ' ';
          const ind2 = field.ind2 && field.ind2.length > 0 ? field.ind2 : ' ';
          const header = `${id} ${field.tag}${ind1}${ind2} L `;
      Severity: Major
      Found in src/aleph-sequential.js - About 6 hrs to fix

        Function reduceToLines has 144 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            function reduceToLines(result, subfield, index, arr) {
              let code; // eslint-disable-line functional/no-let
              let sliceOffset; // eslint-disable-line functional/no-let
              let slicedSegment; // eslint-disable-line functional/no-let
              const tempLength = result.temp ? result.temp.length : 0;
        Severity: Major
        Found in src/aleph-sequential.js - About 5 hrs to fix

          Function from has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
          Open

          export function from(data, validationOptions = {}) {
            let i = 0; // eslint-disable-line functional/no-let
            const lines = data.split('\n').filter(l => l.length > 0);
          
            // eslint-disable-next-line functional/no-loop-statements
          Severity: Minor
          Found in src/aleph-sequential.js - About 4 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 iterate has 110 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                function iterate(segment, firstCall) {
                  const HYPHEN = 45;
                  const SPACE = 32;
                  const CARET = 94;
                  const DOLLAR = 36;
          Severity: Major
          Found in src/aleph-sequential.js - About 4 hrs to fix

            Function from has 109 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function from(data, validationOptions = {}) {
              let i = 0; // eslint-disable-line functional/no-let
              const lines = data.split('\n').filter(l => l.length > 0);
            
              // eslint-disable-next-line functional/no-loop-statements
            Severity: Major
            Found in src/aleph-sequential.js - About 4 hrs to fix

              Function reader has 82 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function reader(stream, validationOptions = {}, genF001fromSysNo = false) {
              
                const emitter = new class extends EventEmitter { }();
                start();
                return emitter;
              Severity: Major
              Found in src/aleph-sequential.js - About 3 hrs to fix

                Function getSliceOffset has 78 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        function getSliceOffset(arr) {
                          const offset = findSeparatorOffset(arr) || findPeriodOffset(arr) || findSpaceOffset(arr) || SPLIT_MAX_FIELD_LENGTH;
                
                          return offset;
                
                
                Severity: Major
                Found in src/aleph-sequential.js - About 3 hrs to fix

                  Function start has 77 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    function start() {
                  
                      let charbuffer = ''; // eslint-disable-line functional/no-let
                      const linebuffer = []; // eslint-disable-line functional/no-let
                      let count = 0; // eslint-disable-line functional/no-let
                  Severity: Major
                  Found in src/aleph-sequential.js - About 3 hrs to fix

                    Function parseFieldFromLine has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                      function parseFieldFromLine(lineStr) {
                        const tag = lineStr.substring(10, 13);
                    
                        if (tag === undefined || tag.length !== 3) {
                          throw new Error(`Could not parse tag from line: ${lineStr}`);
                    Severity: Minor
                    Found in src/aleph-sequential.js - About 1 hr to fix

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

                        function recordFormat(record, useCrForContinuingResource) {
                          const {leader} = record;
                          const l6 = leader.slice(6, 7);
                          const l7 = leader.slice(7, 8);
                      
                      
                      Severity: Minor
                      Found in src/aleph-sequential.js - About 1 hr to fix

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

                                  function findPeriodOffset(arr) {
                                    let offset = find(); // eslint-disable-line functional/no-let
                        
                                    if (offset !== undefined) {
                                      // Append the number of chars in separator
                        Severity: Minor
                        Found in src/aleph-sequential.js - About 1 hr to fix

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

                                    function findSeparatorOffset(arr) {
                          
                                      let offset = find(); // eslint-disable-line functional/no-let
                          
                                      if (offset !== undefined) {
                          Severity: Minor
                          Found in src/aleph-sequential.js - About 1 hr to fix

                            Avoid too many return statements within this function.
                            Open

                                  return 'SE';
                            Severity: Major
                            Found in src/aleph-sequential.js - About 30 mins to fix

                              Avoid too many return statements within this function.
                              Open

                                    return 'VM';
                              Severity: Major
                              Found in src/aleph-sequential.js - About 30 mins to fix

                                Avoid too many return statements within this function.
                                Open

                                      return 'MX';
                                Severity: Major
                                Found in src/aleph-sequential.js - About 30 mins to fix

                                  Avoid too many return statements within this function.
                                  Open

                                        return 'MU';
                                  Severity: Major
                                  Found in src/aleph-sequential.js - About 30 mins to fix

                                    Avoid too many return statements within this function.
                                    Open

                                          return 'MP';
                                    Severity: Major
                                    Found in src/aleph-sequential.js - About 30 mins to fix

                                      Avoid too many return statements within this function.
                                      Open

                                          return 'BK';
                                      Severity: Major
                                      Found in src/aleph-sequential.js - About 30 mins to fix

                                        Avoid too many return statements within this function.
                                        Open

                                            return true;
                                        Severity: Major
                                        Found in src/aleph-sequential.js - About 30 mins to fix

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

                                                    function findSeparatorOffset(arr) {
                                          
                                                      let offset = find(); // eslint-disable-line functional/no-let
                                          
                                                      if (offset !== undefined) {
                                          Severity: Major
                                          Found in src/aleph-sequential.js and 1 other location - About 1 day to fix
                                          src/aleph-sequential.js on lines 454..492

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

                                          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

                                                    function findPeriodOffset(arr) {
                                                      let offset = find(); // eslint-disable-line functional/no-let
                                          
                                                      if (offset !== undefined) {
                                                        // Append the number of chars in separator
                                          Severity: Major
                                          Found in src/aleph-sequential.js and 1 other location - About 1 day to fix
                                          src/aleph-sequential.js on lines 412..452

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

                                          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