TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

File api.js has 544 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

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

    import setupGhostApi from './utils/api';
    import {chooseBestErrorMessage} 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

      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

        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 CollectionsService.ts has 516 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import logging from '@tryghost/logging';
          import tpl from '@tryghost/tpl';
          import isEqual from 'lodash/isEqual';
          import {Knex} from 'knex';
          import {
          Severity: Major
          Found in ghost/collections/src/CollectionsService.ts - About 1 day to fix

            Function update has 209 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                async update(data, options) {
                    const sharedOptions = {
                        transacting: options.transacting
                    };
            
            
            Severity: Major
            Found in ghost/members-api/lib/repositories/MemberRepository.js - About 1 day to fix

              Function draw has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
              Open

              Chart.elements.Rectangle.prototype.draw = function () {
                  var ctx = this._chart.ctx;
                  var vm = this._view;
                  var left, right, top, bottom, borderSkipped, radius;
              
              
              Severity: Minor
              Found in ghost/admin/app/components/dashboard/charts/paid-mix.js - About 7 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 handleVideoPlayer has 197 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  const handleVideoPlayer = function (videoElementContainer) {
                      const videoPlayer = videoElementContainer.querySelector('.kg-video-player');
                      const videoPlayerContainer = videoElementContainer.querySelector('.kg-video-player-container');
                      const playIconContainer = videoElementContainer.querySelector('.kg-video-play-icon');
                      const pauseIconContainer = videoElementContainer.querySelector('.kg-video-pause-icon');
              Severity: Major
              Found in ghost/core/core/frontend/src/cards/js/video.js - About 7 hrs to fix

                Function UnsubscribePage has 197 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export default function UnsubscribePage() {
                    const {site, api, pageData, member: loggedInMember, onAction, t} = useContext(AppContext);
                    // member is the member data fetched from the API based on the uuid and its state is limited to just this modal, not all of Portal
                    const [member, setMember] = useState();
                    const [loading, setLoading] = useState(true);
                Severity: Major
                Found in apps/portal/src/components/pages/UnsubscribePage.js - About 7 hrs to fix

                  Function InviteUserModal has 194 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const InviteUserModal = NiceModal.create(() => {
                      const modal = NiceModal.useModal();
                      const rolesQuery = useBrowseRoles();
                      const assignableRolesQuery = useBrowseRoles({
                          searchParams: {limit: 'all', permissions: 'assign'}

                    Function milestoneEmailConfig has 192 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const milestoneEmailConfig = (siteTitle, formattedValue) => {
                        const arrContent = {
                            subject: `${siteTitle} hit ${formattedValue} ARR`,
                            heading: `Congrats! You reached ${formattedValue} ARR`,
                            content: [
                    Severity: Major
                    Found in ghost/staff-service/lib/milestone-email-config.js - About 7 hrs to fix

                      File ProductRepository.js has 486 lines of code (exceeds 250 allowed). Consider refactoring.
                      Open

                      const {UpdateCollisionError, NotFoundError, MethodNotAllowedError, ValidationError, BadRequestError} = require('@tryghost/errors');
                      const tpl = require('@tryghost/tpl');
                      
                      const messages = {
                          priceMustBeInteger: 'Tier prices must be an integer.',
                      Severity: Minor
                      Found in ghost/members-api/lib/repositories/ProductRepository.js - About 7 hrs to fix

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

                        // NOTE: We must not cache references to membersService.api
                        // as it is a getter and may change during runtime.
                        const moment = require('moment-timezone');
                        const errors = require('@tryghost/errors');
                        const logging = require('@tryghost/logging');
                        Severity: Minor
                        Found in ghost/core/core/server/api/endpoints/members.js - About 7 hrs to fix

                          File gh-post-settings-menu.js has 472 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          import Component from '@ember/component';
                          import boundOneWay from 'ghost-admin/utils/bound-one-way';
                          import classic from 'ember-classic-decorator';
                          import moment from 'moment-timezone';
                          import {action, computed} from '@ember/object';
                          Severity: Minor
                          Found in ghost/admin/app/components/gh-post-settings-menu.js - About 7 hrs to fix

                            Function OffersIndexModal has 182 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            export const OffersIndexModal = () => {
                                const modal = useModal();
                                const {updateRoute} = useRouting();
                                const {data: {offers: allOffers = []} = {}, isFetching: isFetchingOffers} = useBrowseOffers({
                                    searchParams: {

                              Function exports has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring.
                              Open

                              module.exports = async (model, frame, options = {}) => {
                                  const {tiers: tiersData} = options || {};
                              
                                  // NOTE: `model` is now overloaded and may be a bookshelf model or a POJO
                                  let jsonModel = model;

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

                              // @ts-ignore
                              const {VersionMismatchError} = require('@tryghost/errors');
                              // @ts-ignore
                              const debug = require('@tryghost/debug')('stripe');
                              const Stripe = require('stripe').Stripe;
                              Severity: Minor
                              Found in ghost/stripe/lib/StripeAPI.js - About 7 hrs to fix

                                Function exports has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
                                Open

                                module.exports = function (Bookshelf) {
                                    const insertAction = (data, options) => {
                                        // CASE: model does not support action for target event
                                        if (!data) {
                                            return;
                                Severity: Minor
                                Found in ghost/core/core/server/models/base/plugins/actions.js - About 7 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 AddDetailsPopup has 177 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                const AddDetailsPopup = (props: Props) => {
                                    const inputNameRef = useRef<HTMLInputElement>(null);
                                    const inputExpertiseRef = useRef<HTMLInputElement>(null);
                                    const {dispatchAction, member, accentColor, t} = useAppContext();
                                
                                
                                Severity: Major
                                Found in apps/comments-ui/src/components/popups/AddDetailsPopup.tsx - About 7 hrs to fix

                                  File RouterController.js has 461 lines of code (exceeds 250 allowed). Consider refactoring.
                                  Open

                                  const tpl = require('@tryghost/tpl');
                                  const logging = require('@tryghost/logging');
                                  const _ = require('lodash');
                                  const {BadRequestError, NoPermissionError, UnauthorizedError, DisabledFeatureError} = require('@tryghost/errors');
                                  const errors = require('@tryghost/errors');
                                  Severity: Minor
                                  Found in ghost/members-api/lib/controllers/RouterController.js - About 7 hrs to fix
                                    Severity
                                    Category
                                    Status
                                    Source
                                    Language