TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

Function useSortableIndexedList has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const useSortableIndexedList = <Item extends unknown>({items, setItems, blank, canAddNewItem}: {
    items: Item[];
    setItems: (newItems: Item[]) => void;
    blank: Item
    canAddNewItem: (item: Item) => boolean
Severity: Minor
Found in apps/admin-x-design-system/src/hooks/useSortableIndexedList.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 AddDetailsPopup has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const AddDetailsPopup = (props: Props) => {
    const inputNameRef = useRef<HTMLInputElement>(null);
    const inputExpertiseRef = useRef<HTMLInputElement>(null);
    const {dispatchAction, member, accentColor, t} = useAppContext();

Severity: Minor
Found in apps/comments-ui/src/components/popups/AddDetailsPopup.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 CTABox has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const CTABox: React.FC<Props> = ({isFirst, isPaid}) => {
    const {accentColor, commentCount, publication, member, t} = useAppContext();

    const buttonStyle = {
        backgroundColor: accentColor
Severity: Minor
Found in apps/comments-ui/src/components/content/CTABox.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 Form has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const Form: React.FC<FormProps> = ({
    title,
    grouped = false,
    gap = 'md',
    margins = 'md',
Severity: Minor
Found in apps/admin-x-design-system/src/global/form/Form.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 useFilterableApi has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

const useFilterableApi = <
    Data extends {id: string} & {[k in FilterKey]: string} & {[k: string]: unknown},
    ResponseKey extends string = string,
    FilterKey extends string = string
>({path, filterKey, responseKey, limit = 20}: {
Severity: Minor
Found in apps/admin-x-framework/src/hooks/useFilterableApi.ts - 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 saveNewPasswordTask has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    saveNewPasswordTask: task(function* () {
        const validation = this.isLoggedIn ? 'ownPasswordChange' : 'passwordChange';

        try {
            yield this.validate({property: validation});
Severity: Minor
Found in ghost/admin/app/models/user.js - About 1 hr to fix

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

    export default function mockInvites(server) {
        server.get('/invites/', paginatedResponse('invites'));
    
        server.get('/invites/:id', function (schema, request) {
            let {id} = request.params;
    Severity: Minor
    Found in ghost/admin/mirage/config/invites.js - About 1 hr to fix

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

          handleNotification(message, delayed = false) {
              const wordRegex = /[a-z]+/igm;
              const wordMatches = (message.message.string || message.message).matchAll(wordRegex);
      
              for (const wordMatch of wordMatches) {
      Severity: Minor
      Found in ghost/admin/app/services/notifications.js - About 1 hr to fix

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

        export function getStatsParams(config, props, additionalParams = {}) {
            const {chartRange, audience, device, browser, location, source, pathname} = props;
            const {startDate, endDate} = getDateRange(chartRange);
        
            const params = {
        Severity: Minor
        Found in ghost/admin/app/utils/stats.js - About 1 hr to fix

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

              get chartData() {
                  const stats = this.dashboardStats.filledSubscriptionCountStats;
                  const labels = stats.map(stat => stat.date);
                  const newData = stats.map(stat => stat.signups || 0);
                  const canceledData = stats.map(stat => -(stat.cancellations || 0));
          Severity: Minor
          Found in ghost/admin/app/components/dashboard/charts/paid-breakdown.js - About 1 hr to fix

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

                async apiToken() {
                    // TODO: Getting the token can be improved
                    const ghostIntegrationsUrl = this.ghostPaths.url.api('integrations') + '?include=api_keys';
                    return this.ajax.request(ghostIntegrationsUrl).then(async (response) => {
                        const ssmIntegration = response.integrations.find(r => r.slug === 'self-serve-migration');
            Severity: Minor
            Found in ghost/admin/app/services/migrate.js - About 1 hr to fix

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

                  async exchangeTokenForSession(req, res) {
                      if (!req.url) {
                          return Promise.reject(new BadRequestError({
                              message: 'Expected token param containing JWT'
                          }));
              Severity: Minor
              Found in ghost/members-ssr/lib/members-ssr.js - About 1 hr to fix

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

                    customQuery(qb, options) {
                        if (options.aggregateStatusCounts) {
                            if (options.limit || options.filter) {
                                throw new errors.IncorrectUsageError({
                                    message: 'aggregateStatusCounts does not work when passed a filter or limit'
                Severity: Minor
                Found in ghost/core/core/server/models/member-status-event.js - About 1 hr to fix

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

                      async function getMemberDataFromMagicLinkToken(token) {
                          const {email, labels = [], name = '', oldEmail, newsletters, attribution, reqIp, type} = await getTokenDataFromMagicLinkToken(token);
                          if (!email) {
                              return null;
                          }
                  Severity: Minor
                  Found in ghost/members-api/lib/members-api.js - About 1 hr to fix

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

                        constructor(deps) {
                            /** @private */
                            this.OfferModel = deps.Offer;
                            /** @private */
                            this.StripeProductModel = deps.StripeProduct;
                    Severity: Minor
                    Found in ghost/payments/lib/PaymentsService.js - About 1 hr to fix

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

                          getNQLSubset(filter) {
                              if (!filter) {
                                  return [undefined, undefined];
                              }
                      
                      
                      Severity: Minor
                      Found in ghost/members-api/lib/repositories/EventRepository.js - About 1 hr to fix

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

                            async _handleMemberCreatedEvent(event) {
                                const source = event.data?.source;
                                let sourceThreshold;
                        
                                if (source === 'api') {
                        Severity: Minor
                        Found in ghost/verification-trigger/lib/VerificationTrigger.js - About 1 hr to fix

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

                              filterRelations: function filterRelations() {
                                  return {
                                      tags: {
                                          tableName: 'tags',
                                          type: 'manyToMany',
                          Severity: Minor
                          Found in ghost/core/core/server/models/post.js - About 1 hr to fix

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

                            const activityFeedMapper = (event, frame) => {
                                if (event.type === 'comment_event') {
                                    return commentEventMapper(event, frame);
                                }
                                if (event.type === 'click_event') {

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

                              function serializeTier(tier, options) {
                                  const json = tier.toJSON(options);
                              
                                  const serialized = {
                                      id: json.id,
                                Severity
                                Category
                                Status
                                Source
                                Language