r2js/r2admin

View on GitHub
lib/update.js

Summary

Maintainability
C
1 day
Test Coverage

Function exports has 95 lines of code (exceeds 25 allowed). Consider refactoring.
Open

module.exports = (app, conf = {}) => {
  const AdminUtils = adminUtils(app);
  const { baseUrl = 'admin' } = conf;
  const { errors } = AdminUtils;
  const { created } = app.handler;
Severity: Major
Found in lib/update.js - About 3 hrs to fix

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

        object(req, res, next) {
          const { object, id: objectId } = req.params;
          const body = _.omit(req.body, _.isEmpty);
          let modelData;
    
    
    Severity: Major
    Found in lib/update.js - About 2 hrs to fix

      Function form has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          form(req, res) {
            const { object, id: objectId } = req.params;
            const Model = AdminUtils.getModel(object);
            const { query } = AdminUtils.parseQuery(Model, req.query);
            let populate;
      Severity: Minor
      Found in lib/update.js - About 1 hr to fix

        Assignment to property of function parameter 'model'.
        Open

                    model.parentId = null;
        Severity: Minor
        Found in lib/update.js by eslint

        Disallow Reassignment of Function Parameters (no-param-reassign)

        Assignment to variables declared as function parameters can be misleading and lead to confusing behavior, as modifying function parameters will also mutate the arguments object. Often, assignment to function parameters is unintended and indicative of a mistake or programmer error.

        This rule can be also configured to fail when function parameters are modified. Side effects on parameters can cause counter-intuitive execution flow and make errors difficult to track down.

        Rule Details

        This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.

        Examples of incorrect code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            bar = 13;
        }
        
        function foo(bar) {
            bar++;
        }

        Examples of correct code for this rule:

        /*eslint no-param-reassign: "error"*/
        
        function foo(bar) {
            var baz = bar;
        }

        Options

        This rule takes one option, an object, with a boolean property "props" and an array "ignorePropertyModificationsFor". "props" is false by default. If "props" is set to true, this rule warns against the modification of parameter properties unless they're included in "ignorePropertyModificationsFor", which is an empty array by default.

        props

        Examples of correct code for the default { "props": false } option:

        /*eslint no-param-reassign: ["error", { "props": false }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        Examples of incorrect code for the { "props": true } option:

        /*eslint no-param-reassign: ["error", { "props": true }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        Examples of correct code for the { "props": true } option with "ignorePropertyModificationsFor" set:

        /*eslint no-param-reassign: ["error", { "props": true, "ignorePropertyModificationsFor": ["bar"] }]*/
        
        function foo(bar) {
            bar.prop = "value";
        }
        
        function foo(bar) {
            delete bar.aaa;
        }
        
        function foo(bar) {
            bar.aaa++;
        }

        When Not To Use It

        If you want to allow assignment to function parameters, then you can safely disable this rule.

        Further Reading

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

                  if (req.query.redirect) {
                    redirect = req.query.redirect;
                  } else if (req.body.redirect) {
                    redirect = req.body.redirect;
                  }
        Severity: Major
        Found in lib/update.js and 1 other location - About 1 hr to fix
        lib/create.js on lines 39..43

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

        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