wbotelhos/raty

View on GitHub

Showing 12 of 12 total issues

File raty.js has 571 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/*!
 * Raty - A Star Rating Plugin
 *
 * author: Washington Botelho
 * github: wbotelhos/raty
Severity: Major
Found in src/raty.js - About 1 day to fix

Raty has 52 functions (exceeds 20 allowed). Consider refactoring.
Open

class Raty {
  /**
   *
   * @param {object} element
   * @param {object} options
Severity: Major
Found in src/raty.js - About 7 hrs to fix

Function _getHint has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

  _getHint(score, evt) {
    if (score !== 0 && !score) {
      return this.opt.noRatedMsg;
    }

Severity: Minor
Found in src/raty.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 _target has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  _target(score, evt) {
    if (this.opt.target) {
      const target = document.querySelector(this.opt.target);

      if (!target) {
Severity: Minor
Found in src/raty.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 _fill has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  _fill(score) {
    let hash = 0;

    if (this.opt.iconRangeSame && this.opt.iconRange) {
      while (hash < this.opt.iconRange.length && this.opt.iconRange[hash].range < score) {
Severity: Minor
Found in src/raty.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 _adjustHints has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  _adjustHints() {
    // TODO: is it possible `hints` does not exist?
    if (!this.opt.hints) {
      this.opt.hints = [];
    }
Severity: Minor
Found in src/raty.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

Function defaultOptions has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  defaultOptions() {
    return {
      cancelButton: false,
      cancelClass: 'raty-cancel',
      cancelHint: 'Cancel this rating!',
Severity: Minor
Found in src/raty.js - About 1 hr to fix

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

  init() {
    this._executeCallbacks();
    this._adjustNumber();
    this._adjustHints();

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

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

  _starName(score, evt) {
    const decimal = +(score % 1).toFixed(2);

    if (evt || this.isMove) {
      return decimal > 0.5 ? 'starOn' : 'starHalf';
Severity: Minor
Found in src/raty.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

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

  _executeCallbacks() {
    const options = ['number', 'readOnly', 'score', 'scoreName', 'target', 'path'];

    for (let i = 0; i < options.length; i++) {
      if (typeof this.opt[options[i]] === 'function') {
Severity: Minor
Found in src/raty.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

Avoid too many return statements within this function.
Open

    return 'starOn'; // Up: [x.26 ...] || [x.6 ...]
Severity: Major
Found in src/raty.js - About 30 mins to fix

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

  _createStars() {
    for (let i = 1; i <= this.opt.number; i++) {
      const attributes = this._attributesForIndex(i);

      let star = document.createElement(this.opt.starType);
Severity: Minor
Found in src/raty.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

Severity
Category
Status
Source
Language