digitalheir/bibtex-js

View on GitHub

Showing 29 of 66 total issues

File ts-parser.ts has 587 lines of code (exceeds 250 allowed). Consider refactoring.
Open

function id(x) {
    return x[0];
}

const isNumber = function (x) {
Severity: Major
Found in src/parser/ts-parser.ts - About 1 day to fix

    Function splitOnPattern has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

    export function splitOnPattern(data: BibStringData, pattern: RegExp, stopAfter?: number): BibStringData[] {
        const splitted: BibStringData[] = [];
    
        let buffer: BibStringData = [];
        for (const datum of data) {
    Severity: Minor
    Found in src/bibfile/datatype/string/bib-string-utils.ts - About 5 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 flattenMyArray has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    export const flattenMyArray = function (arr: any[], result?: any[]): any[] {
        if (!result) result = [];
        for (let i = 0, length = arr.length; i < length; i++) {
            const value: any = arr[i];
            if (Array.isArray(value)) {
    Severity: Minor
    Found in src/util.ts - 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 globContiguousStrings has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

    export function globContiguousStrings(data: BibStringData): (BibStringDatum | ContiguousSimpleString)[] {
        const result: (BibStringDatum | ContiguousSimpleString)[] = [];
        for (const element of data) {
            if (isString(element) || isNumber(element)) {
                if (result.length <= 0) {
    Severity: Minor
    Found in src/bibfile/datatype/string/bib-string-utils.ts - 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 flattenQuotedString has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    function flattenQuotedString(data: BibStringDatum, hideQuotes?: boolean): BibStringDatum | BibStringData {
        if (isBracedString(data))
            return data;
        if (isQuotedString(data)) {
            const flattenedQuotedString: BibStringData = flattenQuotedStrings(data.data, true);
    Severity: Minor
    Found in src/bibfile/datatype/string/bib-string-utils.ts - 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 splitOnPattern has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function splitOnPattern(data: BibStringData, pattern: RegExp, stopAfter?: number): BibStringData[] {
        const splitted: BibStringData[] = [];
    
        let buffer: BibStringData = [];
        for (const datum of data) {
    Severity: Minor
    Found in src/bibfile/datatype/string/bib-string-utils.ts - About 1 hr to fix

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

      const flattenO = (wrapper: any): string => isString(wrapper) ? wrapper
          : typeof wrapper === "number" ? wrapper.toString()
              // : (isString(wrapper.type) && wrapper.type === "@bib" && isString(wrapper.string)) ? "@" + wrapper.string
              : wrapper["type"] === "@bib" ? "@" + mustBeString(wrapper.string)
                  : wrapper["type"] === "escapedEntry" ? "\\" + flattenO(wrapper.data)
      Severity: Minor
      Found in src/bibfile/bib-entry/BibComment.ts - 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 constructor has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          constructor(content: (NonBibComment | BibComment)[]) {
              this.content = content;
              this.comments = content.filter(isBibComment).map(c => {
                  if (isBibComment(c))return c; else throw new Error();
              });
      Severity: Minor
      Found in src/bibfile/BibFile.ts - About 1 hr to fix

        Function startsWithLowerCase has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        function startsWithLowerCase(authorToken: BibStringDatum) {
            if (isString(authorToken)) {
                if (!authorToken) return false;
                const ch = authorToken.charAt(0);
                return ch.toLowerCase() === ch && ch.toUpperCase() !== ch;
        Severity: Minor
        Found in src/bibfile/bib-entry/bibliographic-entity/Author.ts - 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 findError has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        export const findError = (entry: BibEntry, field: MandatoryFields): (Error | undefined) => {
            const fields = entry.fields;
            if (isString(field)) {
                if (!fields[field])
                    return new Error("Warning: expected " + entry.type + " with id " + entry._id

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

        export function globContiguousStrings(data: BibStringData): (BibStringDatum | ContiguousSimpleString)[] {
            const result: (BibStringDatum | ContiguousSimpleString)[] = [];
            for (const element of data) {
                if (isString(element) || isNumber(element)) {
                    if (result.length <= 0) {
        Severity: Minor
        Found in src/bibfile/datatype/string/bib-string-utils.ts - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                              if (stopAfter === undefined || stopAfter > 0)
                                  match = pattern.exec(datum);
                              else
                                  match = undefined;
          Severity: Major
          Found in src/bibfile/datatype/string/bib-string-utils.ts - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (stopAfter === undefined || stopAfter > 0) {
                                    splitted.push(buffer);
                                    buffer = [];
                                    if (stopAfter !== undefined && stopAfter > 0) stopAfter--;
                                }
            Severity: Major
            Found in src/bibfile/datatype/string/bib-string-utils.ts - About 45 mins to fix

              Function parseStringComponent has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export function parseStringComponent(braceDepth: number, obj: any): BibStringComponent | string | number | StringRef {
                  if (isNumber(obj) || isString(obj))
                      return /*new BibStringComponent(typeof obj, braceDepth, [*/obj/*])*/;
              
                  if (isStringRef(obj))
              Severity: Minor
              Found in src/bibfile/datatype/string/bib-string-utils.ts - About 45 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 joinTokens has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function joinTokens(arr) {
                  const strs: any = [];
                  for (let i = 0; i < arr.length; i++) {
                      if (typeof arr[i] === "object") {
                          if (!arr[i].string) throw new Error("Expected token to have a string field called 'string' in object " + JSON.stringify(arr[i]));
              Severity: Minor
              Found in src/parser/ts-parser.ts - About 45 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 firstVonLast has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              function firstVonLast(outer: BibStringData): AuthorName {
                  const authorTokens: BibStringData[] = splitOnPattern(outer, WHITESPACES);
              
                  let vonStartInclusive = -1;
                  let vonEndExclusive = -1;
              Severity: Minor
              Found in src/bibfile/bib-entry/bibliographic-entity/Author.ts - About 45 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 vonLastFirst has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function vonLastFirst(vonLastStr: BibStringData, firstStr: BibStringData) {
                  const vonLast = splitOnPattern(vonLastStr, WHITESPACES);
                  const first = splitOnPattern(firstStr, WHITESPACES);
              
                  let vonStartInclusive = -1;
              Severity: Minor
              Found in src/bibfile/bib-entry/bibliographic-entity/Author.ts - 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 eatNumericString has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private eatNumericString(startAt: NumericChar): number | NumberToken {
                      const nums: NumericChar[] = [startAt];
              
                      const nextPos = this.pos + 1;
                      for (let newPos = nextPos; newPos < this.len + 1; newPos++) {
              Severity: Minor
              Found in src/lexer/Lexer.ts - 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 vonLastJrFirst has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function vonLastJrFirst(vonLastStr: BibStringData, jrStr: BibStringData, firstStr: BibStringData) {
                  const vonLast = splitOnPattern(vonLastStr, WHITESPACES);
                  const first = splitOnPattern(firstStr, WHITESPACES);
                  const jr = splitOnPattern(jrStr, WHITESPACES);
              
              
              Severity: Minor
              Found in src/bibfile/bib-entry/bibliographic-entity/Author.ts - 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

                  else if (obj.constructor == Array) return obj.map(word2string).join("");
              Severity: Major
              Found in src/bibfile/bib-entry/bibliographic-entity/Author.ts - About 30 mins to fix
                Severity
                Category
                Status
                Source
                Language