Memristor-Robotics/mep-master

View on GitHub
src/drivers/motion/MotionDriver.js

Summary

Maintainability
D
2 days
Test Coverage

MotionDriver has 68 functions (exceeds 20 allowed). Consider refactoring.
Open

class MotionDriver extends EventEmitter  {
    static get STATE_IDLE() { return 'I'.charCodeAt(0); }
    static get STATE_STUCK() { return 'S'.charCodeAt(0); }
    static get STATE_MOVING() { return 'M'.charCodeAt(0); }
    static get STATE_ROTATING() { return 'R'.charCodeAt(0); }
Severity: Major
Found in src/drivers/motion/MotionDriver.js - About 1 day to fix

    File MotionDriver.js has 407 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    'use strict';
    /** @namespace drivers.motion */
    
    const Point = Mep.require("misc/geometry/Point");
    const EventEmitter = require('events');
    Severity: Minor
    Found in src/drivers/motion/MotionDriver.js - About 5 hrs to fix

      Function _promiseToStateChanged has 42 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          _promiseToStateChanged() {
              let motionDriver = this;
      
              let timeout = setTimeout(() => {
                  motionDriver.emit('stateChanged', MotionDriver.STATE_STUCK);
      Severity: Minor
      Found in src/drivers/motion/MotionDriver.js - About 1 hr to fix

        Function _onPReceived has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            _onPReceived(buffer) {
                // Ignore garbage
                let state = buffer.readInt8(0);
                let position = new Point(
                    (buffer.readInt8(1) << 8) | (buffer.readInt8(2) & 0xFF),
        Severity: Minor
        Found in src/drivers/motion/MotionDriver.js - About 1 hr to fix

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

              moveToCurvilinear(position, direction, radius, tolerance) {
                  let motionDriver = this;
          
                  this._direction = direction;
                  this._sendCommand(Buffer.from([
          Severity: Minor
          Found in src/drivers/motion/MotionDriver.js - About 1 hr to fix

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

                _onPReceived(buffer) {
                    // Ignore garbage
                    let state = buffer.readInt8(0);
                    let position = new Point(
                        (buffer.readInt8(1) << 8) | (buffer.readInt8(2) & 0xFF),
            Severity: Minor
            Found in src/drivers/motion/MotionDriver.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 stateListener has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        let stateListener = (name, state) => {
                            switch (state) {
                                case MotionDriver.STATE_IDLE:
                                    Mep.Log.debug(TAG, 'Resolved');
                                    clearTimeout(timeout);
            Severity: Minor
            Found in src/drivers/motion/MotionDriver.js - About 1 hr to fix

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

                  async init() {
                      let motionDriver = this;
              
                      this.reset();
                      this.setPositionAndOrientation(
              Severity: Minor
              Found in src/drivers/motion/MotionDriver.js - About 1 hr to fix

                There are no issues that match your filters.

                Category
                Status