ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/components/miq_debug/toast-item.jsx

Summary

Maintainability
A
1 hr
Test Coverage

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

const sanitize = function(data) {
  if (isPlainObject(data) && (data.error || data.message)) {
    return (data.error || '').toString() + ' ' + (data.message || '').toString();
  }

Severity: Minor
Found in app/javascript/components/miq_debug/toast-item.jsx - 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

Avoid too many return statements within this function.
Open

  return data.toString();
Severity: Major
Found in app/javascript/components/miq_debug/toast-item.jsx - About 30 mins to fix

Unexpected string concatenation.
Open

    return (data.error || '').toString() + ' ' + (data.message || '').toString();

Suggest using template literals instead of string concatenation. (prefer-template)

In ES2015 (ES6), we can use template literals instead of string concatenation.

var str = "Hello, " + name + "!";
/*eslint-env es6*/

var str = `Hello, ${name}!`;

Rule Details

This rule is aimed to flag usage of + operators with strings.

Examples

Examples of incorrect code for this rule:

/*eslint prefer-template: "error"*/

var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);

Examples of correct code for this rule:

/*eslint prefer-template: "error"*/
/*eslint-env es6*/

var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;

// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";

When Not To Use It

This rule should not be used in ES3/5 environments.

In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.

Related Rules

Empty components are self-closing
Open

          <span className="pficon pficon-close"></span>

For more information visit Source: http://eslint.org/docs/rules/

'close' is missing in props validation
Open

export const ToastItem = ({ type, data, close }) => {

For more information visit Source: http://eslint.org/docs/rules/

'type' is missing in props validation
Open

export const ToastItem = ({ type, data, close }) => {

For more information visit Source: http://eslint.org/docs/rules/

'data' is missing in props validation
Open

export const ToastItem = ({ type, data, close }) => {

For more information visit Source: http://eslint.org/docs/rules/

Empty components are self-closing
Open

        <span className={icon}></span>

For more information visit Source: http://eslint.org/docs/rules/

There are no issues that match your filters.

Category
Status