TryGhost/Ghost

View on GitHub

Showing 1,756 of 3,886 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

File PopupModal.js has 281 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import React from 'react';
import Frame from './Frame';
import {hasMode} from '../utils/check-mode';
import AppContext from '../AppContext';
import {getFrameStyles} from './Frame.styles';
Severity: Minor
Found in apps/portal/src/components/PopupModal.js - About 2 hrs to fix

    File api.ts has 281 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import {AddComment, Comment} from '../AppContext';
    
    function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}: {siteUrl: string, apiUrl: string, apiKey: string}) {
        const apiPath = 'members/api';
    
    
    Severity: Minor
    Found in apps/comments-ui/src/utils/api.ts - About 2 hrs to fix

      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

                  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 faker from 'faker';
                        import moment from 'moment-timezone';
                        import nql from '@tryghost/nql';
                        import {Response} from 'miragejs';
                        import {
                        Severity: Minor
                        Found in ghost/admin/mirage/config/members.js - About 2 hrs to fix

                          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 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 fetchOembedDataFromUrl has 66 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  async fetchOembedDataFromUrl(url, type, options = {}) {
                                      try {
                                          const urlObject = new URL(url);
                              
                                          // Trimming solves the difference of url validation between `new URL(url)`
                              Severity: Major
                              Found in ghost/oembed-service/lib/OEmbedService.js - About 2 hrs to fix

                                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 onSaving has 65 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      onSaving: function onSaving(newPage, attr, options) {
                                          const self = this;
                                          const tasks = [];
                                          let passwordValidation = {};
                                  
                                  
                                  Severity: Major
                                  Found in ghost/core/core/server/models/user.js - About 2 hrs to fix

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

                                    const authenticateWithToken = async function apiKeyAuthenticateWithToken(originalUrl, token, ignoreMaxAge) {
                                        const decoded = jwt.decode(token, {complete: true});
                                        const jwtValidationOptions = ignoreMaxAge ? _.omit(JWT_OPTIONS_DEFAULTS, 'maxAge') : JWT_OPTIONS_DEFAULTS;
                                    
                                        if (!decoded || !decoded.header) {
                                    Severity: Major
                                    Found in ghost/core/core/server/services/auth/api-key/admin.js - About 2 hrs to fix

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

                                      function ping(post) {
                                          let pingXML;
                                          const title = post.title;
                                          const url = urlService.getUrlByResourceId(post.id, {absolute: true});
                                      
                                      
                                      Severity: Major
                                      Found in ghost/core/core/server/services/xmlrpc.js - About 2 hrs to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language