src/drivers/motion/MotionDriver.js
MotionDriver
has 68 functions (exceeds 20 allowed). Consider refactoring. Open
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); }
File MotionDriver.js
has 407 lines of code (exceeds 250 allowed). Consider refactoring. Open
Open
'use strict';
/** @namespace drivers.motion */
const Point = Mep.require("misc/geometry/Point");
const EventEmitter = require('events');
Function _promiseToStateChanged
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
_promiseToStateChanged() {
let motionDriver = this;
let timeout = setTimeout(() => {
motionDriver.emit('stateChanged', MotionDriver.STATE_STUCK);
Function _onPReceived
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
_onPReceived(buffer) {
// Ignore garbage
let state = buffer.readInt8(0);
let position = new Point(
(buffer.readInt8(1) << 8) | (buffer.readInt8(2) & 0xFF),
Function moveToCurvilinear
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
moveToCurvilinear(position, direction, radius, tolerance) {
let motionDriver = this;
this._direction = direction;
this._sendCommand(Buffer.from([
Function _onPReceived
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
_onPReceived(buffer) {
// Ignore garbage
let state = buffer.readInt8(0);
let position = new Point(
(buffer.readInt8(1) << 8) | (buffer.readInt8(2) & 0xFF),
- Read upRead up
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
Open
let stateListener = (name, state) => {
switch (state) {
case MotionDriver.STATE_IDLE:
Mep.Log.debug(TAG, 'Resolved');
clearTimeout(timeout);
Function init
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
async init() {
let motionDriver = this;
this.reset();
this.setPositionAndOrientation(