HabitRPG/habitrpg

View on GitHub

Showing 688 of 3,401 total issues

Avoid too many return statements within this function.
Open

  return false;
Severity: Major
Found in website/common/script/libs/getItemInfo.js - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

                return next({
                  name: 'groupPlanBilling',
                  params: { groupId },
                });
    Severity: Major
    Found in website/client/src/router/handleRedirect.js - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

          return schedule.matches(startOfDayWithCDSTime) && matchEveryX;
      Severity: Major
      Found in website/common/script/cron.js - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return filteredDates;
        Severity: Major
        Found in website/common/script/cron.js - About 30 mins to fix

          Avoid too many return statements within this function.
          Open

              return res.body.data;
          Severity: Major
          Found in test/helpers/api-integration/requester.js - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

              return null;
            Severity: Major
            Found in test/helpers/api-integration/requester.js - About 30 mins to fix

              Function userToJSON has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                toJSONTransform: function userToJSON (plainObj, originalDoc) {
                  plainObj._tmp = originalDoc._tmp; // be sure to send down drop notifs
              
                  if (plainObj._tmp && plainObj._tmp.leveledUp) {
                    delete plainObj._tmp.leveledUp;
              Severity: Minor
              Found in website/server/models/user/hooks.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

              Function setNextDue has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export function setNextDue (task, user, dueDateOption) {
                if (task.type !== 'daily') return;
              
                let now = moment().toDate();
                let dateTaskIsDue = Date.now();
              Severity: Minor
              Found in website/server/libs/tasks/utils.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

              Function flagGroupMessage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                async flagGroupMessage (group, message, increaseFlagCount) {
                  // Log user ids that have flagged the message
                  if (!message.flags) message.flags = {};
                  // TODO fix error type
                  if (message.flags[this.user._id] && !this.user.hasPermission('moderator')) throw new NotFound(this.res.t('messageGroupChatFlagAlreadyReported'));
              Severity: Minor
              Found in website/server/libs/chatReporting/groupChatReporter.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

              Function finishQuest has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              schema.methods.finishQuest = async function finishQuest (quest) {
                const questK = quest.key;
                const updates = {
                  $inc: {
                    [`achievements.quests.${questK}`]: 1,
              Severity: Minor
              Found in website/server/models/group.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

              Function _sendDataToGoogle has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function _sendDataToGoogle (eventType, data) {
                const eventData = {
                  ec: data.gaCategory || data.category || 'behavior',
                  ea: eventType,
                };
              Severity: Minor
              Found in website/server/libs/analyticsService.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

              Function send has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                send (user, data) {
                  const { webhooks } = user;
              
                  const hooks = webhooks.filter(hook => {
                    if (!isValidWebhook(hook)) return false;
              Severity: Minor
              Found in website/server/libs/webhook.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

              Function challengeUnlinkTasks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              schema.methods.unlinkTasks = async function challengeUnlinkTasks (user, keep, saveUser = true) {
                const challengeId = this._id;
                const findQuery = {
                  userId: user._id,
                  'challenge.id': challengeId,
              Severity: Minor
              Found in website/server/models/challenge.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

              Function _populateDefaultTasks has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              function _populateDefaultTasks (user, taskTypes) {
                let defaultsData;
                if (user.registeredThrough === 'habitica-android' || user.registeredThrough === 'habitica-ios') {
                  defaultsData = common.content.userDefaultsMobile;
                } else {
              Severity: Minor
              Found in website/server/models/user/hooks.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

              Function getGroupChat has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export async function getGroupChat (group) {
                let maxChatCount = MAX_CHAT_COUNT;
                if (group.chatLimitCount && group.chatLimitCount >= MAX_CHAT_COUNT) {
                  maxChatCount = group.chatLimitCount;
                } else if (group.hasActiveGroupPlan()) {
              Severity: Minor
              Found in website/server/libs/chat/group-chat.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

              Function getLanguageFromBrowser has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export function getLanguageFromBrowser (req) {
                const originalLanguageOptions = accepts(req).languages();
                const uniqueListOfLanguages = getUniqueListOfLanguages(originalLanguageOptions);
                const baseLanguage = (uniqueListOfLanguages[0] || '').toLowerCase();
                const languageMapping = multipleVersionsLanguages[baseLanguage];
              Severity: Minor
              Found in website/server/libs/language.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

              Function preenUserHistory has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export function preenUserHistory (user, tasksByType) {
                const isSubscribed = user.isSubscribed();
                const timezoneUtcOffset = user.getUtcOffset();
                const { dayStart } = user.preferences;
                const minHistoryLength = isSubscribed ? 365 : 60;
              Severity: Minor
              Found in website/server/libs/preening.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

              Function sanitizeTransform has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                sanitizeTransform (taskObj) {
                  if (taskObj.type && taskObj.type !== 'reward') { // value should be settable directly only for rewards
                    delete taskObj.value;
                  }
              
              
              Severity: Minor
              Found in website/server/models/task.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

              Function authorizeOnBillingAgreement has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              api.authorizeOnBillingAgreement = function authorizeOnBillingAgreement (inputSet) {
                return new Promise((resolve, reject) => {
                  amzPayment.offAmazonPayments.authorizeOnBillingAgreement(inputSet, (err, response) => {
                    if (err) return reject(err);
                    if (response.AuthorizationDetails.AuthorizationStatus.State === 'Declined') return reject(new BadRequest(i18n.t('paymentNotSuccessful')));
              Severity: Minor
              Found in website/server/libs/payments/amazon.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

              Function compare has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              export async function compare (user, passwordToCheck) {
                if (!user || !passwordToCheck) throw new Error('user and passwordToCheck are required parameters.');
              
                const { passwordHashMethod } = user.auth.local;
                const passwordHash = user.auth.local.hashed_password;
              Severity: Minor
              Found in website/server/libs/password.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

              Severity
              Category
              Status
              Source
              Language