NodeBB/NodeBB

View on GitHub

Showing 490 of 506 total issues

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

    Posts.generatePostPath = async function (pid, uid) {
        const paths = await Posts.generatePostPaths([pid], uid);
        return Array.isArray(paths) && paths.length ? paths[0] : null;
    };
Severity: Minor
Found in src/posts/topics.js and 2 other locations - About 35 mins to fix
src/topics/index.js on lines 236..239
src/topics/teaser.js on lines 160..163

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

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 3 locations. Consider refactoring.
Open

Topics.getMainPost = async function (tid, uid) {
    const mainPosts = await Topics.getMainPosts([tid], uid);
    return Array.isArray(mainPosts) && mainPosts.length ? mainPosts[0] : null;
};
Severity: Minor
Found in src/topics/index.js and 2 other locations - About 35 mins to fix
src/posts/topics.js on lines 29..32
src/topics/teaser.js on lines 160..163

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

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 fireResponseHook has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

async function fireResponseHook(hook, hookList, params) {
    if (!Array.isArray(hookList) || !hookList.length) {
        return;
    }
    for (const hookObj of hookList) {
Severity: Minor
Found in src/plugins/hooks.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 exports has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (Topics) {
    Topics.getTopicsFields = async function (tids, fields) {
        if (!Array.isArray(tids) || !tids.length) {
            return [];
        }
Severity: Minor
Found in src/topics/data.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 exports has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (Topics) {
    Topics.merge = async function (tids, uid, options) {
        options = options || {};

        const topicsData = await Topics.getTopicsFields(tids, ['scheduled']);
Severity: Minor
Found in src/topics/merge.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 get has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

function get() {
    if (real) {
        return real;
    }

Severity: Minor
Found in src/pubsub.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 register has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

authenticationController.register = async function (req, res) {
    const registrationType = meta.config.registrationType || 'normal';

    if (registrationType === 'disabled') {
        return res.sendStatus(403);
Severity: Minor
Found in src/controllers/authentication.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 leave has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

groupsAPI.leave = async function (caller, data) {
    if (!data) {
        throw new Error('[[error:invalid-data]]');
    }
    if (caller.uid <= 0) {
Severity: Minor
Found in src/api/groups.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 invite has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

Users.invite = async (req, res) => {
    const { emails, groupsToJoin = [] } = req.body;

    if (!emails || !Array.isArray(groupsToJoin)) {
        return helpers.formatApiResponse(400, res, new Error('[[error:invalid-data]]'));
Severity: Minor
Found in src/controllers/write/users.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 loadConfig has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

apiController.loadConfig = async function (req) {
    const config = {
        relative_path,
        upload_url,
        assetBaseUrl: `${relative_path}/assets`,
Severity: Minor
Found in src/controllers/api.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 handle404 has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

exports.handle404 = function handle404(req, res) {
    const relativePath = nconf.get('relative_path');
    const isClientScript = new RegExp(`^${relativePath}\\/assets\\/src\\/.+\\.js(\\?v=\\w+)?$`);

    if (plugins.hooks.hasListeners('action:meta.override404')) {
Severity: Minor
Found in src/controllers/404.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 setPrivilege has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

categoriesAPI.setPrivilege = async (caller, data) => {
    const [userExists, groupExists] = await Promise.all([
        user.exists(data.member),
        groups.exists(data.member),
    ]);
Severity: Minor
Found in src/api/categories.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 sendToEmail has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

Emailer.sendToEmail = async (template, email, language, params) => {
    const lang = language || meta.config.defaultLang || 'en-GB';
    const unsubscribable = ['digest', 'notification'];

    // Digests and notifications can be one-click unsubbed
Severity: Minor
Found in src/emailer.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 set has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

Settings.prototype.set = function (key, val) {
    let part;
    let obj;
    let parts;
    this.cfg.v = this.version;
Severity: Minor
Found in src/settings.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 expandObjBy has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

function expandObjBy(obj1, obj2) {
    let changed = false;
    if (!obj1 || !obj2) {
        return changed;
    }
Severity: Minor
Found in src/settings.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 process has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

Upgrade.process = async function (files, skipCount) {
    console.log('OK'.green + ' | '.reset + String(files.length).cyan + ' script(s) found'.cyan + (skipCount > 0 ? ', '.cyan + String(skipCount).cyan + ' skipped'.cyan : ''));
    const [schemaDate, schemaLogCount] = await Promise.all([
        db.get('schemaDate'),
        db.sortedSetCard('schemaLog'),
Severity: Minor
Found in src/upgrade.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 exports has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (Posts) {
    Posts.tools = {};

    Posts.tools.delete = async function (uid, pid) {
        return await togglePostDelete(uid, pid, true);
Severity: Minor
Found in src/posts/tools.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 resizeImage has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

image.resizeImage = async function (data) {
    if (plugins.hooks.hasListeners('filter:image.resize')) {
        await plugins.hooks.fire('filter:image.resize', {
            path: data.path,
            target: data.target,
Severity: Minor
Found in src/image.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 createAdmin has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

async function createAdmin() {
    const User = require('./user');
    const Groups = require('./groups');
    let password;

Severity: Minor
Found in src/install.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 exports has a Cognitive Complexity of 12 (exceeds 10 allowed). Consider refactoring.
Open

module.exports = function (theModule, ignoreKeys) {
    ignoreKeys = ignoreKeys || [];
    function isCallbackedFunction(func) {
        if (typeof func !== 'function') {
            return false;
Severity: Minor
Found in src/promisify.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

Severity
Category
Status
Source
Language