igbopie/spherov2.js

View on GitHub

Showing 47 of 47 total issues

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

const fillGyroV21 = (state: IParserState): IParserState => {
  const { sensorMask, floats, response, location } = state;
  if (sensorMask.v21.indexOf(SensorMaskV2.gyroFilteredAllV21) >= 0) {
    response.gyro = {
      filtered: {
Severity: Major
Found in lib/src/toys/utils.ts and 1 other location - About 6 hrs to fix
lib/src/toys/utils.ts on lines 118..135

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

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 fillAccelerometer = (state: IParserState): IParserState => {
  const { sensorMask, floats, response, location } = state;
  if (sensorMask.v2.indexOf(SensorMaskV2.accelerometerFilteredAll) >= 0) {
    response.accelerometer = {
      filtered: {
Severity: Major
Found in lib/src/toys/utils.ts and 1 other location - About 6 hrs to fix
lib/src/toys/utils.ts on lines 182..200

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

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

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

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

                  export default (generator: CommandGenerator) => {
                    const encode = generator(DeviceId.somethingAPI);
                    return {
                      something5: (): ICommandWithRaw =>
                        encode({
                  Severity: Major
                  Found in lib/src/commands/something-api.ts and 1 other location - About 1 hr to fix
                  lib/src/commands/api.ts on lines 8..16

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

                  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

                  export default (generator: CommandGenerator) => {
                    const encode = generator(DeviceId.apiProcessor);
                    return {
                      echo: (): ICommandWithRaw =>
                        encode({
                  Severity: Major
                  Found in lib/src/commands/api.ts and 1 other location - About 1 hr to fix
                  lib/src/commands/something-api.ts on lines 8..16

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

                  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

                      rightStick: {
                        xRaw: data.readInt8(Buttons.RightStickX),
                        yRaw: data.readInt8(Buttons.RightStickY),
                        x: 0,
                        y: 0,
                  Severity: Major
                  Found in examples/src/utils/nimbus.ts and 1 other location - About 1 hr to fix
                  examples/src/utils/nimbus.ts on lines 80..87

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

                  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

                      leftStick: {
                        xRaw: data.readInt8(Buttons.LeftStickX),
                        yRaw: data.readInt8(Buttons.LeftStickY),
                        x: 0,
                        y: 0,
                  Severity: Major
                  Found in examples/src/utils/nimbus.ts and 1 other location - About 1 hr to fix
                  examples/src/utils/nimbus.ts on lines 88..95

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

                  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

                  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

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

                      public setBackLedIntensity(i: number): Promise<IQueuePayload> {
                        return this.queueCommand(this.commands.userIo.setBackLedIntensity(i));
                      }
                    Severity: Major
                    Found in lib/src/toys/rollable-toy.ts and 2 other locations - About 1 hr to fix
                    lib/src/toys/rollable-toy.ts on lines 61..63
                    lib/src/toys/rollable-toy.ts on lines 84..86

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

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

                      public setMainLedGreenIntensity(i: number): Promise<IQueuePayload> {
                        return this.queueCommand(this.commands.userIo.setMainLedGreenIntensity(i));
                      }
                    Severity: Major
                    Found in lib/src/toys/rollable-toy.ts and 2 other locations - About 1 hr to fix
                    lib/src/toys/rollable-toy.ts on lines 53..55
                    lib/src/toys/rollable-toy.ts on lines 61..63

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

                    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

                    Severity
                    Category
                    Status
                    Source
                    Language