collinbrewer/predicate

View on GitHub

Showing 41 of 41 total issues

Function evaluateWithObject has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
Open

ComparisonPredicate.prototype.evaluateWithObject = function (o, vars) {
    vars || (vars = this._substitutionVariables);

    var leftExpressionValue = (this.left.type === 'variable' ? this.left.getValueWithObject(o, vars) : this.left.getValueWithObject(o));
    var rightExpressionValue = (this.right.type === 'variable' ? this.right.getValueWithObject(o, vars) : this.right.getValueWithObject(o));
Severity: Minor
Found in src/types/comparison-predicate.js - About 6 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

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

    context('#and', function () {
        it('should return a new and compound predicate', function () {
            var predicate = CompoundPredicate.parse('1 AND 2').and(CompoundPredicate.parse('3 and 4'));
            var subpredicates = predicate.getSubpredicates();

Severity: Major
Found in src/types/compound-predicate.test.js and 1 other location - About 6 hrs to fix
src/types/compound-predicate.test.js on lines 81..90

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 156.

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

    context('#or', function () {
        it('should return a new or compound predicate', function () {
            var predicate = CompoundPredicate.parse('1 AND 2').or(CompoundPredicate.parse('3 and 4'));
            var subpredicates = predicate.getSubpredicates();

Severity: Major
Found in src/types/compound-predicate.test.js and 1 other location - About 6 hrs to fix
src/types/compound-predicate.test.js on lines 70..79

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 156.

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 parse has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
Open

CompoundPredicate.parse = function (str, vars) {
    var predicate;

    function getParts (s) {
        var matches = s.match(regex);
Severity: Minor
Found in src/types/compound-predicate.js - 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

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

        it('returns a comparison predicate from arg list with selector', function () {
            var predicate = new ComparisonPredicate('left', 'right', 'operator');
            expect(predicate.left).to.exist;
            expect(predicate.right).to.exist;
            expect(predicate.operator).to.equal('operator');
Severity: Major
Found in src/types/comparison-predicate.test.js and 1 other location - About 3 hrs to fix
src/types/comparison-predicate.test.js on lines 17..23

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 110.

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

        it('returns a comparison predicate from arg list with operator', function () {
            var predicate = new ComparisonPredicate('left', 'right', 'operator');
            expect(predicate.left).to.exist;
            expect(predicate.right).to.exist;
            expect(predicate.operator).to.equal('operator');
Severity: Major
Found in src/types/comparison-predicate.test.js and 1 other location - About 3 hrs to fix
src/types/comparison-predicate.test.js on lines 25..31

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 110.

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

CompoundPredicate.parse = function (str, vars) {
    var predicate;

    function getParts (s) {
        var matches = s.match(regex);
Severity: Major
Found in src/types/compound-predicate.js - About 3 hrs to fix

    Function evaluateWithObject has 57 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    ComparisonPredicate.prototype.evaluateWithObject = function (o, vars) {
        vars || (vars = this._substitutionVariables);
    
        var leftExpressionValue = (this.left.type === 'variable' ? this.left.getValueWithObject(o, vars) : this.left.getValueWithObject(o));
        var rightExpressionValue = (this.right.type === 'variable' ? this.right.getValueWithObject(o, vars) : this.right.getValueWithObject(o));
    Severity: Major
    Found in src/types/comparison-predicate.js - About 2 hrs to fix

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

              it('returns a multiple coumpound predicates', function () {
                  var predicate = Predicate.parse('(1==1 && 2==2) || (3==3 && 4==4)');
      
                  expect(predicate).to.have.property('subpredicates');
                  expect(predicate.subpredicates).to.have.length(2);
      Severity: Major
      Found in src/predicate.test.js and 1 other location - About 2 hrs to fix
      src/predicate.test.js on lines 17..21

      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 78.

      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

              it('returns a complex compound predicate', function () {
                  var predicate = Predicate.parse('1==1 && 2==2 && 3==3');
                  expect(predicate).to.have.property('subpredicates');
                  expect(predicate.subpredicates).to.have.length(3);
              });
      Severity: Major
      Found in src/predicate.test.js and 1 other location - About 2 hrs to fix
      src/predicate.test.js on lines 84..89

      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 78.

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

          function splitByGates (s) {
              var subpredicates = [];
              var gate;
              var i;
              var l;
      Severity: Major
      Found in src/types/compound-predicate.js - About 2 hrs to fix

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

        CompoundPredicate.prototype.stringify = function () {
            return this.subpredicates.map(function (predicate) {
                return predicate.stringify();
            }).join(' ' + this.gate + ' ');
        };
        Severity: Major
        Found in src/types/compound-predicate.js and 1 other location - About 1 hr to fix
        src/types/compound-predicate.js on lines 183..187

        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 70.

        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

        CompoundPredicate.prototype.toLocaleString = function () {
            return this.subpredicates.map(function (p) {
                return p.toLocaleString();
            }).join(' ' + this.gate + ' ');
        };
        Severity: Major
        Found in src/types/compound-predicate.js and 1 other location - About 1 hr to fix
        src/types/compound-predicate.js on lines 174..178

        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 70.

        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

            context('#toLocaleString', function () {
                it('should return a natural language string', function () {
                    var predicate = new CompoundPredicate('AND', [1, 2, 3]);
        
                    expect(predicate.toLocaleString()).to.equal('1 and 2 and 3');
        Severity: Major
        Found in src/types/compound-predicate.test.js and 1 other location - About 1 hr to fix
        src/types/compound-predicate.test.js on lines 54..60

        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 68.

        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

            context('#stringify', function () {
                it('should return a serialized string', function () {
                    var predicate = new CompoundPredicate('AND', [1, 2, 3]);
        
                    expect(predicate.stringify()).to.equal('1 and 2 and 3');
        Severity: Major
        Found in src/types/compound-predicate.test.js and 1 other location - About 1 hr to fix
        src/types/compound-predicate.test.js on lines 62..68

        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 68.

        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

            context('#stringify', function () {
                it('should return a serialized string', function () {
                    var predicate = new ComparisonPredicate(1, 2, '<');
        
                    expect(predicate.stringify()).to.equal('1 < 2');
        Severity: Major
        Found in src/types/comparison-predicate.test.js and 1 other location - About 1 hr to fix
        src/types/comparison-predicate.test.js on lines 68..74

        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 65.

        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

            context('#toLocaleString', function () {
                it('should return a natural language string', function () {
                    var predicate = new ComparisonPredicate(1, 2, '<');
        
                    expect(predicate.toLocaleString()).to.equal('1 less than 2');
        Severity: Major
        Found in src/types/comparison-predicate.test.js and 1 other location - About 1 hr to fix
        src/types/comparison-predicate.test.js on lines 60..66

        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 65.

        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 evaluateWithObject has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

        CompoundPredicate.prototype.evaluateWithObject = function (o, vars) {
            vars || (vars = this._substitutionVariables);
        
            var subpredicates = this.subpredicates;
            var gate = this.gate;
        Severity: Minor
        Found in src/types/compound-predicate.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

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

                it('should end with', function () {
                    var predicate = ComparisonPredicate.parse('"foobar" endswith "bar"');
        
                    expect(predicate.evaluateWithObject()).to.be.true;
                });
        Severity: Major
        Found in src/types/comparison-predicate.test.js and 7 other locations - About 55 mins to fix
        src/types/comparison-predicate.test.js on lines 131..135
        src/types/comparison-predicate.test.js on lines 143..147
        src/types/comparison-predicate.test.js on lines 149..153
        src/types/compound-predicate.test.js on lines 93..96
        src/types/compound-predicate.test.js on lines 98..101
        src/types/compound-predicate.test.js on lines 103..106
        src/types/compound-predicate.test.js on lines 108..111

        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 54.

        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 8 locations. Consider refactoring.
        Open

                it('should begin with', function () {
                    var predicate = ComparisonPredicate.parse('"foobar" beginswith "foo"');
        
                    expect(predicate.evaluateWithObject()).to.be.true;
                });
        Severity: Major
        Found in src/types/comparison-predicate.test.js and 7 other locations - About 55 mins to fix
        src/types/comparison-predicate.test.js on lines 137..141
        src/types/comparison-predicate.test.js on lines 143..147
        src/types/comparison-predicate.test.js on lines 149..153
        src/types/compound-predicate.test.js on lines 93..96
        src/types/compound-predicate.test.js on lines 98..101
        src/types/compound-predicate.test.js on lines 103..106
        src/types/compound-predicate.test.js on lines 108..111

        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 54.

        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

        Severity
        Category
        Status
        Source
        Language