TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function add has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    add(apiConfig, frame, options = {add: true}) {
        debug('add');

        if (_.get(frame,'options.source')) {
            const html = frame.data.pages[0].html;
Severity: Minor
Found in ghost/core/core/server/api/endpoints/utils/serializers/input/pages.js - About 3 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 beforeImport has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    beforeImport() {
        debug('beforeImport');

        const activeTheme = _.find(this.dataToImport, {key: 'active_theme'});

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

const RecommendationItem = (recommendation) => {
    const {t, onAction, member, site} = useContext(AppContext);
    const {title, url, description, favicon, one_click_subscribe: oneClickSubscribe, featured_image: featuredImage} = recommendation;
    const allowOneClickSubscribe = member && oneClickSubscribe;
    const [subscribed, setSubscribed] = useState(false);
Severity: Minor
Found in apps/portal/src/components/pages/RecommendationsPage.js - About 3 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 NewsletterPreviewContent has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

}> = ({
    senderName,
    senderEmail,
    senderReplyTo,
    headerImage,

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

        permissible: function permissible(postModelOrId, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission) {
            const self = this;
            const postModel = postModelOrId;
            let origArgs;
            let isContributor;
Severity: Major
Found in ghost/core/core/server/models/relations/authors.js - About 3 hrs to fix

    Function AboutModal has 85 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const AboutModal = NiceModal.create<RoutingModalProps>(({}) => {
        const {updateRoute} = useRouting();
        const globalData = useGlobalData();
        let config = globalData.config;
        const upgradeStatus = useUpgradeStatus();
    Severity: Major
    Found in apps/admin-x-settings/src/components/settings/general/About.tsx - About 3 hrs to fix

      Function getAction has 83 lines of code (exceeds 25 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: Major
      Found in ghost/admin/app/helpers/parse-member-event.js - About 3 hrs to fix

        Function mockPosts has 82 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 3 hrs to fix

          Function onTitleKeydown has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              @action
              onTitleKeydown(event) {
                  if (this.feature.editorExcerpt) {
                      // move cursor to the excerpt on
                      // - Tab (handled by browser)
          Severity: Minor
          Found in ghost/admin/app/components/gh-koenig-editor-lexical.js - About 3 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 handleSubscriptionEvent has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              async handleSubscriptionEvent(session) {
                  const customer = await this.api.getCustomer(session.customer, {
                      expand: ['subscriptions.data.default_payment_method']
                  });
          
          
          Severity: Minor
          Found in ghost/stripe/lib/services/webhook/CheckoutSessionEventService.js - About 3 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 setResponseContext has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

          function setResponseContext(req, res, data) {
              const pageParam = req.params && req.params.page !== undefined ? parseInt(req.params.page, 10) : 1;
          
              res.locals = res.locals || {};
              res.locals.context = [];
          Severity: Minor
          Found in ghost/core/core/frontend/services/rendering/context.js - About 3 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 unsubscribeController has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

          module.exports = async function unsubscribeController(req, res) {
              debug('unsubscribeController');
          
              const {query} = url.parse(req.url, true);
          
          
          Severity: Minor
          Found in ghost/core/core/frontend/services/routing/controllers/unsubscribe.js - About 3 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 fetchOembedDataFromUrl has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

              async fetchOembedDataFromUrl(url, type, options = {}) {
                  try {
                      const urlObject = new URL(url);
          
                      // YouTube has started not returning oembed <link>tags for some live URLs
          Severity: Minor
          Found in ghost/oembed-service/lib/OEmbedService.js - About 3 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 UnsubscribePage has a Cognitive Complexity of 23 (exceeds 5 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: Minor
          Found in apps/portal/src/components/pages/UnsubscribePage.js - About 3 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 Sidebar has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
          Open

                  validate: () => void}> = ({clearError, errors, offer, updateOffer}) => {
                      const {siteData} = useGlobalData();
                      const [isCopied, setIsCopied] = useState(false);
                      const handleError = useHandleError();
                      const {mutateAsync: editOffer} = useEditOffer();

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

          import AppContext from '../../AppContext';
          import {useContext, useState, useEffect, useCallback, useMemo} from 'react';
          import CloseButton from '../common/CloseButton';
          import {clearURLParams} from '../../utils/notifications';
          import LoadingPage from './LoadingPage';
          Severity: Minor
          Found in apps/portal/src/components/pages/RecommendationsPage.js - About 3 hrs to fix

            Function replaceIdentifiers has 81 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                replaceIdentifiers() {
                    const ownerUserId = _.find(this.requiredExistingData.users, (user) => {
                        if (user.roles[0].name === 'Owner') {
                            return true;
                        }
            Severity: Major
            Found in ghost/core/core/server/data/importer/importers/data/Base.js - About 3 hrs to fix

              Function foreach has 80 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              module.exports = function foreach(items, options) {
                  if (!options) {
                      logging.warn(tpl(messages.iteratorNeeded));
                  }
              
              
              Severity: Major
              Found in ghost/core/core/frontend/helpers/foreach.js - About 3 hrs to fix

                Function EmailReceivingPage has 80 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export default function EmailReceivingPage() {
                    const {brandColor, onAction, site, lastPage, member, t, pageData} = useContext(AppContext);
                
                    const supportAddressEmail = getSupportAddress({site});
                    const supportAddress = `mailto:${supportAddressEmail}`;
                Severity: Major
                Found in apps/portal/src/components/pages/EmailReceivingFAQ.js - About 3 hrs to fix

                  Function render has 80 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      render() {
                          const {page, pageQuery, site, customSiteUrl} = this.context;
                          const products = getSiteProducts({site});
                          const noOfProducts = products.length;
                  
                  
                  Severity: Major
                  Found in apps/portal/src/components/PopupModal.js - About 3 hrs to fix
                    Severity
                    Category
                    Status
                    Source
                    Language