Goldinteractive/js-base

View on GitHub

Showing 32 of 32 total issues

File features.js has 464 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * Features module.
 * @module base/features
 */

Severity: Minor
Found in src/features.js - About 7 hrs to fix

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

    if (scrollTargetX !== null) {
      scrollTargetX = scrollTargetX - opts.offsetX
      scrollTargetX = scrollTargetX < 0 ? 0 : scrollTargetX

      // determine scroll time for x axis
Severity: Major
Found in src/utils/dom.js and 1 other location - About 3 hrs to fix
src/utils/dom.js on lines 342..354

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

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

    if (scrollTargetY !== null) {
      scrollTargetY = scrollTargetY - opts.offsetY
      scrollTargetY = scrollTargetY < 0 ? 0 : scrollTargetY

      // determine scroll time for y axis
Severity: Major
Found in src/utils/dom.js and 1 other location - About 3 hrs to fix
src/utils/dom.js on lines 328..340

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

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 to has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  to(options = {}) {
    let timeX = 0
    let timeY = 0
    let currentTime = 0
    let rootElement = Array.isArray(this._opts.rootElement)
Severity: Major
Found in src/utils/dom.js - About 2 hrs to fix

Function init has 58 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function init(container = document.body, name = null, options = {}) {
  options = Object.assign({}, defaultInitOptions, options)

  const instances = []
  const names = name ? name.split(ATTR_FEATURES_SEPARATOR) : null
Severity: Major
Found in src/features.js - About 2 hrs to fix

Function to has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  to(options = {}) {
    let timeX = 0
    let timeY = 0
    let currentTime = 0
    let rootElement = Array.isArray(this._opts.rootElement)
Severity: Minor
Found in src/utils/dom.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 loadExternals has 46 lines of code (exceeds 25 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 1 hr to fix

Function debounce has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

export function debounce(func, wait = 60, immediate = false) {
  var timeout, args, context, timestamp, result

  function later() {
    var last = Date.now() - timestamp
Severity: Minor
Found in src/utils/fn.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

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

export function outerWidth(element) {
  let width = element.offsetWidth,
    style = window.getComputedStyle(element)

  width += pxToInt(style.marginLeft) + pxToInt(style.marginRight)
Severity: Major
Found in src/utils/dom.js and 1 other location - About 1 hr to fix
src/utils/dom.js on lines 50..56

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

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 outerHeight(element) {
  let height = element.offsetHeight,
    style = window.getComputedStyle(element)

  height += pxToInt(style.marginTop) + pxToInt(style.marginBottom)
Severity: Major
Found in src/utils/dom.js and 1 other location - About 1 hr to fix
src/utils/dom.js on lines 64..70

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

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

    features.forEach(feature => {
      if (bundle[1].includes(feature) && !optimizedBundles[bundle[0]]) {
        optimizedBundles[bundle[0]] = bundle[1]
      }
    })
Severity: Major
Found in src/features.js and 1 other location - About 1 hr to fix
src/features.js on lines 183..187

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

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

    extFeatures.forEach(feature => {
      if (bundle[1].includes(feature) && !externalBundles[bundle[0]]) {
        externalBundles[bundle[0]] = bundle[1]
      }
    })
Severity: Major
Found in src/features.js and 1 other location - About 1 hr to fix
src/features.js on lines 174..178

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

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 lazyload has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function lazyload(bundles, assetPath) {
  if (!bundles || !assetPath) {
    throw Error('Cannot lazyload features without a bundles file or a path!')
  }

Severity: Minor
Found in src/features.js - About 1 hr to fix

Function destroy has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function destroy(container = document.body, name = null, options = {}) {
  options = Object.assign({}, defaultDestroyOptions, options)

  const names = name ? name.split(ATTR_FEATURES_SEPARATOR) : null
  const featureNodes = [...container.querySelectorAll(`[${ATTR_FEATURES}]`)]
Severity: Minor
Found in src/features.js - About 1 hr to fix

Function debounce has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export function debounce(func, wait = 60, immediate = false) {
  var timeout, args, context, timestamp, result

  function later() {
    var last = Date.now() - timestamp
Severity: Minor
Found in src/utils/fn.js - About 1 hr to fix

Function exports has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = function(env = {}) {
  var entry = path.join(root, process.env.SOURCE_PATH, 'index.js')
  var outputPath = path.join(root, process.env.LIBRARY_PATH)
  var outputFile = LIBRARY_NAME + '.js'

Severity: Minor
Found in .config/webpack.js - About 1 hr to fix

Function getRelevantBundles has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function getRelevantBundles(bundles) {
  const features = getFeatures()
  let extElements = document.querySelectorAll(`[${ATTR_EXTERNAL_SCRIPT}]`)
  let extFeatures = []
  let optimizedBundles = {}
Severity: Minor
Found in src/features.js - About 1 hr to fix

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

export function pushState(url, state = null, title = '') {
  window.history.pushState(state, title, url)
  eventHub.trigger('pushstate', state).trigger('statechange', state)
}
Severity: Major
Found in src/utils/url.js and 1 other location - About 1 hr to fix
src/utils/url.js on lines 72..75

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

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 replaceState(url, state = null, title = '') {
  window.history.replaceState(state, title, url)
  eventHub.trigger('replacestate', state).trigger('statechange', state)
}
Severity: Major
Found in src/utils/url.js and 1 other location - About 1 hr to fix
src/utils/url.js on lines 60..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 58.

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

export function lazyload(bundles, assetPath) {
  if (!bundles || !assetPath) {
    throw Error('Cannot lazyload features without a bundles file or a path!')
  }

Severity: Minor
Found in src/features.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

Severity
Category
Status
Source
Language