BeameryHQ/Ditto

View on GitHub

Showing 19 of 19 total issues

Function map has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

async function map(document, mappings, plugins) {

    /**
     * @function processMappings
     *
Severity: Minor
Found in ditto/mappers/map.js - About 1 day 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 map has 123 lines of code (exceeds 25 allowed). Consider refactoring.
Open

async function map(document, mappings, plugins) {

    /**
     * @function processMappings
     *
Severity: Major
Found in ditto/mappers/map.js - About 4 hrs to fix

    Function processMappings has 118 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function processMappings(mappings, document, result, parentKey) {
    
            _.each(mappings, function(path, key) {
    
                key = parentKey ? `${parentKey}.${key}` : key;
    Severity: Major
    Found in ditto/mappers/map.js - About 4 hrs to fix

      Function cleanURI has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

      function cleanURI(source, service) {
      
          if (!!source && typeof(source) === "string") {
      
          // Replace all spaces with nothing, and truncate to 400 chars,
      Severity: Minor
      Found in ditto/plugins/cleanURI.js - About 2 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 getValue has 32 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              function getValue(path, subDocument) {
      
                  if (!path) return;
      
                  if (path === '!') return document;
      Severity: Minor
      Found in ditto/mappers/map.js - About 1 hr to fix

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

            return _.get(_.filter(countries, _country => {
                return _country.alpha2Code.toLowerCase() === countryCode.toLowerCase()
            })[0], 'alpha3Code', null);
        Severity: Major
        Found in ditto/plugins/getCountryCode.js and 1 other location - About 1 hr to fix
        ditto/plugins/getCountryCode.js on lines 21..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 57.

        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

                return _.get(_.filter(countries, _country => {
                    return _country.name.toLowerCase() === country.toLowerCase()
                })[0], 'alpha3Code', null);
        Severity: Major
        Found in ditto/plugins/getCountryCode.js and 1 other location - About 1 hr to fix
        ditto/plugins/getCountryCode.js on lines 26..28

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

        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 parseMappings has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                            function parseMappings(result, innerResult, path, key, $value, $key) {
        Severity: Minor
        Found in ditto/mappers/map.js - About 45 mins to fix

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

          function getLinkType(source, service) {
          
              if (!source || typeof(source) !== "string") return null;
          
              if(!!service && MESSAGING_SERVICES.find(item => item.toLowerCase().trim() === service.toLowerCase().trim())){
          Severity: Minor
          Found in ditto/plugins/getLinkType.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 (!!path.prerequisite) {
                                              if (!!eval(path.prerequisite)) _.set(result, fullPath, innerResult);
                                          } else _.set(result, fullPath, innerResult);
          Severity: Major
          Found in ditto/mappers/map.js - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                            if (!!path.prerequisite) {
                                                if (!!eval(path.prerequisite)) _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
                                            } else _.updateWith(result, key, function(theArray){ theArray.push(innerResult); return theArray }, []);
            Severity: Major
            Found in ditto/mappers/map.js - About 45 mins to fix

              Function extractName has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              function extractName(fullName, position) {
              
                  const ALLOWED_POSITIONS = ["firstName", "middleName", "lastName"];
              
                  if (!!fullName && typeof(fullName) === "string"
              Severity: Minor
              Found in ditto/plugins/extractName.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 _.isPlainObject(subDocument) ? _.get(subDocument, path) :  _.get(document, path);
              Severity: Major
              Found in ditto/mappers/map.js - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                                    return plugins[functionCall].apply(null, paramteresValues);
                Severity: Major
                Found in ditto/mappers/map.js - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                              } else return getValue(path, $value);
                  Severity: Major
                  Found in ditto/mappers/map.js - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                        } else return null;
                    Severity: Major
                    Found in ditto/plugins/cleanURI.js - About 30 mins to fix

                      Avoid too many return statements within this function.
                      Open

                                      return isValidValue ? applyTransformation(null, parameters.targetValue, null, subDocument) : null;
                      Severity: Major
                      Found in ditto/mappers/map.js - About 30 mins to fix

                        Avoid too many return statements within this function.
                        Open

                                        return getValue(pathWithDefault[0], subDocument) || getValue(`${pathWithDefault[1]}`);
                        Severity: Major
                        Found in ditto/mappers/map.js - About 30 mins to fix

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

                          function getLinkService(source, service) {
                          
                              if (!source || typeof(source) !== "string" || !Joi.validate(source, Joi.string().email({errorLevel: true})).error ) return null;
                              if (!!service) return service.replace(/\s\s+/g, "").trim().toLowerCase();
                          
                          
                          Severity: Minor
                          Found in ditto/plugins/getLinkService.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

                          Severity
                          Category
                          Status
                          Source
                          Language