TryGhost/Ghost

View on GitHub

Showing 1,813 of 3,998 total issues

exports has 23 functions (exceeds 20 allowed). Consider refactoring.
Open

module.exports = class EventRepository {
    constructor({
        DonationPaymentEvent,
        EmailRecipient,
        MemberSubscribeEvent,
Severity: Minor
Found in ghost/members-api/lib/repositories/EventRepository.js - About 2 hrs to fix

    `` has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    User = ghostBookshelf.Model.extend({
    
        tableName: 'users',
    
        actionsCollectCRUD: true,
    Severity: Minor
    Found in ghost/core/core/server/models/user.js - About 2 hrs to fix

      ActivityPubAPI has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      export class ActivityPubAPI {
          constructor(
              private readonly apiUrl: URL,
              private readonly authApiUrl: URL,
              private readonly handle: string,
      Severity: Minor
      Found in apps/admin-x-activitypub/src/api/activitypub.ts - About 2 hrs to fix

        Function buildObjectTypeHandlers has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            buildObjectTypeHandlers(objTypes, actType, context, permissionLoad) {
                const objectTypeModelMap = {
                    post: models.Post,
                    role: models.Role,
                    user: models.User,
        Severity: Major
        Found in ghost/core/core/server/services/permissions/can-this.js - About 2 hrs to fix

          Function unsubscribeController has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = async function unsubscribeController(req, res) {
              debug('unsubscribeController');
          
              const {query} = url.parse(req.url, true);
          
          
          Severity: Major
          Found in ghost/core/core/frontend/services/routing/controllers/unsubscribe.js - About 2 hrs to fix

            File OffersIndex.tsx has 269 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import {Button, Tab, TabView} from '@tryghost/admin-x-design-system';
            import {ButtonGroup, ButtonProps, showToast} from '@tryghost/admin-x-design-system';
            import {Icon} from '@tryghost/admin-x-design-system';
            import {Modal} from '@tryghost/admin-x-design-system';
            import {SortMenu} from '@tryghost/admin-x-design-system';

              File Users.tsx has 269 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              import React, {useEffect, useState} from 'react';
              import TopLevelGroup from '../../TopLevelGroup';
              import clsx from 'clsx';
              import useQueryParams from '../../../hooks/useQueryParams';
              import useStaffUsers from '../../../hooks/useStaffUsers';
              Severity: Minor
              Found in apps/admin-x-settings/src/components/settings/general/Users.tsx - About 2 hrs to fix

                Function mockPosts has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export default function mockPosts(server) {
                    server.post('/posts', function ({posts, users, tags}) {
                        let attrs = this.normalizedRequestAttrs();
                
                        attrs.authors = extractAuthors(attrs, users);
                Severity: Major
                Found in ghost/admin/mirage/config/posts.js - About 2 hrs to fix

                  Function getPortalPreviewUrl has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      getPortalPreviewUrl(overrides) {
                          let {
                              disableBackground = false,
                              page = 'signup',
                              button = this.settings.portalButton,
                  Severity: Major
                  Found in ghost/admin/app/services/members-utils.js - About 2 hrs to fix

                    Function populateStripePricesFromStripePlansSetting has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        async populateStripePricesFromStripePlansSetting(options) {
                            if (!options) {
                                return this.models.Product.transaction((transacting) => {
                                    return this.populateStripePricesFromStripePlansSetting({transacting});
                                });
                    Severity: Major
                    Found in ghost/stripe/lib/StripeMigrations.js - About 2 hrs to fix

                      Function connectAndSend has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      module.exports.connectAndSend = (socketAddress, message) => {
                          // Very basic guard against bad calls
                          if (!socketAddress || !socketAddress.host || !socketAddress.port || !logging || !logging.info || !logging.warn || !message) {
                              return Promise.resolve();
                          }
                      Severity: Major
                      Found in ghost/bootstrap-socket/lib/bootstrap-socket.js - About 2 hrs to fix

                        Function exports has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        module.exports = function (Bookshelf) {
                            const ParentModel = Bookshelf.Model;
                        
                            Bookshelf.Model = Bookshelf.Model.extend({
                                /**
                        Severity: Major
                        Found in ghost/core/core/server/models/base/plugins/overrides.js - About 2 hrs to fix

                          Function useLimiter has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          export const useLimiter = () => {
                              const {config} = useGlobalData();
                              const [LimitService, setLimitService] = useState<typeof import('@tryghost/limit-service') | null>(null);
                          
                              useEffect(() => {
                          Severity: Major
                          Found in apps/admin-x-settings/src/hooks/useLimiter.tsx - About 2 hrs to fix

                            Function dummyCards has 61 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                const dummyCards = (noOfCards: number) => {
                                    const cards = [];
                            
                                    for (let i = 0; i < noOfCards; i++) {
                                        cards.push(
                            Severity: Major
                            Found in apps/admin-x-demo/src/ListPage.tsx - About 2 hrs to fix

                              File pages.js has 268 lines of code (exceeds 250 allowed). Consider refactoring.
                              Open

                              const models = require('../../models');
                              const tpl = require('@tryghost/tpl');
                              const errors = require('@tryghost/errors');
                              const getPostServiceInstance = require('../../services/posts/posts-service');
                              const ALLOWED_INCLUDES = ['tags', 'authors', 'authors.roles', 'tiers', 'count.signups', 'count.paid_conversions', 'post_revisions', 'post_revisions.author'];
                              Severity: Minor
                              Found in ghost/core/core/server/api/endpoints/pages.js - About 2 hrs to fix

                                Function chartData has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    get chartData() {
                                        const totalCadence = this.dashboardStats.paidMembersByCadence.month + this.dashboardStats.paidMembersByCadence.year;
                                        const monthlyPercentage = Math.round(this.dashboardStats.paidMembersByCadence.month / totalCadence * 100);
                                        const annualPercentage = Math.round(this.dashboardStats.paidMembersByCadence.year / totalCadence * 100);
                                        const barThickness = 5;
                                Severity: Minor
                                Found in ghost/admin/app/components/dashboard/charts/paid-mix.js - 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 populateProductsAndPrices has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    async populateProductsAndPrices(options) {
                                        if (!options) {
                                            return this.models.Product.transaction((transacting) => {
                                                return this.populateProductsAndPrices({transacting});
                                            });
                                Severity: Minor
                                Found in ghost/stripe/lib/StripeMigrations.js - 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 handleSetupEvent has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    async handleSetupEvent(session) {
                                        const setupIntent = await this.api.getSetupIntent(session.setup_intent);
                                
                                        const memberRepository = this.deps.memberRepository;
                                        const member = await memberRepository.get({
                                Severity: Minor
                                Found in ghost/stripe/lib/services/webhook/CheckoutSessionEventService.js - 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 getCustomerIdByEmail has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    async getCustomerIdByEmail(email) {
                                        await this._searchRateLimitBucket.throttle();
                                        try {
                                            const result = await this._stripe.customers.search({
                                                query: `email:"${email}"`,
                                Severity: Minor
                                Found in ghost/stripe/lib/StripeAPI.js - 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 createCheckoutSession has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
                                Open

                                    async createCheckoutSession(req, res) {
                                        const type = req.body.type ?? 'subscription';
                                        const metadata = req.body.metadata ?? {};
                                        const identity = req.body.identity;
                                        const membersEnabled = true;
                                Severity: Minor
                                Found in ghost/members-api/lib/controllers/RouterController.js - 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

                                Severity
                                Category
                                Status
                                Source
                                Language