TryGhost/Ghost

View on GitHub

Showing 3,879 of 3,879 total issues

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

    const Button: React.FC<ButtonProps> = ({
        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

        Function checkoutSessionEvent has a Cognitive Complexity of 58 (exceeds 5 allowed). Consider refactoring.
        Open

            async checkoutSessionEvent(session) {
                if (session.mode === 'setup') {
                    const setupIntent = await this.api.getSetupIntent(session.setup_intent);
                    const member = await this.deps.memberRepository.get({
                        customer_id: setupIntent.metadata.customer_id
        Severity: Minor
        Found in ghost/stripe/lib/WebhookController.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 58 (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

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

        class PreviewRouter extends ParentRouter {
            constructor(RESOURCE_CONFIG) {
                super('PreviewRouter');
        
                this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.previews;
        Severity: Major
        Found in ghost/core/core/frontend/services/routing/PreviewRouter.js and 1 other location - About 1 day to fix
        ghost/core/core/frontend/services/routing/EmailRouter.js on lines 8..48

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

        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

        class EmailRouter extends ParentRouter {
            constructor(RESOURCE_CONFIG) {
                super('EmailRouter');
        
                this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.email;
        Severity: Major
        Found in ghost/core/core/frontend/services/routing/EmailRouter.js and 1 other location - About 1 day to fix
        ghost/core/core/frontend/services/routing/PreviewRouter.js on lines 8..48

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

        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

            describe('isComplimentaryMember -', () => {
                test('returns true for complimentary member', () => {
                    const value = isComplimentaryMember({member: FixtureMember.complimentary});
                    expect(value).toBe(true);
                });
        Severity: Major
        Found in apps/portal/src/utils/helpers.test.js and 1 other location - About 1 day to fix
        apps/portal/src/utils/helpers.test.js on lines 29..49

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

        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 userReset = function userReset() {
            const ExpressBrute = require('express-brute');
            const BruteKnex = require('brute-knex');
            const db = require('../../../../data/db');
        
        
        ghost/core/core/server/web/shared/middleware/api/spam-prevention.js on lines 103..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 209.

        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 globalReset = () => {
            const ExpressBrute = require('express-brute');
            const BruteKnex = require('brute-knex');
            const db = require('../../../../data/db');
        
        
        ghost/core/core/server/web/shared/middleware/api/spam-prevention.js on lines 282..309

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

        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

            describe('isPaidMember -', () => {
                test('returns true for paid member', () => {
                    const value = isPaidMember({member: FixtureMember.paid});
                    expect(value).toBe(true);
                });
        Severity: Major
        Found in apps/portal/src/utils/helpers.test.js and 1 other location - About 1 day to fix
        apps/portal/src/utils/helpers.test.js on lines 7..27

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

        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 StripeMigrations.js has 528 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        const _ = require('lodash');
        const logging = require('@tryghost/logging');
        
        module.exports = class StripeMigrations {
            /**
        Severity: Major
        Found in ghost/stripe/lib/StripeMigrations.js - About 1 day to fix

          File api.js has 528 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import {HumanReadableError} from './errors';
          import {transformApiSiteData, transformApiTiersData, getUrlHistory} from './helpers';
          
          function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}) {
              const apiPath = 'members/api';
          Severity: Major
          Found in apps/portal/src/utils/api.js - About 1 day to fix

            Function mockMembers has 216 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export default function mockMembers(server) {
                server.post('/members/', withPermissionsCheck(ALLOWED_ROLES, function ({members}) {
                    const attrs = this.normalizedRequestAttrs();
                    return members.create(attrs);
                }));
            Severity: Major
            Found in ghost/admin/mirage/config/members.js - About 1 day to fix

              File actions.js has 526 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import setupGhostApi from './utils/api';
              import {HumanReadableError} from './utils/errors';
              import {createPopupNotification, getMemberEmail, getMemberName, getProductCadenceFromPrice, removePortalLinkFromUrl, getRefDomain} from './utils/helpers';
              
              function switchPage({data, state}) {
              Severity: Major
              Found in apps/portal/src/actions.js - About 1 day to fix

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

                module.exports = addTable('recommendations', {
                    id: {type: 'string', maxlength: 24, nullable: false, primary: true},
                
                    url: {type: 'string', maxlength: 2000, nullable: false},
                    title: {type: 'string', maxlength: 2000, nullable: false},
                ghost/core/core/server/data/schema/schema.js on lines 1079..1090

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

                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

                    recommendations: {
                        id: {type: 'string', maxlength: 24, nullable: false, primary: true},
                        url: {type: 'string', maxlength: 2000, nullable: false},
                        title: {type: 'string', maxlength: 2000, nullable: false},
                        excerpt: {type: 'string', maxlength: 2000, nullable: true},
                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.61/2023-08-29-11-39-10-add-recommendations-table.js on lines 3..18

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

                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

                    format() {
                        const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments);
                        const settingType = attrs.type;
                
                        if (settingType === 'boolean') {
                Severity: Major
                Found in ghost/core/core/server/models/custom-theme-setting.js and 1 other location - About 1 day to fix
                ghost/core/core/server/models/settings.js on lines 139..160

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

                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

                    format() {
                        const attrs = ghostBookshelf.Model.prototype.format.apply(this, arguments);
                        const settingType = attrs.type;
                
                        if (settingType === 'boolean') {
                Severity: Major
                Found in ghost/core/core/server/models/settings.js and 1 other location - About 1 day to fix
                ghost/core/core/server/models/custom-theme-setting.js on lines 30..51

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

                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

                Severity
                Category
                Status
                Source
                Language