TryGhost/Ghost

View on GitHub

Showing 1,747 of 3,879 total issues

File StripeAPI.js has 447 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 6 hrs to fix

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

    module.exports = function (Bookshelf) {
        Bookshelf.Model = Bookshelf.Model.extend({
            initializeEvents: function () {
                // NOTE: triggered before `creating`/`updating`
                this.on('saving', function onSaving(newObj, attrs, options) {
    Severity: Major
    Found in ghost/core/core/server/models/base/plugins/events.js - About 6 hrs to fix

      File helpers.test.js has 445 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import {getAllProductsForSite, getAvailableProducts, getCurrencySymbol, getFreeProduct, getMemberName, getMemberSubscription, getPriceFromSubscription, getPriceIdFromPageQuery, getSupportAddress, getDefaultNewsletterSender, getUrlHistory, hasMultipleProducts, isActiveOffer, isInviteOnlySite, isPaidMember, isSameCurrency, transformApiTiersData, isSigninAllowed, isSignupAllowed, getCompExpiry, isInThePast} from './helpers';
      import * as Fixtures from './fixtures-generator';
      import {site as FixturesSite, member as FixtureMember, offer as FixtureOffer, transformTierFixture as TransformFixtureTiers} from '../utils/test-fixtures';
      import {isComplimentaryMember} from '../utils/helpers';
      
      
      Severity: Minor
      Found in apps/portal/src/utils/helpers.test.js - About 6 hrs to fix

        File UserDetailModal.tsx has 445 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import ChangePasswordForm from './users/ChangePasswordForm';
        import EmailNotifications from './users/EmailNotifications';
        import NiceModal, {useModal} from '@ebay/nice-modal-react';
        import ProfileBasics from './users/ProfileBasics';
        import ProfileDetails from './users/ProfileDetails';

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

          module.exports = function (Bookshelf) {
              Bookshelf.Model = Bookshelf.Model.extend({}, {
                  /**
                   * ### Generate Slug
                   * Create a string to act as the permalink for an object.
          Severity: Minor
          Found in ghost/core/core/server/models/base/plugins/generate-slug.js - About 6 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 forPost has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports.forPost = (options, model, attrs) => {
              const _ = require('lodash');
              // This function is split up in 3 conditions for 3 different purposes:
              // 1. Gets excerpt from post's plaintext. If custom_excerpt exists, it overrides the excerpt but the key remains excerpt.
              if (Object.prototype.hasOwnProperty.call(options, 'columns') || _.includes(options.columns, 'excerpt') || _.includes(options.columns, 'excerpt') && options.formats && options.formats.includes('plaintext')) {

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

          function createApiInstance(config) {
              const membersApiInstance = MembersApi({
                  tokenConfig: config.getTokenConfig(),
                  auth: {
                      getSigninURL: config.getSigninURL.bind(config),
          Severity: Major
          Found in ghost/core/core/server/services/members/api.js - About 6 hrs to fix

            File AccountPlanPage.js has 435 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            import React, {useContext, useState} from 'react';
            import AppContext from '../../AppContext';
            import ActionButton from '../common/ActionButton';
            import CloseButton from '../common/CloseButton';
            import BackButton from '../common/BackButton';
            Severity: Minor
            Found in apps/portal/src/components/pages/AccountPlanPage.js - About 6 hrs to fix

              Function Sidebar has 161 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const Sidebar: React.FC = () => {
                  const {filter, setFilter, checkVisible, noResult, setNoResult} = useSearch();
                  const {updateRoute} = useRouting();
                  const searchInputRef = useRef<HTMLInputElement | null>(null);
                  const {isAnyTextFieldFocused} = useFocusContext();
              Severity: Major
              Found in apps/admin-x-settings/src/components/Sidebar.tsx - About 6 hrs to fix

                Function generate has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
                Open

                    generate() {
                        this.count += 1;
                
                        const member = this.model;
                        const customer = this.membersStripeCustomers.get(this.model.id);

                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

                Consider simplifying this complex logical expression.
                Open

                    if (!unstyled) {
                        className = clsx(
                            'inline-flex items-center justify-center whitespace-nowrap rounded text-sm transition',
                            ((link && color !== 'clear' && color !== 'black') || (!link && color !== 'clear')) ? 'font-bold' : 'font-semibold',
                            !link ? `${size === 'sm' ? 'h-7' : 'h-[34px]'}` : '',
                Severity: Critical
                Found in apps/admin-x-design-system/src/global/Button.tsx - About 6 hrs to fix

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

                  module.exports = function (defaults) {
                      let app = new EmberApp(defaults, {
                          addons: {denylist},
                          babel: {
                              plugins: [
                  Severity: Major
                  Found in ghost/admin/ember-cli-build.js - About 6 hrs to fix

                    Function replaceIdentifiers has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                        replaceIdentifiers() {
                            const ownerUserId = _.find(this.requiredExistingData.users, (user) => {
                                if (user.roles[0].name === 'Owner') {
                                    return true;
                                }
                    Severity: Minor
                    Found in ghost/core/core/server/data/importer/importers/data/Base.js - About 6 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 PaidAccountActions has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const PaidAccountActions = () => {
                        const {member, site, onAction, t} = useContext(AppContext);
                    
                        const onEditBilling = () => {
                            const subscription = getMemberSubscription({member});

                    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 ChangePasswordForm has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const ChangePasswordForm: React.FC<{user: User}> = ({user}) => {
                        const {currentUser, config, siteData} = useGlobalData();
                        const [editPassword, setEditPassword] = useState(false);
                        const [oldPassword, setOldPassword] = useState('');
                        const [newPassword, setNewPassword] = useState('');

                    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 AddOfferModal has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const AddOfferModal = () => {
                        const {siteData} = useGlobalData();
                        const typeOptions = [
                            {title: 'Discount', description: 'Offer a special reduced price', value: 'percent'},
                            {title: 'Free trial', description: 'Give free access for a limited time', value: 'trial'}

                    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 SettingGroup has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
                    Open

                    const SettingGroup = forwardRef<HTMLDivElement, SettingGroupProps>(function SettingGroup({
                        navid,
                        testId,
                        title,
                        description,
                    Severity: Minor
                    Found in apps/admin-x-design-system/src/settings/SettingGroup.tsx - About 6 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 RouterController.js has 425 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 6 hrs to fix

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

                      module.exports = function (Bookshelf) {
                          Bookshelf.Model = Bookshelf.Model.extend({}, {
                              /**
                               * If you want to fetch all data fast, i recommend using this function.
                               * Bookshelf is just too slow, too much ORM overhead.
                      Severity: Major
                      Found in ghost/core/core/server/models/base/plugins/raw-knex.js - About 6 hrs to fix

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

                        module.exports = createIrreversibleMigration(async (knex) => {
                            logging.info('Transforming all internal urls to transform-ready');
                        
                            await knex.transaction(async (trx) => {
                                // posts and posts_meta
                          Severity
                          Category
                          Status
                          Source
                          Language