NodeBB/NodeBB

View on GitHub
src/flags.js

Summary

Maintainability
D
2 days
Test Coverage

File flags.js has 871 lines of code (exceeds 500 allowed). Consider refactoring.
Open

'use strict';

const _ = require('lodash');
const winston = require('winston');
const validator = require('validator');
Severity: Major
Found in src/flags.js - About 1 day to fix

    Function update has a Cognitive Complexity of 30 (exceeds 10 allowed). Consider refactoring.
    Open

    Flags.update = async function (flagId, uid, changeset) {
        const current = await db.getObjectFields(`flag:${flagId}`, ['uid', 'state', 'assignee', 'type', 'targetId']);
        if (!current.type) {
            return;
        }
    Severity: Minor
    Found in src/flags.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

    Function validate has a Cognitive Complexity of 15 (exceeds 10 allowed). Consider refactoring.
    Open

    Flags.validate = async function (payload) {
        const [target, reporter] = await Promise.all([
            Flags.getTarget(payload.type, payload.id, payload.uid),
            user.getUserData(payload.uid),
        ]);
    Severity: Minor
    Found in src/flags.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 getFlagIdsWithFilters has a Cognitive Complexity of 14 (exceeds 10 allowed). Consider refactoring.
    Open

    Flags.getFlagIdsWithFilters = async function ({ filters, uid, query }) {
        let sets = [];
        const orSets = [];
    
        // Default filter
    Severity: Minor
    Found in src/flags.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

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

    Flags.addReport = async function (flagId, type, id, uid, reason, timestamp) {
    Severity: Minor
    Found in src/flags.js - About 45 mins to fix

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

      Flags.create = async function (type, id, uid, reason, timestamp, forceFlag = false) {
      Severity: Minor
      Found in src/flags.js - About 45 mins to fix

        Function create has a Cognitive Complexity of 11 (exceeds 10 allowed). Consider refactoring.
        Open

        Flags.create = async function (type, id, uid, reason, timestamp, forceFlag = false) {
            let doHistoryAppend = false;
            if (!timestamp) {
                timestamp = Date.now();
                doHistoryAppend = true;
        Severity: Minor
        Found in src/flags.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

        There are no issues that match your filters.

        Category
        Status