TryGhost/Ghost

View on GitHub

Showing 4,015 of 4,015 total issues

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

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

    function getTwitterImage(data) {
        const context = data.context ? data.context : null;
        const contextObject = getContextObject(data, context);
    
        if (_.includes(context, 'home')) {
    Severity: Major
    Found in ghost/core/core/frontend/meta/twitter-image.js and 1 other location - About 2 days to fix
    ghost/core/core/frontend/meta/og-image.js on lines 6..42

    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 415.

    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

    function getOgImage(data) {
        const context = data.context ? data.context : null;
        const contextObject = getContextObject(data, context);
    
        if (_.includes(context, 'home')) {
    Severity: Major
    Found in ghost/core/core/frontend/meta/og-image.js and 1 other location - About 2 days to fix
    ghost/core/core/frontend/meta/twitter-image.js on lines 6..42

    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 415.

    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 all(models, apiConfig, frame) {
            debug('all');
    
            // CASE: e.g. destroy returns null
            if (!models) {
    ghost/core/core/server/api/endpoints/utils/serializers/output/pages.js on lines 6..54

    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 406.

    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 all(models, apiConfig, frame) {
            debug('all');
    
            // CASE: e.g. destroy returns null
            if (!models) {
    ghost/core/core/server/api/endpoints/utils/serializers/output/posts.js on lines 7..54

    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 406.

    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 (data.monthly_price) {
                        const existingPrice = await this._StripePrice.findOne({
                            stripe_product_id: defaultStripeProduct.get('stripe_product_id'),
                            amount: data.monthly_price.amount,
                            currency: data.monthly_price.currency,
    Severity: Major
    Found in ghost/members-api/lib/repositories/ProductRepository.js and 1 other location - About 2 days to fix
    ghost/members-api/lib/repositories/ProductRepository.js on lines 513..560

    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 405.

    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 (data.yearly_price) {
                        const existingPrice = await this._StripePrice.findOne({
                            stripe_product_id: defaultStripeProduct.get('stripe_product_id'),
                            amount: data.yearly_price.amount,
                            currency: data.yearly_price.currency,
    Severity: Major
    Found in ghost/members-api/lib/repositories/ProductRepository.js and 1 other location - About 2 days to fix
    ghost/members-api/lib/repositories/ProductRepository.js on lines 465..511

    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 405.

    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

        Array.prototype.forEach.call(document.querySelectorAll('[data-members-continue-subscription]'), function (el) {
            let errorEl = el.parentElement.querySelector('[data-members-error]');
            function clickHandler(event) {
                el.removeEventListener('click', clickHandler);
                event.preventDefault();
    Severity: Major
    Found in apps/portal/src/data-attributes.js and 1 other location - About 2 days to fix
    apps/portal/src/data-attributes.js on lines 294..342

    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 405.

    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

        Array.prototype.forEach.call(document.querySelectorAll('[data-members-cancel-subscription]'), function (el) {
            let errorEl = el.parentElement.querySelector('[data-members-error]');
            function clickHandler(event) {
                el.removeEventListener('click', clickHandler);
                event.preventDefault();
    Severity: Major
    Found in apps/portal/src/data-attributes.js and 1 other location - About 2 days to fix
    apps/portal/src/data-attributes.js on lines 344..392

    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 405.

    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 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

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

        module.exports = utils.addTable('offers', {
            id: {type: 'string', maxlength: 24, nullable: false, primary: true},
            active: {type: 'boolean', nullable: false, defaultTo: true},
            name: {type: 'string', maxlength: 191, nullable: false, unique: true},
            code: {type: 'string', maxlength: 191, nullable: false, unique: true},
        ghost/core/core/server/data/migrations/versions/4.20/02-remove-offers-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 352.

        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

        const migration = utils.addTable('offers', {
            id: {type: 'string', maxlength: 24, nullable: false, primary: true},
            active: {type: 'boolean', nullable: false, defaultTo: true},
            name: {type: 'string', maxlength: 191, nullable: false, unique: true},
            code: {type: 'string', maxlength: 191, nullable: false, unique: true},
        ghost/core/core/server/data/migrations/versions/4.20/03-add-offers-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 352.

        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 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
                    Severity
                    Category
                    Status
                    Source
                    Language