danielwippermann/resol-vbus

View on GitHub
src/specification-file.js

Summary

Maintainability
F
1 wk
Test Coverage

File specification-file.js has 540 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*! resol-vbus | Copyright (c) 2016-present, Daniel Wippermann | MIT license */

const fs = require('fs');
const path = require('path');

Severity: Major
Found in src/specification-file.js - About 1 day to fix

    Function _parseBuffer has 180 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        _parseBuffer(buffer) {
            const that = this;
    
            const sliceBlock = function(name, offset, size) {
                if ((offset < 0) || (offset > buffer.length)) {
    Severity: Major
    Found in src/specification-file.js - About 7 hrs to fix

      Function _generateSpecificationData has 157 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _generateSpecificationData(language) {
              const that = this;
      
              let units = {
                  ...this.knownUnitsByCode,
      Severity: Major
      Found in src/specification-file.js - About 6 hrs to fix

        Function _generateSpecificationData has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
        Open

            _generateSpecificationData(language) {
                const that = this;
        
                let units = {
                    ...this.knownUnitsByCode,
        Severity: Minor
        Found in src/specification-file.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 getRawValue has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            getRawValue(pt, ptf, buffer, start, end) {
                let rawValue = 0, valid = false;
                for (const part of ptf.parts) {
                    if (start + part.offset < end) {
                        let partValue;
        Severity: Minor
        Found in src/specification-file.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 constructor has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            constructor(buffer, language) {
                this.buffer = buffer;
        
                this.types = types;
        
        
        Severity: Minor
        Found in src/specification-file.js - About 1 hr to fix

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

                  const packetFieldSpecs = this.packetTemplates.reduce((memo, pt) => {
                      const packetId = sprintf('_%04X_%04X_%04X', pt.destinationAddress, pt.sourceAddress, pt.command);
          
                      memo [packetId] = pt.fields.map((ptf) => {
                          const rootTypeId = ptf.type && ptf.type.typeCode;
          Severity: Minor
          Found in src/specification-file.js - About 1 hr to fix

            Function setRawValue has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                setRawValue(pt, ptf, newValue, buffer, start, end) {
                    if (ptf.precision > 0) {
                        newValue = newValue * Math.pow(10, ptf.precision);
                    }
                    newValue = Math.round(newValue);
            Severity: Minor
            Found in src/specification-file.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 _parseBuffer has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                _parseBuffer(buffer) {
                    const that = this;
            
                    const sliceBlock = function(name, offset, size) {
                        if ((offset < 0) || (offset > buffer.length)) {
            Severity: Minor
            Found in src/specification-file.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 packetId has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        memo [packetId] = pt.fields.map((ptf) => {
                            const rootTypeId = ptf.type && ptf.type.typeCode;
                            const { precision } = ptf;
                            const unitCode = (ptf.unit && ptf.unit.unitCode) || 'None';
            
            
            Severity: Minor
            Found in src/specification-file.js - About 1 hr to fix

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

                  getRawValue(pt, ptf, buffer, start, end) {
                      let rawValue = 0, valid = false;
                      for (const part of ptf.parts) {
                          if (start + part.offset < end) {
                              let partValue;
              Severity: Minor
              Found in src/specification-file.js - About 1 hr to fix

                Function processBlockTable has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                        const processBlockTable = function(blockName, tableCount, tableOffset, blockSize, cb) {
                Severity: Minor
                Found in src/specification-file.js - About 35 mins to fix

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

                  const crc16Table = [
                      0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
                      0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
                      0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e,
                      0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876,
                  Severity: Major
                  Found in src/specification-file.js and 1 other location - About 1 day to fix
                  src/header.js on lines 10..43

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

                  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 ptBlock = {
                                  destinationAddress: ptBuffer.readUInt16LE(0x00),
                                  destinationMask: ptBuffer.readUInt16LE(0x02),
                                  sourceAddress: ptBuffer.readUInt16LE(0x04),
                                  sourceMask: ptBuffer.readUInt16LE(0x06),
                  Severity: Major
                  Found in src/specification-file.js and 1 other location - About 3 hrs to fix
                  src/specification-file.js on lines 512..520

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

                  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 ptfBlock = {
                                      idTextIndex: ptfBuffer.readInt32LE(0x00),
                                      nameLocalizedTextIndex: ptfBuffer.readInt32LE(0x04),
                                      unitId: ptfBuffer.readInt32LE(0x08),
                                      precision: ptfBuffer.readInt32LE(0x0c),
                  Severity: Major
                  Found in src/specification-file.js and 1 other location - About 3 hrs to fix
                  src/specification-file.js on lines 500..508

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

                  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 fileHeaderBlock = {
                              checksumA: fileHeaderBuffer.readUInt16LE(0x00),
                              checksumB: fileHeaderBuffer.readUInt16LE(0x02),
                              totalLength: fileHeaderBuffer.readInt32LE(0x04),
                              dataVersion: fileHeaderBuffer.readInt32LE(0x08),
                  Severity: Major
                  Found in src/specification-file.js and 1 other location - About 1 hr to fix
                  src/specification-file.js on lines 481..487

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

                  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 dtBlock = {
                                  selfAddress: dtBuffer.readUInt16LE(0x00),
                                  selfMask: dtBuffer.readUInt16LE(0x02),
                                  peerAddress: dtBuffer.readUInt16LE(0x04),
                                  peerMask: dtBuffer.readUInt16LE(0x06),
                  Severity: Major
                  Found in src/specification-file.js and 1 other location - About 1 hr to fix
                  src/specification-file.js on lines 388..394

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

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

                          this.unitFamilyById = unitFamilies.reduce((memo, unitFamily) => {
                              memo [unitFamily.unitFamilyId] = unitFamily;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 119..122
                  src/specification-file.js on lines 124..127
                  src/specification-file.js on lines 136..139
                  src/specification-file.js on lines 143..146
                  src/specification-file.js on lines 148..151

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

                          this.knownUnitsByCode = knownUnits.reduce((memo, unit) => {
                              memo [unit.unitCode] = unit;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 119..122
                  src/specification-file.js on lines 124..127
                  src/specification-file.js on lines 131..134
                  src/specification-file.js on lines 136..139
                  src/specification-file.js on lines 143..146

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

                          this.typeById = types.reduce((memo, type) => {
                              memo [type.typeId] = type;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 124..127
                  src/specification-file.js on lines 131..134
                  src/specification-file.js on lines 136..139
                  src/specification-file.js on lines 143..146
                  src/specification-file.js on lines 148..151

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

                          this.knownUnitsById = knownUnits.reduce((memo, unit) => {
                              memo [unit.unitId] = unit;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 119..122
                  src/specification-file.js on lines 124..127
                  src/specification-file.js on lines 131..134
                  src/specification-file.js on lines 136..139
                  src/specification-file.js on lines 148..151

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

                          this.typeByCode = types.reduce((memo, type) => {
                              memo [type.typeCode] = type;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 119..122
                  src/specification-file.js on lines 131..134
                  src/specification-file.js on lines 136..139
                  src/specification-file.js on lines 143..146
                  src/specification-file.js on lines 148..151

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

                          this.unitFamilyByCode = unitFamilies.reduce((memo, unitFamily) => {
                              memo [unitFamily.unitFamilyCode] = unitFamily;
                              return memo;
                          }, {});
                  Severity: Major
                  Found in src/specification-file.js and 5 other locations - About 35 mins to fix
                  src/specification-file.js on lines 119..122
                  src/specification-file.js on lines 124..127
                  src/specification-file.js on lines 131..134
                  src/specification-file.js on lines 143..146
                  src/specification-file.js on lines 148..151

                  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