TryGhost/Ghost

View on GitHub

Showing 1,756 of 3,886 total issues

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

    async function up(knex) {
        logging.info('Populating members_paid_subscription_events from members_stripe_customers_subscriptions');
        const allSubscriptions = await knex
            .select(
                'c.member_id',

    Function getPageFromLinkPath has 93 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        getPageFromLinkPath(path, useSite) {
            const customPricesSignupRegex = /^signup\/?(?:\/(\w+?))?\/?$/;
            const customMonthlyProductSignup = /^signup\/?(?:\/(\w+?))\/monthly\/?$/;
            const customYearlyProductSignup = /^signup\/?(?:\/(\w+?))\/yearly\/?$/;
            const customOfferRegex = /^offers\/(\w+?)\/?$/;
    Severity: Major
    Found in apps/portal/src/App.js - About 3 hrs to fix

      Function fetchQueryStrData has 93 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          fetchQueryStrData(qs = '') {
              const qsParams = new URLSearchParams(qs);
              const data = {
                  site: {
                      plans: {}
      Severity: Major
      Found in apps/portal/src/App.js - About 3 hrs to fix

        Function draw has 92 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            draw: function () {
                var ctx = this._chart.ctx;
                var vm = this._view;
                var left, right, top, bottom, borderSkipped, radius;
        
        
        Severity: Major
        Found in ghost/admin/app/components/dashboard/charts/paid-breakdown.js - About 3 hrs to fix

          File test-fixtures.js has 320 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          /* eslint-disable no-unused-vars*/
          import {getFreeProduct, getMemberData, getOfferData, getPriceData, getProductData, getSiteData, getSubscriptionData, getNewsletterData} from './fixtures-generator';
          
          export const transformTierFixture = [
              getFreeProduct({
          Severity: Minor
          Found in apps/portal/src/utils/test-fixtures.js - About 3 hrs to fix

            Consider simplifying this complex logical expression.
            Open

                        if (!member) {
                            const metadataName = _.get(session, 'metadata.name');
                            const metadataNewsletters = _.get(session, 'metadata.newsletters');
                            const attribution = {
                                id: session.metadata.attribution_id ?? null,
            Severity: Critical
            Found in ghost/stripe/lib/WebhookController.js - About 3 hrs to fix

              File import-manager.js has 319 lines of code (exceeds 250 allowed). Consider refactoring.
              Open

              const _ = require('lodash');
              const fs = require('fs-extra');
              const path = require('path');
              const os = require('os');
              const glob = require('glob');
              Severity: Minor
              Found in ghost/core/core/server/data/importer/import-manager.js - About 3 hrs to fix

                Function sendMagicLink has 91 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    async sendMagicLink(req, res) {
                        const {email, autoRedirect} = req.body;
                        let {emailType, redirect} = req.body;
                
                        let referer = req.get('referer');
                Severity: Major
                Found in ghost/members-api/lib/controllers/RouterController.js - About 3 hrs to fix

                  Function renderForm has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      renderForm() {
                          const fields = this.getInputFields({state: this.state});
                          const {site, pageQuery, t} = this.context;
                  
                          if (this.state.showNewsletterSelection) {
                  Severity: Major
                  Found in apps/portal/src/components/pages/SignupPage.js - About 3 hrs to fix

                    Function Connect has 90 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    const Connect: React.FC = () => {
                        const [submitEnabled, setSubmitEnabled] = useState(false);
                        const [token, setToken] = useState('');
                        const [testMode, setTestMode] = useState(false);
                        const [error, setError] = useState('');

                      Function getIcon has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                          getIcon(event) {
                              let icon;
                      
                              if (event.type === 'login_event') {
                                  icon = 'logged-in';
                      Severity: Minor
                      Found in ghost/admin/app/helpers/parse-member-event.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 willTransition has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                          @action
                          willTransition(transition) {
                              let isExploreTransition = false;
                      
                              if (transition) {
                      Severity: Minor
                      Found in ghost/admin/app/routes/explore/index.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 generatePassword has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                      export default function generatePassword(length, memorable, pattern, prefix) {
                          var char = '', n, i, validChars = [];
                          if (length === null || typeof (length) === 'undefined') {
                              length = 10;
                          }
                      Severity: Minor
                      Found in ghost/admin/app/utils/password-generator.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 chartOptions has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                          get chartOptions() {
                              const that = this;
                              let activeDays = this.dashboardStats.chartDays;
                              let barColor = this.feature.nightShift ? 'rgba(200, 204, 217, 0.25)' : 'rgba(200, 204, 217, 0.65)';
                      
                      
                      Severity: Minor
                      Found in ghost/admin/app/components/dashboard/charts/anchor-attribution.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 getAdapter has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                          getAdapter(adapterName, adapterClassName, config) {
                              if (!adapterName || !adapterClassName) {
                                  throw new errors.IncorrectUsageError({
                                      message: 'getAdapter must be called with a adapterName and a adapterClassName.'
                                  });
                      Severity: Minor
                      Found in ghost/adapter-manager/lib/AdapterManager.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 replace has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
                      Open

                          async replace(html, replaceLink, options = {}) {
                              const {tokenize} = require('html5parser');
                              const entities = require('entities');
                      
                              try {
                      Severity: Minor
                      Found in ghost/link-replacer/lib/link-replacer.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 http has 89 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                      const http = (apiImpl) => {
                          /**
                           * @param {import('express').Request} req - Express request object.
                           * @param {import('express').Response} res - Express response object.
                           * @param {import('express').NextFunction} next - Express next function.
                      Severity: Major
                      Found in ghost/api-framework/lib/http.js - About 3 hrs to fix

                        Function forceStripeSubscriptionToProduct has 89 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            async forceStripeSubscriptionToProduct(data, options) {
                                if (!this._stripeAPIService.configured) {
                                    throw new DataImportError({
                                        message: tpl(messages.noStripeConnection, {action: 'force subscription to product'})
                                    });
                        Severity: Major
                        Found in ghost/members-importer/lib/MembersCSVImporterStripeUtils.js - About 3 hrs to fix

                          File MemberBREADService.js has 315 lines of code (exceeds 250 allowed). Consider refactoring.
                          Open

                          const errors = require('@tryghost/errors');
                          const logging = require('@tryghost/logging');
                          const tpl = require('@tryghost/tpl');
                          const moment = require('moment');
                          
                          
                          Severity: Minor
                          Found in ghost/members-api/lib/services/MemberBREADService.js - About 3 hrs to fix

                            Function chartData has 88 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                get chartData() {
                                    const totalCadence = this.dashboardStats.paidMembersByCadence.month + this.dashboardStats.paidMembersByCadence.year;
                                    const monthlyPercentage = Math.round(this.dashboardStats.paidMembersByCadence.month / totalCadence * 100);
                                    const annualPercentage = Math.round(this.dashboardStats.paidMembersByCadence.year / totalCadence * 100);
                                    const barThickness = 5;
                            Severity: Major
                            Found in ghost/admin/app/components/dashboard/charts/paid-mix.js - About 3 hrs to fix
                              Severity
                              Category
                              Status
                              Source
                              Language