TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

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

const AmpModal = NiceModal.create(() => {
    const {updateRoute} = useRouting();
    const {settings} = useGlobalData();
    const [ampEnabled] = getSettingValues<boolean>(settings, ['amp']);
    const [ampId] = getSettingValues<string>(settings, ['amp_gtag_id']);

    File FeedbackPage.js has 299 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import {useContext, useEffect, useState} from 'react';
    import AppContext from '../../AppContext';
    import {ReactComponent as ThumbDownIcon} from '../../images/icons/thumbs-down.svg';
    import {ReactComponent as ThumbUpIcon} from '../../images/icons/thumbs-up.svg';
    import {ReactComponent as ThumbErrorIcon} from '../../images/icons/thumbs-error.svg';
    Severity: Minor
    Found in apps/portal/src/components/pages/FeedbackPage.js - About 3 hrs to fix

      Function up has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          async function up(knex) {
              logging.info('Adjusting MRR based on Offer Redemptions');
              const offerRedemptions = await knex
                  .select('or.*', 'o.discount_type', 'o.discount_amount', 'o.interval AS discount_interval', 's.mrr AS mrr', 's.id AS subscription_id', 'p.amount AS amount', 'p.interval AS interval')
                  .from('offer_redemptions AS or')

        Function create has 78 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            static async create(data, uniqueChecker) {
                let isNew = false;
                let id;
        
                if (data.id instanceof ObjectID) {
        Severity: Major
        Found in ghost/offers/lib/domain/models/Offer.js - About 3 hrs to fix

          Function validateSchema has 78 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function validateSchema(tableName, model, options) {
              options = options || {};
          
              const columns = _.keys(schema[tableName]);
              let validationErrors = [];
          Severity: Major
          Found in ghost/core/core/server/data/schema/validator.js - About 3 hrs to fix

            Function setupMembersApp has 78 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            module.exports = function setupMembersApp() {
                debug('Members App setup start');
                const membersApp = express('members');
            
                // Members API shouldn't be cached
            Severity: Major
            Found in ghost/core/core/server/web/members/app.js - About 3 hrs to fix

              Function generateMonochromePalette has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

              export function generateMonochromePalette(baseColor, count = 10) {
                  // Convert hex to RGB
                  let r = parseInt(baseColor.slice(1, 3), 16);
                  let g = parseInt(baseColor.slice(3, 5), 16);
                  let b = parseInt(baseColor.slice(5, 7), 16);
              Severity: Minor
              Found in ghost/admin/app/utils/stats.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 updateSubscription has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

                  async updateSubscription(req, res) {
                      try {
                          const identity = req.body.identity;
                          const subscriptionId = req.params.id;
                          const cancelAtPeriodEnd = req.body.cancel_at_period_end;
              Severity: Minor
              Found in ghost/members-api/lib/controllers/MemberController.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 all has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

                  all(_apiConfig, frame) {
                      if (frame.options.filter) {
                          try {
                              frame.options.filter = nql.parse(frame.options.filter);
                          } catch (err) {
              Severity: Minor
              Found in ghost/core/core/server/api/endpoints/utils/serializers/input/tiers.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 chooseBestErrorMessage has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

              export function chooseBestErrorMessage(error, alreadyTranslatedDefaultMessage, t) {
                  // helper functions
                  const translateMessage = (message, number = null) => {
                      if (number) {
                          return t(message, {number});
              Severity: Minor
              Found in apps/portal/src/utils/errors.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 NewsletterPreview has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
              Open

              const NewsletterPreview: React.FC<{newsletter: Newsletter}> = ({newsletter}) => {
                  const hasEmailCustomization = useFeatureFlag('emailCustomization');
                  const {currentUser, settings, siteData, config} = useGlobalData();
                  const [title, icon, commentsEnabled, supportEmailAddress, defaultEmailAddress] = getSettingValues<string>(settings, ['title', 'icon', 'comments_enabled', 'support_email_address', 'default_email_address']);
              
              

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

                  async handleSubscriptionEvent(session) {
                      const customer = await this.api.getCustomer(session.customer, {
                          expand: ['subscriptions.data.default_payment_method']
                      });
              
              
              Severity: Major
              Found in ghost/stripe/lib/services/webhook/CheckoutSessionEventService.js - About 3 hrs to fix

                Function RecommendationItem has 77 lines of code (exceeds 25 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: Major
                Found in apps/portal/src/components/pages/RecommendationsPage.js - About 3 hrs to fix

                  File api.ts has 294 lines of code (exceeds 250 allowed). Consider refactoring.
                  Open

                  import {AddComment, Comment, LabsContextType} from '../AppContext';
                  
                  function setupGhostApi({siteUrl = window.location.origin, apiUrl, apiKey}: {siteUrl: string, apiUrl: string, apiKey: string}) {
                      const apiPath = 'members/api';
                  
                  
                  Severity: Minor
                  Found in apps/comments-ui/src/utils/api.ts - About 3 hrs to fix

                    File GlobalSettings.tsx has 291 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    import BehindFeatureFlag from '../../../BehindFeatureFlag';
                    import React, {useState} from 'react';
                    import UnsplashSelector from '../../../selectors/UnsplashSelector';
                    import clsx from 'clsx';
                    import usePinturaEditor from '../../../../hooks/usePinturaEditor';

                      Function edit has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          edit(apiConfig, frame) {
                              const errors = [];
                      
                              _.each(frame.data.settings, (setting) => {
                                  // TODO: the below array is INCOMPLETE

                        Function validateCollections has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                        _private.validateCollections = function validateCollections(collections) {
                            if (collections.constructor !== Object) {
                                throw new errors.ValidationError({
                                    message: tpl(messages.validationError, {
                                        at: collections,
                        Severity: Major
                        Found in ghost/core/core/server/services/route-settings/validate.js - About 2 hrs to fix

                          Function testRoutes has 74 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                          module.exports = function testRoutes() {
                              const router = express.Router('testmode');
                          
                              router.get('/500', (req, res) => res.sendStatus(500));
                              router.get('/400', (req, res) => res.sendStatus(400));
                          Severity: Major
                          Found in ghost/core/core/server/web/api/testmode/routes.js - About 2 hrs to fix

                            Function add has 73 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                add({api, InviteModel, invites, options, user}) {
                                    let invite;
                                    let emailData;
                            
                                    return InviteModel.findOne({email: invites[0].email}, options)
                            Severity: Major
                            Found in ghost/core/core/server/services/invites/Invites.js - About 2 hrs to fix

                              Function init has 73 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  async init() {
                                      if (this.didInit) {
                                          return;
                                      }
                                      this.didInit = true;
                              Severity: Major
                              Found in ghost/core/core/server/services/mentions/service.js - About 2 hrs to fix
                                Severity
                                Category
                                Status
                                Source
                                Language