NodeBB/NodeBB

View on GitHub
src/messaging/rooms.js

Summary

Maintainability
F
3 days
Test Coverage

Function exports has 459 lines of code (exceeds 75 allowed). Consider refactoring.
Open

module.exports = function (Messaging) {
    Messaging.getRoomData = async (roomId, fields = []) => {
        const roomData = await Messaging.getRoomsData([roomId], fields);
        return roomData[0];
    };
Severity: Major
Found in src/messaging/rooms.js - About 2 days to fix

    Function exports has a Cognitive Complexity of 84 (exceeds 10 allowed). Consider refactoring.
    Open

    module.exports = function (Messaging) {
        Messaging.getRoomData = async (roomId, fields = []) => {
            const roomData = await Messaging.getRoomsData([roomId], fields);
            return roomData[0];
        };
    Severity: Minor
    Found in src/messaging/rooms.js - About 1 day 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 loadRoom has 92 lines of code (exceeds 75 allowed). Consider refactoring.
    Open

        Messaging.loadRoom = async (uid, data) => {
            const { roomId } = data;
            const [room, inRoom, canChat, isAdmin, isGlobalMod] = await Promise.all([
                Messaging.getRoomData(roomId),
                Messaging.isUserInRoom(uid, roomId),
    Severity: Major
    Found in src/messaging/rooms.js - About 1 hr to fix

      Consider simplifying this complex logical expression.
      Open

              if (!room ||
                  (!room.public && !inRoom) ||
                  (room.public && (
                      Array.isArray(room.groups) && room.groups.length && !isAdmin && !(await groups.isMemberOfAny(uid, room.groups)))
                  )
      Severity: Critical
      Found in src/messaging/rooms.js - About 1 hr to fix

        There are no issues that match your filters.

        Category
        Status