TryGhost/Ghost

View on GitHub

Showing 1,756 of 3,886 total issues

File SettingsBREADService.js has 285 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const _ = require('lodash');
const tpl = require('@tryghost/tpl');
const {NotFoundError, NoPermissionError, BadRequestError, IncorrectUsageError, ValidationError} = require('@tryghost/errors');
const {obfuscatedSetting, isSecretSetting, hideValueIfSecret} = require('./settings-utils');
const logging = require('@tryghost/logging');
Severity: Minor
Found in ghost/core/core/server/services/settings/SettingsBREADService.js - About 2 hrs to fix

    Function AmpModal has 71 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']);

      Function useFetchApi has 71 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export const useFetchApi = () => {
          const {ghostVersion, sentryDSN} = useFramework();
      
          // eslint-disable-next-line @typescript-eslint/no-explicit-any
          return async <ResponseData = any>(endpoint: string | URL, {headers = {}, retry, ...options}: RequestOptions = {}): Promise<ResponseData> => {
      Severity: Major
      Found in apps/admin-x-framework/src/utils/api/fetchApi.ts - About 2 hrs to fix

        Offer has 25 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Offer {
            events = [];
            get id() {
                return this.props.id.toHexString();
            }
        Severity: Minor
        Found in ghost/offers/lib/domain/models/Offer.js - About 2 hrs to fix

          Member has 25 functions (exceeds 20 allowed). Consider refactoring.
          Open

          const Member = ghostBookshelf.Model.extend({
              tableName: 'members',
          
              defaults() {
                  return {
          Severity: Minor
          Found in ghost/core/core/server/models/member.js - About 2 hrs to fix

            I18n has 25 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class I18n {
                /**
                 * @param {object} [options]
                 * @param {string} options.basePath - the base path to the translations directory
                 * @param {string} [options.locale] - a locale string
            Severity: Minor
            Found in ghost/core/core/frontend/services/theme-engine/i18n/I18n.js - About 2 hrs to fix

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

                  async edit(settings, options, stripeConnectData) {
                      let filteredSettings = settings.filter((setting) => {
                          // The `stripe_connect_integration_token` "setting" is only used to set the `stripe_connect_*` settings.
                          return ![
                              'stripe_connect_integration_token',
              Severity: Major
              Found in ghost/core/core/server/services/settings/SettingsBREADService.js - About 2 hrs to fix

                File authors.js has 283 lines of code (exceeds 250 allowed). Consider refactoring.
                Open

                const _ = require('lodash');
                const tpl = require('@tryghost/tpl');
                const errors = require('@tryghost/errors');
                const {sequence} = require('@tryghost/promise');
                
                
                Severity: Minor
                Found in ghost/core/core/server/models/relations/authors.js - About 2 hrs to fix

                  Function mockStats has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export default function mockStats(server) {
                      server.get('/stats/subscriptions/', function () {
                          return {
                              stats: [],
                              meta: {
                  Severity: Major
                  Found in ghost/admin/mirage/config/stats.js - About 2 hrs to fix

                    Function setupMembersApp has 69 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 2 hrs to fix

                      Function each has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          _.each(columns, function each(columnKey) {
                              let message = ''; // KEEP: Validator.js only validates strings.
                              const strVal = _.toString(model.get(columnKey));
                      
                              if (options.method !== 'insert' && !_.has(model.changed, columnKey)) {
                      Severity: Major
                      Found in ghost/core/core/server/data/schema/validator.js - About 2 hrs to fix

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

                            async function up(knex) {
                                logging.info('Checking default_content_visibility for specific tiers');
                        
                                const settings = await knex('settings')
                                    .select()

                          Function replaceIdentifiers has 69 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/PostsImporter.js - About 2 hrs to fix

                            Function getImageDimensions has 69 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                            async function getImageDimensions(metaData) {
                                const MAX_SOCIAL_IMG_WIDTH = config.get('imageOptimization:internalImageSizes:social-image:width') || 1200;
                            
                                const fetch = {
                                    coverImage: imageSizeCache.getCachedImageSizeFromUrl(metaData.coverImage.url),
                            Severity: Major
                            Found in ghost/core/core/frontend/meta/image-dimensions.js - About 2 hrs to fix

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

                                  async add(data, options) {
                                      if (!this.stripeService.configured && (data.comped || data.stripe_customer_id)) {
                                          const property = data.comped ? 'comped' : 'stripe_customer_id';
                                          throw new errors.ValidationError({
                                              message: tpl(messages.stripeNotConnected),
                              Severity: Minor
                              Found in ghost/members-api/lib/services/MemberBREADService.js - About 2 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 mediaValidation has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                              Open

                              const mediaValidation = function ({type}) {
                                  return function mediaUploadValidation(req, res, next) {
                                      const extensions = (config.get('uploads')[type] && config.get('uploads')[type].extensions) || [];
                                      const contentTypes = (config.get('uploads')[type] && config.get('uploads')[type].contentTypes) || [];
                              
                              
                              Severity: Minor
                              Found in ghost/core/core/server/web/api/middleware/upload.js - About 2 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 render has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                              Open

                                  render() {
                                      const {page, pageQuery, site, customSiteUrl} = this.context;
                                      const products = getSiteProducts({site});
                                      const noOfProducts = products.length;
                              
                              
                              Severity: Minor
                              Found in apps/portal/src/components/PopupModal.js - About 2 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 NotificationText has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                              Open

                              const NotificationText = ({type, status, context}) => {
                                  const t = context.t;
                                  const signinPortalLink = getPortalLink({page: 'signin', siteUrl: context.site.url});
                                  const singupPortalLink = getPortalLink({page: 'signup', siteUrl: context.site.url});
                              
                              
                              Severity: Minor
                              Found in apps/portal/src/components/Notification.js - About 2 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 getPortalPreviewUrl has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                              Open

                              export const getPortalPreviewUrl = ({settings, config, tiers, siteData, selectedTab} : portalPreviewUrlTypes): string | null => {
                                  if (!siteData?.url) {
                                      return null;
                                  }
                                  let portalTiers = tiers.filter((t) => {
                              Severity: Minor
                              Found in apps/admin-x-settings/src/utils/getPortalPreviewUrl.ts - About 2 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 ThemePreview has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
                              Open

                              }> = ({
                                  selectedTheme,
                                  isInstalling,
                                  installedTheme,
                                  onBack,

                              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