qcminecraft/Carbon-Forum-F

View on GitHub
static/js/default/new.function.js

Summary

Maintainability
F
6 days
Test Coverage

Function InitNewTopicEditor has 106 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function InitNewTopicEditor() {
    UE.delEditor('editor');
    //Initialize editor
    //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
    window.UEDITOR_CONFIG['textarea'] = 'Content';
Severity: Major
Found in static/js/default/new.function.js - About 4 hrs to fix

    File new.function.js has 295 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /*
     * Carbon-Forum-F
     * https://github.com/lincanbin/Carbon-Forum
     *
     * Copyright 2006-2017 Canbin Lin (lincanbin@hotmail.com)
    Severity: Minor
    Found in static/js/default/new.function.js - About 3 hrs to fix

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

      function GetTags() {
          var CurrentContentHash = md5(document.NewForm.Title.value + UE.getEditor('editor').getContentTxt());
          //取Title与Content 联合Hash值,与之前input的内容比较,不同则开始获取话题,随后保存进hidden input。
          if (CurrentContentHash !== document.NewForm.ContentHash.value) {
              if (document.NewForm.Title.value.length || UE.getEditor('editor').getContentTxt().length) {
      Severity: Minor
      Found in static/js/default/new.function.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 CreateNewTopic has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function CreateNewTopic() {
          if (!document.NewForm.Title.value.length) {
              alert(Lang['Title_Can_Not_Be_Empty']);
              document.NewForm.Title.focus();
              return false;
      Severity: Major
      Found in static/js/default/new.function.js - About 2 hrs to fix

        Function CreateNewTopic has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        function CreateNewTopic() {
            if (!document.NewForm.Title.value.length) {
                alert(Lang['Title_Can_Not_Be_Empty']);
                document.NewForm.Title.focus();
                return false;
        Severity: Minor
        Found in static/js/default/new.function.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 InitNewTopicEditor has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

        function InitNewTopicEditor() {
            UE.delEditor('editor');
            //Initialize editor
            //建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
            window.UEDITOR_CONFIG['textarea'] = 'Content';
        Severity: Minor
        Found in static/js/default/new.function.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 onready has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                onready: function () {
                    //从草稿中恢复
                    if (window.localStorage) {
                        if (typeof SaveDraftTimer !== "undefined") {
                            clearInterval(SaveDraftTimer);
        Severity: Minor
        Found in static/js/default/new.function.js - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                      if (CheckTag(data.lists[i], 0)) {
                                          TagsListAppend(data.lists[i], i);
                                      }
          Severity: Major
          Found in static/js/default/new.function.js - About 45 mins to fix

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

            function CtrlAndEnter(Event, IsPreventDefault) {
                //console.log("keydown");
                if (Event.keyCode === 13) {
                    if (IsPreventDefault) {
                        //屏蔽Tag输入框的回车提交,阻止回车的默认操作
            Severity: Minor
            Found in static/js/default/new.function.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

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

            function SaveTopicDraft() {
                try {
                    var TagsList = JSON.stringify($("input[name='Tag[]']").map(function () {
                        return $(this).val();
                    }).get());
            Severity: Minor
            Found in static/js/default/new.function.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

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

            function RecoverTopicContents() {
                var DraftTitle = localStorage.getItem(Prefix + "TopicTitle");
                var DraftContent = localStorage.getItem(Prefix + "TopicContent");
                var DraftTagsList = JSON.parse(localStorage.getItem(Prefix + "TopicTagsList"));
                if (DraftTitle) {
            Severity: Minor
            Found in static/js/default/new.function.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

            function CheckTag(TagName, IsAdd) {
                TagName = $.trim(TagName);
                var show = true;
                var i = 1;
                $("input[name='Tag[]']").each(function (index) {
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 7 hrs to fix
            static/js/mobile/topic.function.js on lines 82..102

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

            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

            function AddTag(TagName, id) {
                if (CheckTag(TagName, 1)) {
                    $("#SelectTags").append('<a href="###" onclick="javascript:TagRemove(\'' + TagName + '\',' + id + ');" id="Tag' + id + '">' + TagName + '&nbsp;×<input type="hidden" name="Tag[]" value="' + TagName + '" /></a>');
                    $("#TagsList" + id).remove();
                }
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 7 hrs to fix
            static/js/mobile/topic.function.js on lines 138..149

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

            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

                } else if (AllowEmptyTags === false && !$("#SelectTags").html()) {
                    if ($("#AlternativeTag").val().length !== 0) {
                        AddTag($("#AlternativeTag").val(), Math.round(new Date().getTime() / 1000));
                    } else {
                        alert(Lang['Tags_Empty']);
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 3 hrs to fix
            static/js/mobile/topic.function.js on lines 30..78

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

            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

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

            function TagRemove(TagName, id) {
                $("#Tag" + id).remove();
                TagsListAppend(TagName, id);
                if ($("input[name='Tag[]']").length < MaxTagNum) {
                    $("#AlternativeTag").attr("disabled", false);
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 3 hrs to fix
            static/js/mobile/topic.function.js on lines 166..174

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

            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

                } else if (document.NewForm.Title.value.replace(/[^\x00-\xff]/g, "***").length > MaxTitleChars) {
                    alert(Lang['Title_Too_Long'].replace("{{MaxTitleChars}}", MaxTitleChars).replace("{{Current_Title_Length}}", document.NewForm.Title.value.replace(/[^\x00-\xff]/g, "***").length));
                    document.NewForm.Title.focus();
                    return false;
                } else if (AllowEmptyTags === false && !$("#SelectTags").html()) {
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 2 hrs to fix
            static/js/mobile/topic.function.js on lines 26..78

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

            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

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

                window.UEDITOR_CONFIG['toolbars'] = [
                    [
                        'fullscreen',
                        'source',
                        '|',
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 2 hrs to fix
            static/js/default/topic.function.js on lines 99..149

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

            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

                        case 13:
                            if ($("#AlternativeTag").val().length !== 0) {
                                AddTag($("#AlternativeTag").val(), Math.round(new Date().getTime() / 1000));
                            }
                            break;
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 1 hr to fix
            static/js/mobile/topic.function.js on lines 155..159

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

            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

            function TagsListAppend(TagName, id) {
                $("#TagsList").append('<a href="###" onclick="javascript:AddTag(\'' + TagName + '\',' + id + ');GetTags();" id="TagsList' + id + '">' + TagName + '&nbsp;+</a>');
                //document.NewForm.AlternativeTag.focus();
            }
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 1 hr to fix
            static/js/mobile/topic.function.js on lines 133..136

            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

                        error: function () {
                            alert(Lang['Submit_Failure']);
                            UE.getEditor('editor').setEnabled();
                            $("#PublishButton").val(Lang['Submit_Again']);
                        }
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 1 hr to fix
            static/js/default/topic.function.js on lines 403..407

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

            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

                try {
                    var TagsList = JSON.stringify($("input[name='Tag[]']").map(function () {
                        return $(this).val();
                    }).get());
                    if (document.NewForm.Title.value.length >= 4) {
            Severity: Major
            Found in static/js/default/new.function.js and 1 other location - About 1 hr to fix
            static/js/default/topic.function.js on lines 428..438

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

            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

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

                if (DraftContent) {
                    UE.getEditor('editor').setContent(DraftContent);
                } else {
                    UE.getEditor('editor').execCommand('cleardoc');
                }
            Severity: Minor
            Found in static/js/default/new.function.js and 1 other location - About 40 mins to fix
            static/js/default/topic.function.js on lines 449..453

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

            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