Function cron
has 180 lines of code (exceeds 25 allowed). Consider refactoring. Open
export async function cron (options = {}) {
const {
user, tasksByType, analytics, now = new Date(), daysMissed, timezoneUtcOffsetFromUserPrefs,
} = options;
let _progress = { down: 0, up: 0, collectedItems: 0 };
File cron.js
has 367 lines of code (exceeds 250 allowed). Consider refactoring. Open
import moment from 'moment';
import _ from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import nconf from 'nconf';
import { model as User } from '../models/user';
Function cron
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
export async function cron (options = {}) {
const {
user, tasksByType, analytics, now = new Date(), daysMissed, timezoneUtcOffsetFromUserPrefs,
} = options;
let _progress = { down: 0, up: 0, collectedItems: 0 };
- Read upRead up
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 awardLoginIncentives
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
function awardLoginIncentives (user) {
if (user.loginIncentives > MAX_INCENTIVES) return;
// Remove old notifications if they exists
user.notifications.forEach((notif, index) => {
- Read upRead up
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 grantEndOfTheMonthPerks
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
async function grantEndOfTheMonthPerks (user, now) {
const { plan, elapsedMonths } = getPlanContext(user, now);
if (elapsedMonths > 0) {
plan.dateUpdated = now;
- Read upRead up
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 awardLoginIncentives
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
function awardLoginIncentives (user) {
if (user.loginIncentives > MAX_INCENTIVES) return;
// Remove old notifications if they exists
user.notifications.forEach((notif, index) => {
Function resetHabitCounters
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function resetHabitCounters (user, tasksByType, now, daysMissed) {
// check if we've passed a day on which we should reset the habit counters, including today
let resetWeekly = false;
let resetMonthly = false;
for (let i = 0; i < daysMissed; i += 1) {
Function resetHabitCounters
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function resetHabitCounters (user, tasksByType, now, daysMissed) {
// check if we've passed a day on which we should reset the habit counters, including today
let resetWeekly = false;
let resetMonthly = false;
for (let i = 0; i < daysMissed; i += 1) {
- Read upRead up
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
Avoid deeply nested control flow statements. Open
if (!CRON_SEMI_SAFE_MODE) {
// Apply damage from a boss, less damage for Trivial priority (difficulty)
user.party.quest.progress.down += delta * (task.priority < 1 ? task.priority : 1);
// NB: Medium and Hard priorities do not increase damage from boss.
// This was by accident
Consider simplifying this complex logical expression. Open
if (
user.party && user.party.quest && !user.party.quest.RSVPNeeded
&& !user.party.quest.completed && user.party.quest.key && !user.preferences.sleep
) {
analytics.track('quest participation', {
Function recoverCron
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
export async function recoverCron (status, locals) {
const { user } = locals;
await sleep(0.3);
- Read upRead up
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"