TryGhost/Ghost

View on GitHub

Showing 1,734 of 3,834 total issues

File MemberRepository.js has 1289 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 post.js has 1168 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    // # Post Model
    const _ = require('lodash');
    const uuid = require('uuid');
    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 132 (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 schema.js has 1056 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 Frame.styles.js has 1051 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 ProductsSection.js has 976 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 436 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 821 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 1 day 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 helpers.js has 792 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 740 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

                        File SignupPage.js has 717 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

                          Function linkSubscription has 325 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

                            Function SUBSCRIBED_FILTER has a Cognitive Complexity of 81 (exceeds 5 allowed). Consider refactoring.
                            Open

                            export const SUBSCRIBED_FILTER = ({newsletters, feature, group}) => {
                                if (feature.filterEmailDisabled) {
                                    return {
                                        label: newsletters.length > 1 ? 'All newsletters' : 'Newsletter subscription',
                                        name: 'subscribed',
                            Severity: Minor
                            Found in ghost/admin/app/components/members/filters/subscribed.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 onSaving has 318 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 AddOfferModal has 313 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'}

                                File EventRepository.js has 684 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} = require('@tryghost/mongo-utils');
                                
                                
                                Severity: Major
                                Found in ghost/members-api/lib/repositories/EventRepository.js - About 1 day to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language