TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

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 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

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

      File boot.js has 422 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      // The Ghost Boot Sequence
      // -----------------------
      // - This is intentionally one big file at the moment, so that we don't have to follow boot logic all over the place
      // - This file is FULL of debug statements so we can see timings for the various steps because the boot needs to be as fast as possible
      // - As we manage to break the codebase down into distinct components for e.g. the frontend, their boot logic can be offloaded to them
      Severity: Minor
      Found in ghost/core/core/boot.js - About 6 hrs to fix

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

        module.exports = function (Bookshelf) {
            Bookshelf.Model = Bookshelf.Model.extend({
                // When loading an instance, subclasses can specify default to fetch
                defaultColumnsToFetch: function defaultColumnsToFetch() {
                    return [];
        Severity: Major
        Found in ghost/core/core/server/models/base/plugins/crud.js - About 6 hrs to fix

          Function getAction has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
          Open

              getAction(event, hasMultipleNewsletters) {
                  if (event.type === 'signup_event' || (event.type === 'subscription_event' && event.data.type === 'created' && event.data.signup)) {
                      return 'signed up';
                  }
          
          
          Severity: Minor
          Found in ghost/admin/app/helpers/parse-member-event.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 OffersIndexModal has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
          Open

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

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

          /* globals Chart */
          
          import Component from '@glimmer/component';
          import {action} from '@ember/object';
          import {inject as service} from '@ember/service';
          Severity: Minor
          Found in ghost/admin/app/components/dashboard/charts/paid-mix.js - About 5 hrs to fix

            Function fetchAll has 148 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                        fetchAll: function (options) {
                            options = options || {};
            
                            const nql = require('@tryghost/nql');
                            const modelName = options.modelName;
            Severity: Major
            Found in ghost/core/core/server/models/base/plugins/raw-knex.js - About 5 hrs to fix

              Function DesignModal has 148 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              const DesignModal: React.FC = () => {
                  const {settings, siteData} = useGlobalData();
                  const {mutateAsync: editSettings} = useEditSettings();
                  const {data: {posts: [latestPost]} = {posts: []}} = useBrowsePosts({
                      searchParams: {
              Severity: Major
              Found in apps/admin-x-settings/src/components/settings/site/DesignModal.tsx - About 5 hrs to fix

                Function validateSchema has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
                Open

                function validateSchema(tableName, model, options) {
                    options = options || {};
                
                    const columns = _.keys(schema[tableName]);
                    let validationErrors = [];
                Severity: Minor
                Found in ghost/core/core/server/data/schema/validator.js - About 5 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 fetchLinkData has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
                Open

                    fetchLinkData(site, member) {
                        const qParams = new URLSearchParams(window.location.search);
                        if (qParams.get('action') === 'unsubscribe') {
                            // if the user is unsubscribing from a newsletter with an old unsubscribe link that we can't validate, push them to newsletter mgmt where they have to log in
                            if (qParams.get('key') && qParams.get('uuid')) {
                Severity: Minor
                Found in apps/portal/src/App.js - About 5 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 147 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

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

                  Function PortalModal has 147 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  const PortalModal: React.FC = () => {
                      const {updateRoute} = useRouting();
                  
                      const [selectedPreviewTab, setSelectedPreviewTab] = useState('signup');
                  
                  

                    File StaffServiceEmails.js has 410 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    const {promises: fs, readFileSync} = require('fs');
                    const path = require('path');
                    const moment = require('moment');
                    const glob = require('glob');
                    const {EmailAddressParser} = require('@tryghost/email-addresses');
                    Severity: Minor
                    Found in ghost/staff-service/lib/StaffServiceEmails.js - About 5 hrs to fix

                      Function Sidebar has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
                      Open

                      }> = ({newsletter, onlyOne, updateNewsletter, validate, errors, clearError}) => {
                          const {updateRoute} = useRouting();
                          const {mutateAsync: editNewsletter} = useEditNewsletter();
                          const limiter = useLimiter();
                          const {settings, siteData, config} = useGlobalData();

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

                      const PinturaModal = NiceModal.create(() => {
                          const {updateRoute} = useRouting();
                          const [uploadingState, setUploadingState] = useState({
                              js: false,
                              css: false

                        Function MembersAPI has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
                        Open

                        module.exports = function MembersAPI({
                            tokenConfig: {
                                issuer,
                                privateKey,
                                publicKey
                        Severity: Minor
                        Found in ghost/members-api/lib/members-api.js - About 5 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 prepAttrsForEmailVerification has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
                        Open

                            async prepAttrsForEmailVerification(attrs, newsletter) {
                                const cleanedAttrs = _.cloneDeep(attrs);
                                const emailsToVerify = [];
                                const emailProperties = [
                                    {property: 'sender_email', type: 'from', emptyable: true, error: messages.senderEmailNotAllowed}
                        Severity: Minor
                        Found in ghost/core/core/server/services/newsletters/NewslettersService.js - About 5 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