TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function formatRelativeTime has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

export function formatRelativeTime(dateString: string, t: TranslationFunction): string {
    const date = new Date(dateString);
    const now = new Date();

    // Diff is in seconds
Severity: Minor
Found in apps/comments-ui/src/utils/helpers.ts - About 2 hrs 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 getAllActivities has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    async getAllActivities(
        includeOwn: boolean = false,
        includeReplies: boolean = false,
        filter: {type?: string[]} | null = null
    ): Promise<Activity[]> {
Severity: Minor
Found in apps/admin-x-activitypub/src/api/activitypub.ts - About 2 hrs 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 formatUrl has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

export const formatUrl = (value: string, baseUrl?: string, nullable?: boolean) => {
    if (nullable && !value) {
        return {save: null, display: ''};
    }

Severity: Minor
Found in apps/admin-x-design-system/src/utils/formatUrl.ts - About 2 hrs 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 EditOfferModal.tsx has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import NiceModal from '@ebay/nice-modal-react';
import PortalFrame from '../../membership/portal/PortalFrame';
import toast from 'react-hot-toast';
import {Button, ConfirmationModal, Form, PreviewModalContent, TextArea, TextField, showToast} from '@tryghost/admin-x-design-system';
import {ErrorMessages, useForm, useHandleError} from '@tryghost/admin-x-framework/hooks';

    Function generate has 68 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        generate() {
            const title = faker.lorem.sentence();
            const content = faker.lorem.paragraphs(faker.datatype.number({
                min: 3,
                max: 10
    Severity: Major
    Found in ghost/data-generator/lib/importers/PostsImporter.js - About 2 hrs to fix

      Function getAdapter has 68 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          getAdapter(adapterName, adapterClassName, config) {
              if (!adapterName || !adapterClassName) {
                  throw new errors.IncorrectUsageError({
                      message: 'getAdapter must be called with a adapterName and a adapterClassName.'
                  });
      Severity: Major
      Found in ghost/adapter-manager/lib/AdapterManager.js - About 2 hrs to fix

        Function countRelations has 68 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            countRelations() {
                return {
                    signups(modelOrCollection) {
                        modelOrCollection.query('columns', 'posts.*', (qb) => {
                            qb.count('members_created_events.id')
        Severity: Major
        Found in ghost/core/core/server/models/post.js - About 2 hrs to fix

          Function createSessionFromMagicLink has 68 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          const createSessionFromMagicLink = async function createSessionFromMagicLink(req, res, next) {
              if (!req.url.includes('token=')) {
                  return next();
              }
          
          
          Severity: Major
          Found in ghost/core/core/server/services/members/middleware.js - About 2 hrs to fix

            File PreviewModal.tsx has 280 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import NiceModal, {useModal} from '@ebay/nice-modal-react';
            import clsx from 'clsx';
            import React, {useEffect, useState} from 'react';
            import useGlobalDirtyState from '../../hooks/useGlobalDirtyState';
            import {confirmIfDirty} from '../../utils/modals';
            Severity: Minor
            Found in apps/admin-x-design-system/src/global/modal/PreviewModal.tsx - About 2 hrs to fix

              File Form.tsx has 279 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import React from 'react';
              import {Avatar} from '../Avatar';
              import {Comment, useAppContext, useLabs} from '../../../AppContext';
              import {ReactComponent as EditIcon} from '../../../images/icons/edit.svg';
              import {Editor, EditorContent} from '@tiptap/react';
              Severity: Minor
              Found in apps/comments-ui/src/components/content/forms/Form.tsx - About 2 hrs to fix

                Function get has 67 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                module.exports = async function get(resource, options) {
                    options = options || {};
                    options.hash = options.hash || {};
                    options.data = options.data || {};
                
                
                Severity: Major
                Found in ghost/core/core/frontend/helpers/get.js - About 2 hrs to fix

                  Function AddIntegrationModal has 67 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const AddIntegrationModal: React.FC<RoutingModalProps> = () => {
                      const modal = useModal();
                      const {updateRoute} = useRouting();
                      const [name, setName] = useState('');
                      const [errors, setErrors] = useState({name: ''});

                    OfferPage has 24 functions (exceeds 20 allowed). Consider refactoring.
                    Open

                    export default class OfferPage extends React.Component {
                        static contextType = AppContext;
                    
                        constructor(props, context) {
                            super(props, context);
                    Severity: Minor
                    Found in apps/portal/src/components/pages/OfferPage.js - About 2 hrs to fix

                      SignupPage has 24 functions (exceeds 20 allowed). Consider refactoring.
                      Open

                      class SignupPage extends React.Component {
                          static contextType = AppContext;
                      
                          constructor(props) {
                              super(props);
                      Severity: Minor
                      Found in apps/portal/src/components/pages/SignupPage.js - About 2 hrs to fix

                        File members.js has 277 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        import moment from 'moment-timezone';
                        import nql from '@tryghost/nql';
                        import {Response} from 'miragejs';
                        import {
                            extractFilterParam,
                        Severity: Minor
                        Found in ghost/admin/mirage/config/members.js - About 2 hrs to fix

                          Function up has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              async function up(knex) {
                                  logging.info('Resolving the orphaned webhooks');
                          
                                  const orphanedWebhooks = await knex('webhooks')
                                      .select('webhooks.id')

                            Function getDescription has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            function getDescription(data, root, options = {}) {
                                const context = root ? root.context : null;
                            
                                let description = '';
                            
                            
                            Severity: Major
                            Found in ghost/core/core/frontend/meta/description.js - About 2 hrs to fix

                              Function NavigationModal has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              const NavigationModal = NiceModal.create(() => {
                                  const modal = useModal();
                                  const {updateRoute} = useRouting();
                                  const {
                                      localSettings,

                                Function getReferrerDetails has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    getReferrerDetails(history) {
                                        // Empty history will return null as it means script is not loaded
                                        if (history.length === 0) {
                                            return {
                                                referrerSource: null,
                                Severity: Major
                                Found in ghost/member-attribution/lib/ReferrerTranslator.js - About 2 hrs to fix

                                  Function constructor has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      constructor({
                                          labs,
                                          membersService,
                                          donationService,
                                          staffService,
                                  Severity: Major
                                  Found in ghost/stripe/lib/StripeService.js - About 2 hrs to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language