TryGhost/Ghost

View on GitHub

Showing 3,834 of 3,834 total issues

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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      async function unlikeComment({state, api, data: comment}: {state: EditableAppContext, api: GhostApi, data: {id: string}}) {
          await api.comments.unlike({comment});
      
          return {
              comments: state.comments.map((c) => {
      Severity: Major
      Found in apps/comments-ui/src/actions.ts and 1 other location - About 1 day to fix
      apps/comments-ui/src/actions.ts on lines 141..179

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 280.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      async function likeComment({state, api, data: comment}: {state: EditableAppContext, api: GhostApi, data: {id: string}}) {
          await api.comments.like({comment});
      
          return {
              comments: state.comments.map((c) => {
      Severity: Major
      Found in apps/comments-ui/src/actions.ts and 1 other location - About 1 day to fix
      apps/comments-ui/src/actions.ts on lines 187..224

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 280.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                      <SettingGroupContent className="overflow-hidden rounded-md border border-grey-300 dark:border-grey-900">
                          <ImageUpload
                              fileUploadClassName='flex cursor-pointer items-center justify-center rounded rounded-b-none border border-grey-100 border-b-0 bg-grey-75 p-3 text-sm font-semibold text-grey-800 hover:text-black dark:border-grey-900'
                              height='300px'
                              id='twitter-image'
      apps/admin-x-settings/src/components/settings/general/Facebook.tsx on lines 77..117

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 264.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                      <SettingGroupContent className="overflow-hidden rounded-md border border-grey-300 dark:border-grey-900">
                          <ImageUpload
                              fileUploadClassName='flex cursor-pointer items-center justify-center rounded rounded-b-none border border-grey-100 border-b-0 bg-grey-75 p-3 text-sm font-semibold text-grey-800 hover:text-black dark:border-grey-900'
                              height='300px'
                              id='facebook-image'
      apps/admin-x-settings/src/components/settings/general/Twitter.tsx on lines 73..113

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 264.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          async getEmailOpenedEvents(options = {}, filter) {
              options = {
                  ...options,
                  withRelated: ['member', 'email'],
                  filter: 'opened_at:-null+custom:true',
      Severity: Major
      Found in ghost/members-api/lib/repositories/EventRepository.js and 1 other location - About 1 day to fix
      ghost/members-api/lib/repositories/EventRepository.js on lines 608..648

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 260.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          async getEmailDeliveredEvents(options = {}, filter) {
              options = {
                  ...options,
                  withRelated: ['member', 'email'],
                  filter: 'delivered_at:-null+custom:true',
      Severity: Major
      Found in ghost/members-api/lib/repositories/EventRepository.js and 1 other location - About 1 day to fix
      ghost/members-api/lib/repositories/EventRepository.js on lines 650..690

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 260.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      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 PopupModal.js has 619 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 update has a Cognitive Complexity of 68 (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

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  permissions: {
                      before: (frame) => {
                          if (frame.options.context && frame.options.context.integration && frame.options.context.integration.id) {
                              return models.Webhook.findOne({id: frame.options.id})
                                  .then((webhook) => {
          Severity: Major
          Found in ghost/core/core/server/api/endpoints/webhooks.js and 1 other location - About 1 day to fix
          ghost/core/core/server/api/endpoints/webhooks.js on lines 40..66

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 247.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

                  permissions: {
                      before: (frame) => {
                          if (frame.options.context && frame.options.context.integration && frame.options.context.integration.id) {
                              return models.Webhook.findOne({id: frame.options.id})
                                  .then((webhook) => {
          Severity: Major
          Found in ghost/core/core/server/api/endpoints/webhooks.js and 1 other location - About 1 day to fix
          ghost/core/core/server/api/endpoints/webhooks.js on lines 104..130

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 247.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          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

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

              email_recipient_failures: {
                  id: {type: 'string', maxlength: 24, nullable: false, primary: true},
                  email_id: {type: 'string', maxlength: 24, nullable: false, references: 'emails.id'},
                  member_id: {type: 'string', maxlength: 24, nullable: true},
                  email_recipient_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_recipients.id'},
          Severity: Major
          Found in ghost/core/core/server/data/schema/schema.js and 1 other location - About 1 day to fix
          ghost/core/core/server/data/migrations/versions/5.25/2022-11-29-08-30-add-error-recipient-failures-table.js on lines 3..20

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 243.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Identical blocks of code found in 2 locations. Consider refactoring.
          Open

          module.exports = utils.addTable('email_recipient_failures', {
              id: {type: 'string', maxlength: 24, nullable: false, primary: true},
              email_id: {type: 'string', maxlength: 24, nullable: false, references: 'emails.id'},
              member_id: {type: 'string', maxlength: 24, nullable: true},
              email_recipient_id: {type: 'string', maxlength: 24, nullable: false, references: 'email_recipients.id'},
          ghost/core/core/server/data/schema/schema.js on lines 881..898

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 243.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          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

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if (!monthlyPrice) {
                        logging.info('Could not any active Monthly price - creating a new one');
                        let defaultStripeProduct;
                        const stripeProductsPage = await this.models.StripeProduct.findPage({...options, limit: 1});
                        defaultStripeProduct = stripeProductsPage.data[0];
            Severity: Major
            Found in ghost/stripe/lib/StripeMigrations.js and 1 other location - About 1 day to fix
            ghost/stripe/lib/StripeMigrations.js on lines 399..424

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 242.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                    if (!yearlyPrice) {
                        logging.info('Could not any active yearly price - creating a new one');
                        let defaultStripeProduct;
                        const stripeProductsPage = await this.models.StripeProduct.findPage({...options, limit: 1});
                        defaultStripeProduct = stripeProductsPage.data[0];
            Severity: Major
            Found in ghost/stripe/lib/StripeMigrations.js and 1 other location - About 1 day to fix
            ghost/stripe/lib/StripeMigrations.js on lines 323..348

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 242.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

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

            import PortalFrame from '../../membership/portal/PortalFrame';
            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';
            import {getHomepageUrl} from '@tryghost/admin-x-framework/api/site';
              Severity
              Category
              Status
              Source
              Language