TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function articleBodyStyles has 4696 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const articleBodyStyles = (siteUrl: string|undefined) => {
    return `<style>
    /* Table of contents
/* ------------------------------------------------------------

Severity: Major
Found in apps/admin-x-activitypub/src/components/articleBodyStyles.ts - About 3 wks to fix

    File articleBodyStyles.ts has 4699 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    const articleBodyStyles = (siteUrl: string|undefined) => {
        return `<style>
        /* Table of contents
    /* ------------------------------------------------------------
    
    
    Severity: Major
    Found in apps/admin-x-activitypub/src/components/articleBodyStyles.ts - About 1 wk to fix

      File MemberRepository.js has 1327 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      const _ = require('lodash');
      const errors = require('@tryghost/errors');
      const logging = require('@tryghost/logging');
      const tpl = require('@tryghost/tpl');
      const DomainEvents = require('@tryghost/domain-events');
      Severity: Major
      Found in ghost/members-api/lib/repositories/MemberRepository.js - About 3 days to fix

        File activitypub.test.ts has 1227 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import {Activity, ActivityPubAPI} from './activitypub';
        
        function NotFound() {
            return new Response(null, {
                status: 404
        Severity: Major
        Found in apps/admin-x-activitypub/src/api/activitypub.test.ts - About 3 days to fix

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

          // # Post Model
          const _ = require('lodash');
          const crypto = require('crypto');
          const moment = require('moment');
          const {sequence} = require('@tryghost/promise');
          Severity: Major
          Found in ghost/core/core/server/models/post.js - About 3 days to fix

            Function linkSubscription has a Cognitive Complexity of 145 (exceeds 5 allowed). Consider refactoring.
            Open

                async linkSubscription(data, options = {}) {
                    if (!this._stripeAPIService.configured) {
                        throw new errors.BadRequestError({message: tpl(messages.noStripeConnection, {action: 'link Stripe Subscription'})});
                    }
            
            
            Severity: Minor
            Found in ghost/members-api/lib/repositories/MemberRepository.js - About 2 days 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 Frame.styles.js has 1088 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            /** By default, CRAs webpack bundle combines and appends the main css at root level, so they are not applied inside iframe
             * This uses a hack where we append `<style> </style>` tag with all CSS inside the head of iframe dynamically, thus making it available easily
             * We can create separate variables to keep styles grouped logically, and export them as one appended string
            */
            
            
            Severity: Major
            Found in apps/portal/src/components/Frame.styles.js - About 2 days to fix

              File schema.js has 1065 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              /* String Column Sizes Information
               * (From: https://github.com/TryGhost/Ghost/pull/7932)
               *
               * Small strings = length 50
               * Medium strings = length 191
              Severity: Major
              Found in ghost/core/core/server/data/schema/schema.js - About 2 days to fix

                File ProductsSection.js has 987 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                import React, {useContext, useEffect, useState} from 'react';
                import {ReactComponent as LoaderIcon} from '../../images/icons/loader.svg';
                import {ReactComponent as CheckmarkIcon} from '../../images/icons/checkmark.svg';
                import {getCurrencySymbol, getPriceString, getStripeAmount, getMemberActivePrice, getProductFromPrice, getFreeTierTitle, getFreeTierDescription, getFreeProduct, getFreeProductBenefits, getSupportAddress, formatNumber, isCookiesDisabled, hasOnlyFreeProduct, isMemberActivePrice, hasFreeTrialTier, isComplimentaryMember} from '../../utils/helpers';
                import AppContext from '../../AppContext';
                Severity: Major
                Found in apps/portal/src/components/common/ProductsSection.js - About 2 days to fix

                  Function onSaving has a Cognitive Complexity of 112 (exceeds 5 allowed). Consider refactoring.
                  Open

                      onSaving: async function onSaving(model, attrs, options) {
                          options = options || {};
                  
                          const self = this;
                          let title;
                  Severity: Minor
                  Found in ghost/core/core/server/models/post.js - About 2 days 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 ProductsSectionStyles has 446 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export const ProductsSectionStyles = () => {
                      // const products = getSiteProducts({site});
                      // const noOfProducts = products.length;
                      return `
                          .gh-portal-products {
                  Severity: Major
                  Found in apps/portal/src/components/common/ProductsSection.js - About 2 days to fix

                    File App.js has 865 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import React from 'react';
                    import * as Sentry from '@sentry/react';
                    import TriggerButton from './components/TriggerButton';
                    import Notification from './components/Notification';
                    import PopupModal from './components/PopupModal';
                    Severity: Major
                    Found in apps/portal/src/App.js - About 2 days to fix

                      File user.js has 804 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      const _ = require('lodash');
                      const validator = require('@tryghost/validator');
                      const ObjectId = require('bson-objectid').default;
                      const ghostBookshelf = require('./base');
                      const baseUtils = require('./base/utils');
                      Severity: Major
                      Found in ghost/core/core/server/models/user.js - About 1 day to fix

                        File EventRepository.js has 796 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        const errors = require('@tryghost/errors');
                        const nql = require('@tryghost/nql');
                        const mingo = require('mingo');
                        const {replaceFilters, expandFilters, splitFilter, getUsedKeys, chainTransformers, mapKeys, rejectStatements} = require('@tryghost/mongo-utils');
                        
                        
                        Severity: Major
                        Found in ghost/members-api/lib/repositories/EventRepository.js - About 1 day to fix

                          File helpers.js has 795 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          import {getDateString} from './date-time';
                          
                          export function removePortalLinkFromUrl() {
                              const [path] = window.location.hash.substr(1).split('?');
                              const linkRegex = /^\/portal\/?(?:\/(\w+(?:\/\w+)*))?\/?$/;
                          Severity: Major
                          Found in apps/portal/src/utils/helpers.js - About 1 day to fix

                            Function emptyData has 368 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                get emptyData() {
                                    return {
                                        stats: [
                                            {
                                                date: '2022-04-07',
                            Severity: Major
                            Found in ghost/admin/app/components/dashboard/charts/anchor-attribution.js - About 1 day to fix

                              File anchor-attribution.js has 765 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              /* global Chart */
                              
                              import Component from '@glimmer/component';
                              import moment from 'moment-timezone';
                              import {action} from '@ember/object';
                              Severity: Major
                              Found in ghost/admin/app/components/dashboard/charts/anchor-attribution.js - About 1 day to fix

                                Function linkSubscription has 359 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    async linkSubscription(data, options = {}) {
                                        if (!this._stripeAPIService.configured) {
                                            throw new errors.BadRequestError({message: tpl(messages.noStripeConnection, {action: 'link Stripe Subscription'})});
                                        }
                                
                                
                                Severity: Major
                                Found in ghost/members-api/lib/repositories/MemberRepository.js - About 1 day to fix

                                  File SignupPage.js has 737 lines of code (exceeds 250 allowed). Consider refactoring.
                                  Open

                                  import React from 'react';
                                  import ActionButton from '../common/ActionButton';
                                  import AppContext from '../../AppContext';
                                  import CloseButton from '../common/CloseButton';
                                  import SiteTitleBackButton from '../common/SiteTitleBackButton';
                                  Severity: Major
                                  Found in apps/portal/src/components/pages/SignupPage.js - About 1 day to fix

                                    Function exports has a Cognitive Complexity of 82 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                    module.exports = function (Bookshelf) {
                                        Bookshelf.Model = Bookshelf.Model.extend({
                                            initializeEvents: function () {
                                                // NOTE: triggered before `creating`/`updating`
                                                this.on('saving', function onSaving(newObj, attrs, options) {
                                    Severity: Minor
                                    Found in ghost/core/core/server/models/base/plugins/events.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

                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language