NodeBB/NodeBB

View on GitHub
src/topics/posts.js

Summary

Maintainability
B
4 hrs
Test Coverage

Function exports has a Cognitive Complexity of 110 (exceeds 10 allowed). Consider refactoring.
Invalid

module.exports = function (Topics) {
    Topics.onNewPostMade = async function (postData) {
        await Topics.updateLastPostTime(postData.tid, postData.timestamp);
        await Topics.addPostToTopic(postData.tid, postData);
    };
Severity: Minor
Found in src/topics/posts.js - About 2 days 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 exports has 360 lines of code (exceeds 75 allowed). Consider refactoring.
Invalid

module.exports = function (Topics) {
    Topics.onNewPostMade = async function (postData) {
        await Topics.updateLastPostTime(postData.tid, postData.timestamp);
        await Topics.addPostToTopic(postData.tid, postData);
    };
Severity: Major
Found in src/topics/posts.js - About 1 day to fix

    Consider simplifying this complex logical expression.
    Open

                if (post) {
                    post.topicOwnerPost = parseInt(topicData.uid, 10) === parseInt(post.uid, 10);
                    post.display_edit_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:edit']);
                    post.display_delete_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:delete']);
                    post.display_moderator_tools = post.display_edit_tools || post.display_delete_tools;
    Severity: Critical
    Found in src/topics/posts.js - About 4 hrs to fix

      Function getTopicPosts has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          Topics.getTopicPosts = async function (topicData, set, start, stop, uid, reverse) {
      Severity: Minor
      Found in src/topics/posts.js - About 45 mins to fix

        There are no issues that match your filters.

        Category
        Status