digitalheir/bibliography-js

View on GitHub
depr/bibtex/field_value/utils.js

Summary

Maintainability
A
3 hrs
Test Coverage

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

const getFirstLetter = function (wordObj) {
  if (typeof wordObj === 'string') {
    if (wordObj.length > 1 && wordObj.charAt(0) == '/') return wordObj.charAt(1);
    else if (wordObj.length > 0) return wordObj.charAt(0);
    else return null;
Severity: Minor
Found in depr/bibtex/field_value/utils.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 too many return statements within this function.
Open

  else if (wordObj.unicode)  return getFirstLetter(wordObj.unicode);
Severity: Major
Found in depr/bibtex/field_value/utils.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

      else if (authorToken.constructor == Array) return authorToken.map(flattenToString).join('');
    Severity: Major
    Found in depr/bibtex/field_value/utils.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

        else if (wordObj.constructor == Array) return getFirstLetter(flattenToString(wordObj).trim());
      Severity: Major
      Found in depr/bibtex/field_value/utils.js - About 30 mins to fix

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

        function flattenToString(authorToken) {
          if (typeof authorToken === 'string') return authorToken;
          else if (authorToken.type == 'braced')  return flattenToString(authorToken.data);
          else if (authorToken.type == 'ws') {
            //console.log(authorToken)
        Severity: Minor
        Found in depr/bibtex/field_value/utils.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