showdownjs/showdown

View on GitHub
src/helpers.js

Summary

Maintainability
F
1 wk
Test Coverage

File helpers.js has 2173 lines of code (exceeds 250 allowed). Consider refactoring.
Open

/**
 * showdownjs helper functions
 */

if (!showdown.hasOwnProperty('helper')) {
Severity: Major
Found in src/helpers.js - About 6 days to fix

Function rgxFindMatchPos has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

var rgxFindMatchPos = function (str, left, right, flags) {
  'use strict';
  var f = flags || '',
      g = f.indexOf('g') > -1,
      x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
Severity: Minor
Found in src/helpers.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 forEach has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

showdown.helper.forEach = function (obj, callback) {
  'use strict';
  // check if obj is defined
  if (showdown.helper.isUndefined(obj)) {
    throw new Error('obj param is required');
Severity: Minor
Found in src/helpers.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 Event has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

showdown.helper.Event = function (name, text, params) {
  'use strict';

  var regexp = params.regexp || null;
  var matches = params.matches || {};
Severity: Minor
Found in src/helpers.js - About 1 hr to fix

Function replaceRecursiveRegExp has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
  'use strict';

  if (!showdown.helper.isFunction(replacement)) {
    var repStr = replacement;
Severity: Minor
Found in src/helpers.js - About 1 hr to fix

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

var rgxFindMatchPos = function (str, left, right, flags) {
  'use strict';
  var f = flags || '',
      g = f.indexOf('g') > -1,
      x = new RegExp(left + '|' + right, 'g' + f.replace(/g/g, '')),
Severity: Minor
Found in src/helpers.js - About 1 hr to fix

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

showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
  'use strict';

  if (!showdown.helper.isFunction(replacement)) {
    var repStr = replacement;
Severity: Minor
Found in src/helpers.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

Avoid deeply nested control flow statements.
Open

        if (!--t) {
          end = m.index + m[0].length;
          var obj = {
            left: {start: start, end: s},
            match: {start: s, end: m.index},
Severity: Major
Found in src/helpers.js - About 45 mins to fix

Function replaceRecursiveRegExp has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

showdown.helper.replaceRecursiveRegExp = function (str, replacement, left, right, flags) {
Severity: Minor
Found in src/helpers.js - About 35 mins to fix

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

showdown.helper.repeat = function (str, count) {
  'use strict';
  // use built-in method if it's available
  if (!showdown.helper.isUndefined(String.prototype.repeat)) {
    return str.repeat(count);
Severity: Minor
Found in src/helpers.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