TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function AddOfferModal has 327 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const AddOfferModal = () => {
    const {siteData} = useGlobalData();
    const typeOptions = [
        {title: 'Discount', description: 'Offer a special reduced price', value: 'percent'},
        {title: 'Free trial', description: 'Give free access for a limited time', value: 'trial'}

    Function onSaving has 319 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        onSaving: async function onSaving(model, attrs, options) {
            options = options || {};
    
            const self = this;
            let title;
    Severity: Major
    Found in ghost/core/core/server/models/post.js - About 1 day to fix

      Function ghost_head has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
      Open

      module.exports = async function ghost_head(options) { // eslint-disable-line camelcase
          debug('begin');
      
          // if server error page do nothing
          if (options.data.root.statusCode >= 500) {
      Severity: Minor
      Found in ghost/core/core/frontend/helpers/ghost_head.js - About 1 day 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 update has a Cognitive Complexity of 70 (exceeds 5 allowed). Consider refactoring.
      Open

          async update(data, options) {
              const sharedOptions = {
                  transacting: options.transacting
              };
      
      
      Severity: Minor
      Found in ghost/members-api/lib/repositories/MemberRepository.js - About 1 day 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

      File PopupModal.js has 624 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import Frame from './Frame';
      import AppContext from '../AppContext';
      import {ReactComponent as SearchIcon} from '../icons/search.svg';
      import {ReactComponent as ClearIcon} from '../icons/clear.svg';
      import {ReactComponent as CircleAnimated} from '../icons/circle-anim.svg';
      Severity: Major
      Found in apps/sodo-search/src/components/PopupModal.js - About 1 day to fix

        Function extendModel has 272 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
            const proto = Post.prototype;
        
            const Model = Post.extend({
                _handleOptions: function _handleOptions(fnName) {
        Severity: Major
        Found in ghost/core/core/server/models/relations/authors.js - About 1 day to fix

          File AddOfferModal.tsx has 613 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import PortalFrame from '../../membership/portal/PortalFrame';
          import toast from 'react-hot-toast';
          import {Button} from '@tryghost/admin-x-design-system';
          import {ErrorMessages, useForm} from '@tryghost/admin-x-framework/hooks';
          import {Form, Icon, PreviewModalContent, Select, SelectOption, TextArea, TextField, showToast} from '@tryghost/admin-x-design-system';

            Function extendModel has a Cognitive Complexity of 67 (exceeds 5 allowed). Consider refactoring.
            Open

            module.exports.extendModel = function extendModel(Post, Posts, ghostBookshelf) {
                const proto = Post.prototype;
            
                const Model = Post.extend({
                    _handleOptions: function _handleOptions(fnName) {
            Severity: Minor
            Found in ghost/core/core/server/models/relations/authors.js - About 1 day 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

            File OfferPage.js has 601 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import React from 'react';
            import ActionButton from '../common/ActionButton';
            import AppContext from '../../AppContext';
            import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
            import CloseButton from '../common/CloseButton';
            Severity: Major
            Found in apps/portal/src/components/pages/OfferPage.js - About 1 day to fix

              Function UserDetailModalContent has a Cognitive Complexity of 66 (exceeds 5 allowed). Consider refactoring.
              Open

              const UserDetailModalContent: React.FC<{user: User}> = ({user}) => {
                  const {updateRoute} = useRouting();
                  const {ownerUser} = useStaffUsers();
                  const {currentUser} = useGlobalData();
                  const handleError = useHandleError();

              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 update has 259 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  async update(data, options = {}) {
                      if (!this._stripeAPIService.configured && (data.stripe_prices || data.monthly_price || data.yearly_price)) {
                          throw new UpdateCollisionError({
                              message: 'The requested functionality requires Stripe to be configured. See https://ghost.org/integrations/stripe/',
                              code: 'STRIPE_NOT_CONFIGURED'
              Severity: Major
              Found in ghost/members-api/lib/repositories/ProductRepository.js - About 1 day to fix

                Function updateMockedData has 258 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    updateMockedData({days}) {
                        const generateDays = days;
                        const startDate = new Date();
                        startDate.setDate(startDate.getDate() - generateDays + 1);
                
                
                Severity: Major
                Found in ghost/admin/app/services/dashboard-mocks.js - About 1 day to fix

                  Function update has a Cognitive Complexity of 65 (exceeds 5 allowed). Consider refactoring.
                  Open

                      async update(data, options = {}) {
                          if (!this._stripeAPIService.configured && (data.stripe_prices || data.monthly_price || data.yearly_price)) {
                              throw new UpdateCollisionError({
                                  message: 'The requested functionality requires Stripe to be configured. See https://ghost.org/integrations/stripe/',
                                  code: 'STRIPE_NOT_CONFIGURED'
                  Severity: Minor
                  Found in ghost/members-api/lib/repositories/ProductRepository.js - About 1 day 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 setupGhostApi has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
                  Open

                  function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
                      const apiPath = 'members/api';
                  
                      function endpointFor({type, resource}) {
                          if (type === 'members') {
                  Severity: Minor
                  Found in apps/portal/src/utils/api.js - About 1 day 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 apiRoutes has 248 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  module.exports = function apiRoutes() {
                      const router = express.Router('admin api');
                  
                      // alias delete with del
                      router.del = router.delete;
                  Severity: Major
                  Found in ghost/core/core/server/web/api/endpoints/admin/routes.js - About 1 day to fix

                    File NewsletterDetailModal.tsx has 572 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import NewsletterPreview from './NewsletterPreview';
                    import NiceModal from '@ebay/nice-modal-react';
                    import React, {useCallback, useEffect, useMemo, useState} from 'react';
                    import useFeatureFlag from '../../../../hooks/useFeatureFlag';
                    import useSettingGroup from '../../../../hooks/useSettingGroup';

                      Function TierDetailModalContent has a Cognitive Complexity of 61 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const TierDetailModalContent: React.FC<{tier?: Tier}> = ({tier}) => {
                          const isFreeTier = tier?.type === 'free';
                      
                          const {updateRoute} = useRouting();
                          const {mutateAsync: updateTier} = useEditTier();

                      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 Button has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
                      Open

                      const Button: React.FC<ButtonProps> = React.forwardRef(({
                          testId,
                          size = 'md',
                          label = '',
                          hideLabel = false,
                      Severity: Minor
                      Found in apps/admin-x-design-system/src/global/Button.tsx - About 1 day 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 ListPage has 230 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      const ListPage = () => {
                          const {updateRoute} = useRouting();
                          const [view, setView] = useState<string>('list');
                      
                          const dummyActions = [
                      Severity: Major
                      Found in apps/admin-x-demo/src/ListPage.tsx - About 1 day to fix

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

                        module.exports = {
                            get authentication() {
                                return apiFramework.pipeline(require('./authentication'), localUtils);
                            },
                        
                        
                        Severity: Major
                        Found in ghost/core/core/server/api/endpoints/index.js - About 1 day to fix
                          Severity
                          Category
                          Status
                          Source
                          Language