streetmix/streetmix

View on GitHub
client/src/app/keypress.js

Summary

Maintainability
D
2 days
Test Coverage

Function processCommands has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

function processCommands (commands) {
  // If a string, force to one-element array, otherwise expect an array of strings
  if (typeof commands === 'string') {
    commands = new Array(commands)
  }
Severity: Minor
Found in client/src/app/keypress.js - About 3 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 registerKeypress has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

export function registerKeypress (commands, options, callback) {
  // Defaults
  // For shiftKey, metaKey, and altKey, specifies what it should
  // match on the event object reported by the browser. For instance,
  // if event.metaKey is false, it means the command must be executed
Severity: Minor
Found in client/src/app/keypress.js - About 3 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 deregisterKeypress has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

export function deregisterKeypress (commands, callback) {
  const commandObj = processCommands(commands)

  // Process each command input
  for (const key in commandObj) {
Severity: Minor
Found in client/src/app/keypress.js - 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 processCommands has 62 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function processCommands (commands) {
  // If a string, force to one-element array, otherwise expect an array of strings
  if (typeof commands === 'string') {
    commands = new Array(commands)
  }
Severity: Major
Found in client/src/app/keypress.js - About 2 hrs to fix

Function registerKeypress has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function registerKeypress (commands, options, callback) {
  // Defaults
  // For shiftKey, metaKey, and altKey, specifies what it should
  // match on the event object reported by the browser. For instance,
  // if event.metaKey is false, it means the command must be executed
Severity: Minor
Found in client/src/app/keypress.js - About 1 hr to fix

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

function onGlobalKeyDown (event) {
  const toExecute = []
  const key = event.key

  // There is a bug in Chrome where events can be fired with an
Severity: Minor
Found in client/src/app/keypress.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

Consider simplifying this complex logical expression.
Open

    if (
      (item.shiftKey === event.shiftKey || item.shiftKey === 'optional') &&
      (item.altKey === event.altKey || item.altKey === 'optional') &&
      (item.metaKey === event.metaKey ||
        item.metaKey === event.ctrlKey ||
Severity: Major
Found in client/src/app/keypress.js - About 1 hr to fix

Avoid deeply nested control flow statements.
Open

          if (isShiftOrOptional && isAltOrOptional && isMetaOrOptional) {
            // If matches, remove it from the command list.
            inputs[key].splice(x, 1)
          }
Severity: Major
Found in client/src/app/keypress.js - About 45 mins to fix

Function execute has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

function execute (input, event) {
  // Check if condition is satisfied
  if (!input.condition()) return

  // Check if focus is on the correct place
Severity: Minor
Found in client/src/app/keypress.js - About 25 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

There are no issues that match your filters.

Category
Status