PlanHubMe/PlanHub

View on GitHub

Showing 857 of 857 total issues

Function createSubjectRow has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

window.planner.createSubjectRow = function(subjectName, subjectIndex) {
    var $row = $('<tr class="subjectRow"></tr>');
        $row.attr("data-subjectName", subjectName);
        $row.attr("data-subjectIndex", subjectIndex);

Severity: Minor
Found in public/js/planner.js - About 3 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

                var evObj = {
                    name: ev[evIndex].text,
                    due: new Date(ev[evIndex].date.split("T")[0]),
                    rawDue: ev[evIndex].date,
                    subject: ev[evIndex].sectionIndex,
Severity: Major
Found in public/js/hwView.js and 1 other location - About 3 hrs to fix
public/js/hwView.js on lines 226..233

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

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

                var evObj = {
                    name: overdue[overdueIndex].text,
                    due: new Date(overdue[overdueIndex].date.split("T")[0]),
                    rawDue: overdue[overdueIndex].date,
                    subject: overdue[overdueIndex].sectionIndex,
Severity: Major
Found in public/js/hwView.js and 1 other location - About 3 hrs to fix
public/js/hwView.js on lines 204..211

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

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 has a complexity of 25.
Open

window.hwView.addEventToList = function(ev, list) {
Severity: Minor
Found in public/js/hwView.js by eslint

Limit Cyclomatic Complexity (complexity)

Cyclomatic complexity measures the number of linearly independent paths through a program's source code. This rule allows setting a cyclomatic complexity threshold.

function a(x) {
    if (true) {
        return x; // 1st path
    } else if (false) {
        return x+1; // 2nd path
    } else {
        return 4; // 3rd path
    }
}

Rule Details

This rule is aimed at reducing code complexity by capping the amount of cyclomatic complexity allowed in a program. As such, it will warn when the cyclomatic complexity crosses the configured threshold (default is 20).

Examples of incorrect code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else if (false) {
        return x+1;
    } else {
        return 4; // 3rd path
    }
}

Examples of correct code for a maximum of 2:

/*eslint complexity: ["error", 2]*/

function a(x) {
    if (true) {
        return x;
    } else {
        return 4;
    }
}

Options

Optionally, you may specify a max object property:

"complexity": ["error", 2]

is equivalent to

"complexity": ["error", { "max": 2 }]

Deprecated: the object property maximum is deprecated. Please use the property max instead.

When Not To Use It

If you can't determine an appropriate complexity limit for your code, then it's best to disable this rule.

Further Reading

Related Rules

  • [max-depth](max-depth.md)
  • [max-len](max-len.md)
  • [max-nested-callbacks](max-nested-callbacks.md)
  • [max-params](max-params.md)
  • [max-statements](max-statements.md) Source: http://eslint.org/docs/rules/

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

window.planner.showSaved = function() {
    window.planner.saving = false;
    $("#planner-status").html('<i class="fa fa-check"></i>');
    $("#planner-status").attr("title", "All data saved!");
    $("#planner-status").attr("data-original-title", "All data saved!");
Severity: Major
Found in public/js/planner.js and 1 other location - About 3 hrs to fix
public/js/planner.js on lines 11..17

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

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

window.planner.showSaving = function() {
    window.planner.saving = true;
    $("#planner-status").html('<i class="fa fa-refresh fa-spin"></i>');
    $("#planner-status").attr("title", "Saving...");
    $("#planner-status").attr("data-original-title", "Saving...");
Severity: Major
Found in public/js/planner.js and 1 other location - About 3 hrs to fix
public/js/planner.js on lines 19..25

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

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

                    $deleteThem.click(function() {
                        $(this).parent().remove();
                        var setList = JSON.stringify($("#title-sorting").sortable("toArray"));
                        window.api.post("prefs/set", {name: "titleOrder", value:setList}, function() {});
                    });
Severity: Major
Found in public/js/prefs.js and 1 other location - About 3 hrs to fix
public/js/prefs.js on lines 105..109

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

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

                $deleteButton.click(function() {
                    $(this).parent().remove();
                    var setList = JSON.stringify($("#title-sorting").sortable("toArray"));
                    window.api.post("prefs/set", {name: "titleOrder", value:setList}, function() {});
                });
Severity: Major
Found in public/js/prefs.js and 1 other location - About 3 hrs to fix
public/js/prefs.js on lines 129..133

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

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

window.hwView.addEventToList = function(ev, list) {
    var tag = window.utils.getPrefix(ev.name);
    var name = ev.name.split(" ");
    name.splice(0, 1);
    name = name.join(" ");
Severity: Minor
Found in public/js/hwView.js - About 3 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

router.get('/announcements/get/', global.apiCall, function(req, res, next) {
    knex("announcements").select("*").then(function(obj) {
        res.json({
            status: "ok",
            feedback: obj
Severity: Major
Found in routes/api_overview.js and 1 other location - About 3 hrs to fix
routes/api_admin.js on lines 11..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 95.

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

router.get('/users/get', global.apiCall, global.requireUser, global.getUserRecord, global.requireNonZeroLevel, function(req, res, next) {
    knex("users").select("*").then(function(obj) {
        res.json({
            status: "ok",
            users: obj
Severity: Major
Found in routes/api_admin.js and 1 other location - About 3 hrs to fix
routes/api_overview.js on lines 11..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 95.

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 (code.length < 6) {
            $("#sms-verify-error").text("That code is shorter than it should be! Make sure that you copied the whole code!");
            $("#sms-verify-error").animate({ color: "red" }, 100, "swing", function() {
                $("#sms-verify-error").animate({ color: "black" }, 100, "swing", function() {

Severity: Major
Found in public/js/prefs.js and 1 other location - About 2 hrs to fix
public/js/prefs.js on lines 191..199

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

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 (code.length > 6) {
            $("#sms-verify-error").text("That code is longer than it should be! Make sure that you copied the whole code!");
            $("#sms-verify-error").animate({ color: "red" }, 100, "swing", function() {
                $("#sms-verify-error").animate({ color: "black" }, 100, "swing", function() {

Severity: Major
Found in public/js/prefs.js and 1 other location - About 2 hrs to fix
public/js/prefs.js on lines 182..190

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

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

window.utils.getPrefixes = function() {
    return [
        {
            color: "cal_hw",
            words: ["HW", "Read", "Reading"],
Severity: Major
Found in public/js/utils.js - About 2 hrs to fix

    Function graph has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    window.graph.graph = function(){
        //get data
        var days = [];
        var hwResult;
    
    
    Severity: Major
    Found in public/js/graphs.js - About 2 hrs to fix

      File app.js has 262 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      /*
          MyHomeworkSpace
          https://myhomework.space/
          https://github.com/MyHomeworkSpace/MyHomeworkSpace
          Licensed under the MIT License.
      Severity: Minor
      Found in app.js - About 2 hrs to fix

        Function loadWeek has 49 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        window.planner.loadWeek = function(startDate) {
            window.planner.loadState = 0;
            window.page.showLoading();
        
            var startDate_obj = new Date(startDate);
        Severity: Minor
        Found in public/js/planner.js - About 1 hr to fix

          Function loadWholeWeek has 48 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          window.planner.loadWholeWeek = function(startDate, subjectIndex) {
              window.api.get("planner/events/getWholeWeek/" + window.utils.formatDate_api(startDate), function(data) {
                  for (var announcementIndex in data.announcements) {
                      var announcement = data.announcements[announcementIndex];
                      var date = announcement.date.split("T")[0];
          Severity: Minor
          Found in public/js/planner.js - About 1 hr to fix

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

            utils.findNextMonday = function() {
                var today = new Date();
                while (today.getDay() != 1) { // loop until a monday is found
                    today.setDate(today.getDate() + 1);
                }
            Severity: Major
            Found in utils.js and 1 other location - About 1 hr to fix
            utils.js on lines 3..9

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

            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

            utils.findThisMonday = function() {
                var today = new Date();
                while (today.getDay() != 1) { // loop until a monday is found
                    today.setDate(today.getDate() - 1);
                }
            Severity: Major
            Found in utils.js and 1 other location - About 1 hr to fix
            utils.js on lines 11..17

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

            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