TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function useSearchService has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

const useSearchService = () => {
    const [filter, setFilter] = useState('');
    const [noResult, setNoResult] = useState(false);

    const checkVisible = (keywords: string[]) => {
Severity: Minor
Found in apps/admin-x-settings/src/utils/search.tsx - About 1 hr 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 ThemeActions has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

const ThemeActions: React.FC<ThemeActionProps> = ({
    theme
}) => {
    const {mutateAsync: activateTheme} = useActivateTheme();
    const {mutateAsync: deleteTheme} = useDeleteTheme();

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

const MultiSelect: React.FC<MultiSelectProps> = ({
    title = '',
    clearBg = false,
    error = false,
    placeholder,
Severity: Minor
Found in apps/admin-x-design-system/src/global/form/MultiSelect.tsx - About 1 hr 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 Avatar has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

export const Avatar: React.FC<AvatarProps> = ({comment}) => {
    const {member, avatarSaturation, t} = useAppContext();
    const dimensionClasses = getDimensionClasses();

    const memberName = member?.name ?? comment?.member?.name;
Severity: Minor
Found in apps/comments-ui/src/components/content/Avatar.tsx - About 1 hr 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 getSubscriptionEvents has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    async getSubscriptionEvents(options = {}, filter) {
        options = {
            ...options,
            withRelated: [
                'member',
Severity: Minor
Found in ghost/members-api/lib/repositories/EventRepository.js - About 1 hr to fix

    Function start has 47 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        start(rootApp) {
            debug('Starting...');
            this.rootApp = rootApp;
    
            const {host, port, testmode, shutdownTimeout} = this.serverConfig;
    Severity: Minor
    Found in ghost/core/core/server/GhostServer.js - About 1 hr to fix

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

          async init() {
              const debug = require('@tryghost/debug')('mediaInliner');
              const MediaInliner = require('@tryghost/external-media-inliner');
              const models = require('../../models');
              const jobsService = require('../jobs');
      Severity: Minor
      Found in ghost/core/core/server/services/media-inliner/service.js - About 1 hr to fix

        Function beforeSend has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const beforeSend = function (event, hint) {
            try {
                const exception = hint.originalException;
                const code = exception?.code ?? null;
                const context = exception?.context ?? null;
        Severity: Minor
        Found in ghost/core/core/shared/sentry.js - About 1 hr to fix

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

          module.exports = function has(options) {
              options = options || {};
              options.hash = options.hash || {};
              options.data = options.data || {};
          
          
          Severity: Minor
          Found in ghost/core/core/frontend/helpers/has.js - About 1 hr to fix

            Function AccountWelcome has 47 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            const AccountWelcome = () => {
                const {member, site, t} = useContext(AppContext);
                const {is_stripe_configured: isStripeConfigured} = site;
            
                if (!isStripeConfigured || hasOnlyFreePlan({site})) {

              Function generatePassword has 46 lines of code (exceeds 25 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 1 hr to fix

                Function generate has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    generate() {
                        // We need to add all properties here already otherwise CSV imports won't know all the columns
                        let attribution = {
                            attribution_id: null,
                            attribution_type: null,

                  Function error has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          error(error, transition) {
                              // unauthorized errors are already handled in the ajax service
                              if (isUnauthorizedError(error)) {
                                  return false;
                              }
                  Severity: Minor
                  Found in ghost/admin/app/routes/application.js - About 1 hr to fix

                    Function mockWebhooks has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export default function mockWebhooks(server) {
                        server.get('/webhooks/', paginatedResponse('webhooks'));
                    
                        server.post('/webhooks/', function ({webhooks}) {
                            let attrs = this.normalizedRequestAttrs();
                    Severity: Minor
                    Found in ghost/admin/mirage/config/webhooks.js - About 1 hr to fix

                      Function replace has 46 lines of code (exceeds 25 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 1 hr to fix

                        Function createDonationCheckoutSession has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            async createDonationCheckoutSession({priceId, successUrl, cancelUrl, metadata, customer, customerEmail}) {
                                await this._rateLimitBucket.throttle();
                        
                                /**
                                 * @type {Stripe.Checkout.SessionCreateParams}
                        Severity: Minor
                        Found in ghost/stripe/lib/StripeAPI.js - About 1 hr to fix

                          Function notifyPaidSubscriptionStarted has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              async notifyPaidSubscriptionStarted({member, subscription, offer, tier, attribution}, options = {}) {
                                  const users = await this.models.User.getEmailAlertUsers('paid-started', options);
                          
                                  for (const user of users) {
                                      const to = user.email;
                          Severity: Minor
                          Found in ghost/staff-service/lib/StaffServiceEmails.js - About 1 hr to fix

                            Function objType has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                        objTypeHandlers[objType] = function (modelOrId, unsafeAttrs) {
                                            let modelId;
                                            unsafeAttrs = unsafeAttrs || {};
                            
                                            // If it's an internal request, resolve immediately
                            Severity: Minor
                            Found in ghost/core/core/server/services/permissions/can-this.js - About 1 hr to fix

                              Function getTotalMembersOnDatesInRange has 46 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  async getTotalMembersOnDatesInRange({days, totalMembers, siteTimezone}) {
                                      const startOfRange = moment.tz(siteTimezone).subtract(days - 1, 'days').startOf('day').utc().format(dateFormat);
                                      const tzOffsetMins = moment.tz(siteTimezone).utcOffset();
                              
                                      let result;
                              Severity: Minor
                              Found in ghost/core/core/server/services/members/stats/MembersStats.js - About 1 hr to fix

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

                                    async init(ghostServer) {
                                        _enable = async () => {
                                            if (_isClosing) {
                                                logging.info('Waiting for previous Lexical multiplayer websockets service to close');
                                                await _closePromise;
                                Severity: Minor
                                Found in ghost/core/core/server/services/lexical-multiplayer/service.js - About 1 hr to fix
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language