TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function ImageUpload has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

const ImageUpload: React.FC<ImageUploadProps> = ({
    id,
    children,
    width = '100%',
    height = '120px',
Severity: Minor
Found in apps/admin-x-design-system/src/global/form/ImageUpload.tsx - About 4 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 init has 114 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    async init() {
        if (initialised) {
            return;
        }

Severity: Major
Found in ghost/core/core/server/services/mentions-email-report/service.js - About 4 hrs to fix

    File data-attributes.js has 356 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    /* eslint-disable no-console */
    import {getCheckoutSessionDataFromPlanAttribute, getUrlHistory} from './utils/helpers';
    import {HumanReadableError, chooseBestErrorMessage} from './utils/errors';
    import i18nLib from '@tryghost/i18n';
    
    
    Severity: Minor
    Found in apps/portal/src/data-attributes.js - About 4 hrs to fix

      Function init has 112 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          init() {
              const config = require('../../../shared/config');
              if (config.get('services:recommendations:enabled') === false) {
                  logging.info('[Recommendations] Service is disabled via config');
                  return;

        Function doImport has 112 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            doImport: async function doImport(importData, importOptions) {
                debug('doImport');
                importOptions = importOptions || {};
        
                if (importOptions.importTag && importData?.data?.posts) {
        Severity: Major
        Found in ghost/core/core/server/data/importer/importers/data/data-importer.js - About 4 hrs to fix

          Function exports has 111 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = async (model, frame, options = {}) => {
              const {tiers: tiersData} = options || {};
          
              // NOTE: `model` is now overloaded and may be a bookshelf model or a POJO
              let jsonModel = model;

            Function beforeImport has 111 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                beforeImport() {
                    debug('beforeImport');
            
                    const activeTheme = _.find(this.dataToImport, {key: 'active_theme'});
            
            

              Function foreach has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
              Open

              module.exports = function foreach(items, options) {
                  if (!options) {
                      logging.warn(tpl(messages.iteratorNeeded));
                  }
              
              
              Severity: Minor
              Found in ghost/core/core/frontend/helpers/foreach.js - About 4 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 updateProfile has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
              Open

              async function updateProfile({data, state, api}) {
                  const {t} = state;
                  const [dataUpdate, emailUpdate] = await Promise.all([updateMemberData({data, state, api}), updateMemberEmail({data, state, api})]);
                  if (dataUpdate && emailUpdate) {
                      if (emailUpdate.success) {
              Severity: Minor
              Found in apps/portal/src/actions.js - About 4 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

              exports has 34 functions (exceeds 20 allowed). Consider refactoring.
              Open

              module.exports = {
                  get all() {
                      return require('./all');
                  },
              
              

                File settings.js has 347 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                const _ = require('lodash');
                const crypto = require('crypto');
                const keypair = require('keypair');
                const ObjectID = require('bson-objectid').default;
                const ghostBookshelf = require('./base');
                Severity: Minor
                Found in ghost/core/core/server/models/settings.js - About 4 hrs to fix

                  Function setComplimentarySubscription has 108 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      async setComplimentarySubscription(data, options = {}) {
                          if (!options.transacting) {
                              return this._Member.transaction((transacting) => {
                                  return this.setComplimentarySubscription(data, {
                                      ...options,
                  Severity: Major
                  Found in ghost/members-api/lib/repositories/MemberRepository.js - About 4 hrs to fix

                    File validate.js has 345 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    const _ = require('lodash');
                    const tpl = require('@tryghost/tpl');
                    const errors = require('@tryghost/errors');
                    const _private = {};
                    let RESOURCE_CONFIG;
                    Severity: Minor
                    Found in ghost/core/core/server/services/route-settings/validate.js - About 4 hrs to fix

                      Function http has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const http = (apiImpl) => {
                          /**
                           * @param {import('express').Request} req - Express request object.
                           * @param {import('express').Response} res - Express response object.
                           * @param {import('express').NextFunction} next - Express next function.
                      Severity: Minor
                      Found in ghost/api-framework/lib/http.js - About 4 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 getPageFromLinkPath has 106 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          getPageFromLinkPath(path) {
                              const customPricesSignupRegex = /^signup\/?(?:\/(\w+?))?\/?$/;
                              const customMonthlyProductSignup = /^signup\/?(?:\/(\w+?))\/monthly\/?$/;
                              const customYearlyProductSignup = /^signup\/?(?:\/(\w+?))\/yearly\/?$/;
                              const customOfferRegex = /^offers\/(\w+?)\/?$/;
                      Severity: Major
                      Found in apps/portal/src/App.js - About 4 hrs to fix

                        File members-api.js has 342 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        const {Router} = require('express');
                        const body = require('body-parser');
                        const MagicLink = require('@tryghost/magic-link');
                        const errors = require('@tryghost/errors');
                        const logging = require('@tryghost/logging');
                        Severity: Minor
                        Found in ghost/members-api/lib/members-api.js - About 4 hrs to fix

                          Function permissible has 105 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              permissible: async function permissible(userModelOrId, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
                                  const self = this;
                                  const userModel = userModelOrId;
                                  let origArgs;
                          
                          
                          Severity: Major
                          Found in ghost/core/core/server/models/user.js - About 4 hrs to fix

                            File TierDetailModal.tsx has 341 lines of code (exceeds 250 allowed). Consider refactoring.
                            Open

                            import NiceModal from '@ebay/nice-modal-react';
                            import React, {useEffect, useRef} from 'react';
                            import TierDetailPreview from './TierDetailPreview';
                            import useSettingGroup from '../../../../hooks/useSettingGroup';
                            import {Button, ButtonProps, ConfirmationModal, CurrencyField, Form, Heading, Icon, Modal, Select, SortableList, TextField, Toggle, URLTextField, showToast, useSortableIndexedList} from '@tryghost/admin-x-design-system';

                              File post.js has 339 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              import Ember from 'ember';
                              import Model, {attr, belongsTo, hasMany} from '@ember-data/model';
                              import ValidationEngine from 'ghost-admin/mixins/validation-engine';
                              import boundOneWay from 'ghost-admin/utils/bound-one-way';
                              import moment from 'moment-timezone';
                              Severity: Minor
                              Found in ghost/admin/app/models/post.js - About 4 hrs to fix

                                File actions.ts has 339 lines of code (exceeds 250 allowed). Consider refactoring.
                                Open

                                import {AddComment, Comment, CommentsOptions, EditableAppContext} from './AppContext';
                                import {AdminApi} from './utils/adminApi';
                                import {GhostApi} from './utils/api';
                                import {Page} from './pages';
                                
                                
                                Severity: Minor
                                Found in apps/comments-ui/src/actions.ts - About 4 hrs to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language