igbopie/spherov2.js

View on GitHub

Showing 19 of 47 total issues

Function hid has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
Open

export const hid = async (toy: SpheroMini) => {
  let calibrating = false;
  let offset = 0;
  let stopped = false;
  let heading: number;
Severity: Minor
Found in examples/src/utils/nimbus-sphero.ts - 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 cmdPlay has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

const cmdPlay = (toy: SpheroMini) => {
  let pressTimeout: NodeJS.Timer;
  let heading = 0;
  let currentSpeed = 0;
  let speed = 150;
Severity: Minor
Found in examples/src/cmd.ts - 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 cmdPlay has 89 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const cmdPlay = (toy: SpheroMini) => {
  let pressTimeout: NodeJS.Timer;
  let heading = 0;
  let currentSpeed = 0;
  let speed = 150;
Severity: Major
Found in examples/src/cmd.ts - About 3 hrs to fix

    Core has 26 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Core {
      // Override in child class to get right percent
      protected maxVoltage = 0;
      protected minVoltage = 1;
      protected apiVersion: APIVersion = APIVersion.V2;
    Severity: Minor
    Found in lib/src/toys/core.ts - About 3 hrs to fix

      Function factory has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

      export function factory(
        callback: (err: string, response?: ICommandWithRaw) => void
      ) {
        let msg: number[] = [];
        let checksum = 0;
      Severity: Minor
      Found in lib/src/commands/decoder.ts - About 2 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 factory has 52 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function factory(
        callback: (err: string, response?: ICommandWithRaw) => void
      ) {
        let msg: number[] = [];
        let checksum = 0;
      Severity: Major
      Found in lib/src/commands/decoder.ts - About 2 hrs to fix

        Function handle has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          const handle = async (key = '', symbol: { name?: string } = {}) => {
            cancelPress();
            if (symbol.name === 'up') {
              heading = 0;
              currentSpeed = speed;
        Severity: Minor
        Found in examples/src/cmd.ts - About 1 hr to fix

          Function calculateDomeAngle has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            private calculateDomeAngle(angle: number) {
              const result = new Uint8Array(2);
              switch (angle) {
                case -1:
                  result[0] = 0xbf;
          Severity: Minor
          Found in lib/src/toys/r2d2.ts - About 1 hr to fix

            Function encode has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export function encode(command: ICommand): ICommandWithRaw {
              const {
                commandFlags = [Flags.requestsResponse, Flags.resetsInactivityTimeout],
                deviceId,
                commandId,
            Severity: Minor
            Found in lib/src/commands/encoder.ts - About 1 hr to fix

              Function hid has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export const hid = async (toy: SpheroMini) => {
                let calibrating = false;
                let offset = 0;
                let stopped = false;
                let heading: number;
              Severity: Minor
              Found in examples/src/utils/nimbus-sphero.ts - About 1 hr to fix

                Function add has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    add(byte: number) {
                      switch (byte) {
                        case APIConstants.startOfPacket:
                          if (msg.length !== 0) {
                            init();
                Severity: Minor
                Found in lib/src/commands/decoder.ts - About 1 hr to fix

                  Function loop has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    const loop = async () => {
                      // eslint-disable-next-line no-constant-condition
                      while (true) {
                        if (state) {
                          const { angle, module } = state.leftStick;
                  Severity: Minor
                  Found in examples/src/utils/nimbus-sphero.ts - About 1 hr to fix

                    Function hid has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export const hid = async (toy: LightningMcQueen) => {
                      // let stopped = false;
                      let heading: number;
                    
                      const loop = async () => {
                    Severity: Minor
                    Found in examples/src/utils/hid-lm.ts - About 55 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

                    Function calculateDomeAngle has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                      private calculateDomeAngle(angle: number) {
                        const result = new Uint8Array(2);
                        switch (angle) {
                          case -1:
                            result[0] = 0xbf;
                    Severity: Minor
                    Found in lib/src/toys/r2d2.ts - About 45 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

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

                    const sensorValuesToRawV2 = (
                      sensorMask: SensorMaskValues[],
                      apiVersion: APIVersion = APIVersion.V2
                    ) =>
                      sensorMask.reduce((v2, m) => {
                    Severity: Minor
                    Found in lib/src/toys/utils.ts - 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;
                    Severity: Major
                    Found in lib/src/commands/decoder.ts - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                return init();
                      Severity: Major
                      Found in lib/src/commands/decoder.ts - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                    return error('Invalid escape char position');
                        Severity: Major
                        Found in lib/src/commands/decoder.ts - About 30 mins to fix

                          Avoid too many return statements within this function.
                          Open

                                  return error('Invalid no escape char end found');
                          Severity: Major
                          Found in lib/src/commands/decoder.ts - About 30 mins to fix
                            Severity
                            Category
                            Status
                            Source
                            Language