JacobGrisham/YelpCamp

View on GitHub

Showing 16 of 16 total issues

Function addSorting has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

var addSorting = (function() {
    'use strict';
    var cols,
        currentSort = {
            index: 0,
Severity: Minor
Found in coverage/lcov-report/sorter.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

Function addSorting has 138 lines of code (exceeds 25 allowed). Consider refactoring.
Open

var addSorting = (function() {
    'use strict';
    var cols,
        currentSort = {
            index: 0,
Severity: Major
Found in coverage/lcov-report/sorter.js - About 5 hrs to fix

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

                if(err){
                    res.redirect("back");
                } else {
                    // Verify that user owns the comment or is an Admin
                    if(foundComment.author.id.equals(req.user._id) || req.user.isAdmin){
    Severity: Major
    Found in middleware/index.js and 1 other location - About 2 hrs to fix
    middleware/index.js on lines 27..38

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

    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(err){
                    req.flash("error", "Sorry, campground not found");
                    res.redirect("back");
                } else {
                    // Verify that user owns the campground or is an Admin
    Severity: Major
    Found in middleware/index.js and 1 other location - About 2 hrs to fix
    middleware/index.js on lines 52..62

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

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

    var jumpToCode = (function init() {
        // Classes of code we would like to highlight in the file view
        var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
    
        // Elements to highlight in the file listing view
    Severity: Major
    Found in coverage/lcov-report/block-navigation.js - About 2 hrs to fix

      Function checkCampgroundOwnership has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      middlewareObj.checkCampgroundOwnership = function(req, res, next){
          // First Is any user logged in
          if(req.isAuthenticated()){
              // Find the Campground by Id
              Campground.findById(req.params.id, function(err, foundCampground){
      Severity: Minor
      Found in middleware/index.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 checkCommentOwnership has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      middlewareObj.checkCommentOwnership = function(req, res, next){
          // First Is any user logged in
          if(req.isAuthenticated()){
              // Find the Campground by Id
              Comment.findById(req.params.comment_id, function(err, foundComment){
      Severity: Minor
      Found in middleware/index.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 checkReviewOwnership has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

      middlewareObj.checkReviewOwnership = function(req, res, next) {
          if(req.isAuthenticated()){
              Review.findById(req.params.review_id, function(err, foundReview){
                  if(err || !foundReview){
                      res.redirect("back");
      Severity: Minor
      Found in middleware/index.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 2 locations. Consider refactoring.
      Open

                          res.render("comments/edit", {
                              campground: foundCampground,
                              title: `Edit Comment for ${foundCampground.name}`,
                              comment: foundComment,
                              description: `Edit your comment for ${foundCampground.name}. Perhaps there was a misspelling or another reason.`,
      Severity: Major
      Found in routes/comments.js and 1 other location - About 1 hr to fix
      routes/index.js on lines 88..93

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

      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

              res.render("users/show", {
                  user: foundUser, 
                  title: `${foundUser.username}'s Campgrounds`,
                  campgrounds: campgrounds,
                  description: `Welcome ${foundUser.username}, to your account profile page where you can easily access all the campgrounds you've added.`,
      Severity: Major
      Found in routes/index.js and 1 other location - About 1 hr to fix
      routes/comments.js on lines 65..70

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

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

      middlewareObj.checkReviewExistence = function (req, res, next) {
          if (req.isAuthenticated()) {
              Campground.findById(req.params.id).populate("reviews").exec(function (err, foundCampground) {
                  if (err || !foundCampground) {
                      req.flash("error", "Campground not found.");
      Severity: Minor
      Found in middleware/index.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 enableUI has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          function enableUI() {
              var i,
                  el,
                  ithSorter = function ithSorter(i) {
                      var col = cols[i];
      Severity: Minor
      Found in coverage/lcov-report/sorter.js - About 1 hr to fix

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

                res.render("reviews/index", {
                    campground: campground,
                    title: `Reviews for ${campground.name}`,
                    description: `See the complete list of reviews for ${campground.name}.`,
                });
        Severity: Major
        Found in routes/reviews.js and 2 other locations - About 55 mins to fix
        routes/comments.js on lines 15..19
        routes/reviews.js on lines 33..37

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

                res.render("reviews/new", {
                    campground: campground,
                    title: `Add a Review for ${campground.name}`,
                    description: `Let others know if you enjoyed your experience at ${campground.name}. Love it? Hate it? Leave a review.`,
                });
        Severity: Major
        Found in routes/reviews.js and 2 other locations - About 55 mins to fix
        routes/comments.js on lines 15..19
        routes/reviews.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 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 3 locations. Consider refactoring.
        Open

                    res.render("comments/new", {
                        campground: campground,
                        title: `Add Comment to ${campground.name}`,
                        description: `Engage the community by adding a comment to ${campground.name}`,
                    });
        Severity: Major
        Found in routes/comments.js and 2 other locations - About 55 mins to fix
        routes/reviews.js on lines 17..21
        routes/reviews.js on lines 33..37

        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

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

        var jumpToCode = (function init() {
            // Classes of code we would like to highlight in the file view
            var missingCoverageClasses = ['.cbranch-no', '.cstat-no', '.fstat-no'];
        
            // Elements to highlight in the file listing view
        Severity: Minor
        Found in coverage/lcov-report/block-navigation.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

        Severity
        Category
        Status
        Source
        Language