Goldinteractive/js-base

View on GitHub

Showing 32 of 32 total issues

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

    function tick() {
      currentTime += 1 / 60

      let p = currentTime / time
      let t = easingEquations[opts.easing](p)
Severity: Minor
Found in src/utils/dom.js - About 1 hr to fix

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

  removeEventListener(node, type = null, fn = null) {
    if (!isElement(node) && node !== window) {
      let currentNode = node.length
      while (currentNode--) {
        this.removeEventListener(node[currentNode], type, fn)
Severity: Minor
Found in src/features.js - About 1 hr to fix

Consider simplifying this complex logical expression.
Open

      if (
        nodeInstances.hasOwnProperty(featureName) &&
        (!name || names.indexOf(featureName) > -1) && // name is whitelisted
        (!ignoreFeatures || ignoreFeatures.indexOf(featureName) < 0) && // feature is ignore on this node
        (featureNode._baseFeatureInstances && // feature instance exists
Severity: Major
Found in src/features.js - About 1 hr to fix

Consider simplifying this complex logical expression.
Open

      if (
        !feature || // feature has not been added yet
        (ignoreFeatures && ignoreFeatures.indexOf(featureName) > -1) || // feature is ignored on this node
        (name && names.indexOf(featureName) < 0) || // name is not whitelisted
        (featureNode._baseFeatureInstances && // feature has already been initalized on this node
Severity: Major
Found in src/features.js - About 1 hr to fix

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

export async function loadExternals(bundles, assetPath) {
  let elements = document.querySelectorAll(`[${ATTR_EXTERNAL_SCRIPT}]`)
  let features = getFeatures()
  let scripts = []
  let scriptsLoaded = []
Severity: Minor
Found in src/features.js - 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 isEmpty has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

export function isEmpty(value) {
  // compare value with values considered as empty
  for (let i = 0, len = EMPTY_DEFINITIONS.length; i < len; i++) {
    if (value === EMPTY_DEFINITIONS[i]) {
      return true
Severity: Minor
Found in src/utils/check.js - 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 parents has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

export function parents(element, match = null) {
  let parents = []

  for (; element && element !== document; element = element.parentNode) {
    if (match) {
Severity: Minor
Found in src/utils/dom.js - 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 addEventListener has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  addEventListener(node, type, fn, options = {}) {
    if (!isElement(node) && node !== window) {
      let currentNode = node.length
      while (currentNode--) {
        this.addEventListener(node[currentNode], type, fn, options)
Severity: Minor
Found in src/features.js - 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 removeEventListener has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

  removeEventListener(node, type = null, fn = null) {
    if (!isElement(node) && node !== window) {
      let currentNode = node.length
      while (currentNode--) {
        this.removeEventListener(node[currentNode], type, fn)
Severity: Minor
Found in src/features.js - 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

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

export function text(u, opts = {}) {
  return url(u, opts).then(r => r.text())
}
Severity: Minor
Found in src/utils/fetch.js and 1 other location - About 40 mins to fix
src/utils/fetch.js on lines 79..81

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

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 function json(u, opts = {}) {
  return url(u, opts).then(r => r.json())
}
Severity: Minor
Found in src/utils/fetch.js and 1 other location - About 40 mins to fix
src/utils/fetch.js on lines 106..108

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

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 removeAllEventListener has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  removeAllEventListener(node = null, fn = null) {
    if (node && !isElement(node) && node !== window) {
      let currentNode = node.length
      while (currentNode--) {
        this.removeAllEventListener(node[currentNode], fn)
Severity: Minor
Found in src/features.js - 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

Severity
Category
Status
Source
Language