meteor/meteor

View on GitHub
packages/minimongo/common.js

Summary

Maintainability
F
5 days
Test Coverage

File common.js has 861 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import LocalCollection from './local_collection.js';

export const hasOwn = Object.prototype.hasOwnProperty;

// Each element selector contains:
Severity: Major
Found in packages/minimongo/common.js - About 2 days to fix

    Function $near has 65 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      $near(operand, valueSelector, matcher, isRoot) {
        if (!isRoot) {
          throw Error('$near can\'t be inside another $ operator');
        }
    
    
    Severity: Major
    Found in packages/minimongo/common.js - About 2 hrs to fix

      Function makeLookupFunction has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export function makeLookupFunction(key, options = {}) {
        const parts = key.split('.');
        const firstPart = parts.length ? parts[0] : '';
        const lookupRest = (
          parts.length > 1 &&
      Severity: Major
      Found in packages/minimongo/common.js - About 2 hrs to fix

        Function compileElementSelector has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            compileElementSelector(operand) {
              if (typeof operand === 'string') {
                const operandAliasMap = {
                  'double': 1,
                  'string': 2,
        Severity: Minor
        Found in packages/minimongo/common.js - About 1 hr to fix

          Function compileElementSelector has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              compileElementSelector(operand, valueSelector, matcher) {
                if (!LocalCollection._isPlainObject(operand)) {
                  throw Error('$elemMatch need an object');
                }
          
          
          Severity: Minor
          Found in packages/minimongo/common.js - About 1 hr to fix

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

            export function makeLookupFunction(key, options = {}) {
              const parts = key.split('.');
              const firstPart = parts.length ? parts[0] : '';
              const lookupRest = (
                parts.length > 1 &&
            Severity: Minor
            Found in packages/minimongo/common.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 operatorBranchedMatcher has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function operatorBranchedMatcher(valueSelector, matcher, isRoot) {
              // Each valueSelector works separately on the various branches.  So one
              // operator can match one branch and another can match another branch.  This
              // is OK.
              const operatorMatchers = Object.keys(valueSelector).map(operator => {
            Severity: Minor
            Found in packages/minimongo/common.js - About 1 hr to fix

              Function projectionDetails has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export function projectionDetails(fields) {
                // Find the non-_id keys (_id is handled specially because it is included
                // unless explicitly excluded). Sort the keys, so that our code to detect
                // overlaps like 'foo' and 'foo.bar' can assume that 'foo' comes first.
                let fieldsKeys = Object.keys(fields).sort();
              Severity: Minor
              Found in packages/minimongo/common.js - About 1 hr to fix

                Function pathsToTree has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export function pathsToTree(paths, newLeafFn, conflictFn, root = {}) {
                  paths.forEach(path => {
                    const pathArray = path.split('.');
                    let tree = root;
                
                
                Severity: Minor
                Found in packages/minimongo/common.js - About 1 hr to fix

                  Function operatorMatchers has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    const operatorMatchers = Object.keys(valueSelector).map(operator => {
                      const operand = valueSelector[operator];
                  
                      const simpleRange = (
                        ['$lt', '$lte', '$gt', '$gte'].includes(operator) &&
                  Severity: Minor
                  Found in packages/minimongo/common.js - About 1 hr to fix

                    Function andSomeMatchers has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    function andSomeMatchers(subMatchers) {
                      if (subMatchers.length === 0) {
                        return everythingMatcher;
                      }
                    
                    
                    Severity: Minor
                    Found in packages/minimongo/common.js - About 1 hr to fix

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

                      export function compileDocumentSelector(docSelector, matcher, options = {}) {
                        const docMatchers = Object.keys(docSelector).map(key => {
                          const subSelector = docSelector[key];
                      
                          if (key.substr(0, 1) === '$') {
                      Severity: Minor
                      Found in packages/minimongo/common.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 compileElementSelector has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          compileElementSelector(operand) {
                            if (typeof operand === 'string') {
                              const operandAliasMap = {
                                'double': 1,
                                'string': 2,
                      Severity: Minor
                      Found in packages/minimongo/common.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 compileElementSelector has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                          compileElementSelector(operand, valueSelector) {
                            if (!(typeof operand === 'string' || operand instanceof RegExp)) {
                              throw Error('$regex has to be a string or RegExp');
                            }
                      
                      
                      Severity: Minor
                      Found in packages/minimongo/common.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 operatorBranchedMatcher has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                      Open

                      function operatorBranchedMatcher(valueSelector, matcher, isRoot) {
                        // Each valueSelector works separately on the various branches.  So one
                        // operator can match one branch and another can match another branch.  This
                        // is OK.
                        const operatorMatchers = Object.keys(valueSelector).map(operator => {
                      Severity: Minor
                      Found in packages/minimongo/common.js - 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

                          return result;
                      Severity: Major
                      Found in packages/minimongo/common.js - About 30 mins to fix

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

                          $near(operand, valueSelector, matcher, isRoot) {
                            if (!isRoot) {
                              throw Error('$near can\'t be inside another $ operator');
                            }
                        
                        
                        Severity: Minor
                        Found in packages/minimongo/common.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

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

                          $bitsAnyClear: {
                            compileElementSelector(operand) {
                              const mask = getOperandBitmask(operand, '$bitsAnyClear');
                              return value => {
                                const bitmask = getValueBitmask(value, mask.length);
                        Severity: Major
                        Found in packages/minimongo/common.js and 1 other location - About 2 hrs to fix
                        packages/minimongo/common.js on lines 132..140

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

                        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

                          $bitsAllSet: {
                            compileElementSelector(operand) {
                              const mask = getOperandBitmask(operand, '$bitsAllSet');
                              return value => {
                                const bitmask = getValueBitmask(value, mask.length);
                        Severity: Major
                        Found in packages/minimongo/common.js and 1 other location - About 2 hrs to fix
                        packages/minimongo/common.js on lines 159..167

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

                        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

                        There are no issues that match your filters.

                        Category
                        Status