ContentMine/thresher

View on GitHub

Showing 227 of 227 total issues

Similar blocks of code found in 11 locations. Consider refactoring.
Open

        if (c == '+') {
            types.push(XPathParser.PLUS);
            values.push(c);
            c = s.charAt(pos++);
            continue;
Severity: Major
Found in lib/xpath.js and 10 other locations - About 1 hr to fix
lib/xpath.js on lines 783..788
lib/xpath.js on lines 789..794
lib/xpath.js on lines 795..800
lib/xpath.js on lines 801..806
lib/xpath.js on lines 807..812
lib/xpath.js on lines 813..818
lib/xpath.js on lines 819..824
lib/xpath.js on lines 831..836
lib/xpath.js on lines 837..842
lib/xpath.js on lines 843..848

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if (c == '.') {
                types.push(XPathParser.DOUBLEDOT);
                values.push("..");
                c = s.charAt(pos++);
                continue;
Severity: Major
Found in lib/xpath.js and 1 other location - About 1 hr to fix
lib/xpath.js on lines 956..961

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if (c == '/') {
                types.push(XPathParser.DOUBLESLASH);
                values.push("//");
                c = s.charAt(pos++);
                continue;
Severity: Major
Found in lib/xpath.js and 1 other location - About 1 hr to fix
lib/xpath.js on lines 852..857

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 11 locations. Consider refactoring.
Open

        if (c == ')') {
            types.push(XPathParser.RIGHTPARENTHESIS);
            values.push(c);
            c = s.charAt(pos++);
            continue;
Severity: Major
Found in lib/xpath.js and 10 other locations - About 1 hr to fix
lib/xpath.js on lines 783..788
lib/xpath.js on lines 795..800
lib/xpath.js on lines 801..806
lib/xpath.js on lines 807..812
lib/xpath.js on lines 813..818
lib/xpath.js on lines 819..824
lib/xpath.js on lines 825..830
lib/xpath.js on lines 831..836
lib/xpath.js on lines 837..842
lib/xpath.js on lines 843..848

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 11 locations. Consider refactoring.
Open

        if (c == ',') {
            types.push(XPathParser.COMMA);
            values.push(c);
            c = s.charAt(pos++);
            continue;
Severity: Major
Found in lib/xpath.js and 10 other locations - About 1 hr to fix
lib/xpath.js on lines 783..788
lib/xpath.js on lines 789..794
lib/xpath.js on lines 795..800
lib/xpath.js on lines 801..806
lib/xpath.js on lines 807..812
lib/xpath.js on lines 819..824
lib/xpath.js on lines 825..830
lib/xpath.js on lines 831..836
lib/xpath.js on lines 837..842
lib/xpath.js on lines 843..848

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 11 locations. Consider refactoring.
Open

        if (c == '[') {
            types.push(XPathParser.LEFTBRACKET);
            values.push(c);
            c = s.charAt(pos++);
            continue;
Severity: Major
Found in lib/xpath.js and 10 other locations - About 1 hr to fix
lib/xpath.js on lines 783..788
lib/xpath.js on lines 789..794
lib/xpath.js on lines 801..806
lib/xpath.js on lines 807..812
lib/xpath.js on lines 813..818
lib/xpath.js on lines 819..824
lib/xpath.js on lines 825..830
lib/xpath.js on lines 831..836
lib/xpath.js on lines 837..842
lib/xpath.js on lines 843..848

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 11 locations. Consider refactoring.
Open

        if (c == '@') {
            types.push(XPathParser.AT);
            values.push(c);
            c = s.charAt(pos++);
            continue;
Severity: Major
Found in lib/xpath.js and 10 other locations - About 1 hr to fix
lib/xpath.js on lines 783..788
lib/xpath.js on lines 789..794
lib/xpath.js on lines 795..800
lib/xpath.js on lines 801..806
lib/xpath.js on lines 813..818
lib/xpath.js on lines 819..824
lib/xpath.js on lines 825..830
lib/xpath.js on lines 831..836
lib/xpath.js on lines 837..842
lib/xpath.js on lines 843..848

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 55.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

Scraper.prototype.runRegex = function(string, regex) {
  var re;
  if (regex instanceof Object) {
    if (regex.flags) {
      var flags = regex.flags.join('');
Severity: Minor
Found in lib/scraper.js - 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

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

url.checkUrl = function(theUrl) {
  var protocol = /^(f|ht)tps?:\/\//i.test(theUrl);
  var domain = /:\/\/\w+(\.[^:]+)*([:\/].+)*$/i.test(theUrl);
  if (!protocol || !domain) {
    // not a valid URL
Severity: Minor
Found in lib/url.js - 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

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    if (arguments.length != 2 || !Utilities.instance_of((ns = arguments[1].evaluate(c)), XNodeSet)) {
        throw new Error("Function sum expects (node-set)");
    }
Severity: Minor
Found in lib/xpath.js and 1 other location - About 55 mins to fix
lib/xpath.js on lines 3298..3300

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 53.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

    if (arguments.length != 2 || !Utilities.instance_of(ns = arguments[1].evaluate(c), XNodeSet)) {
        throw new Error("Function count expects (node-set)");
    }
Severity: Minor
Found in lib/xpath.js and 1 other location - About 55 mins to fix
lib/xpath.js on lines 3611..3613

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 53.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

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

ElementQueue.prototype.addElement = function(e) {
  var eq = this;
  // We keep track of which elements
  // are followed by others, so we can rapidly
  // decide which ones needs adjusting in the queue
Severity: Minor
Found in lib/elementQueue.js - 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

Avoid deeply nested control flow statements.
Open

            if (!e.selector) {
              problems.push('element ' + k + ' has no selector');
            }
Severity: Major
Found in lib/scraper.js - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                        while (c >= '0' && c <= '9') {
                            number += c;
                            c = s.charAt(pos++);
                        }
    Severity: Major
    Found in lib/xpath.js - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          while (Utilities.isNCNameChar(c.charCodeAt(0))) {
                              name += c;
                              c = s.charAt(pos++);
                          }
      Severity: Major
      Found in lib/xpath.js - About 45 mins to fix

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

        function getChildElements(obj) {
          var elementsArray = [];
          // process followables first, they
          // will be excluded from results later
          if (obj.followables) {
        Severity: Minor
        Found in lib/scraper.js - 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

        Avoid deeply nested control flow statements.
        Open

                                do {
                                    for (var m = st.pop(); m != null; ) {
                                        if (step.nodeTest.matches(m, xpc)) {
                                            newNodes.push(m);
                                        }
        Severity: Major
        Found in lib/xpath.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if (xpc.virtualRoot != null) {
                                      st = [ xpc.virtualRoot ];
                                  } else {
                                      st = xpc.contextNode.nodeType == 9 /*Node.DOCUMENT_NODE*/
                                          ? [ xpc.contextNode ]
          Severity: Major
          Found in lib/xpath.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                if (name == "div") {
                                    types.push(XPathParser.DIV);
                                    values.push(name);
                                    continue;
                                }
            Severity: Major
            Found in lib/xpath.js - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (xpc.contextNode.nodeType == 2 /*Node.ATTRIBUTE_NODE*/) {
                                          m = this.getOwnerElement(xpc.contextNode);
                                      } else {
                                          m = xpc.contextNode.parentNode;
                                      }
              Severity: Major
              Found in lib/xpath.js - About 45 mins to fix
                Severity
                Category
                Status
                Source
                Language