TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

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

      const Search: React.FC<SearchProps> = ({}) => {
          // Initialise suggested profiles
          const {suggestedProfilesQuery, updateSuggestedProfile} = useSuggestedProfiles('index', ['@index@activitypub.ghost.org', '@index@john.onolan.org', '@index@coffeecomplex.ghost.io', '@index@codename-jimmy.ghost.io', '@index@syphoncontinuity.ghost.io']);
          const {data: suggested = [], isLoading: isLoadingSuggested} = suggestedProfilesQuery;
      
      
      Severity: Major
      Found in apps/admin-x-activitypub/src/components/Search.tsx - About 3 hrs to fix

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

        function SessionMiddleware({sessionService}) {
            async function createSession(req, res, next) {
                try {
                    await sessionService.createSessionForUser(req, res, req.user);
        
        
        Severity: Minor
        Found in ghost/core/core/server/services/auth/session/middleware.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 generateCustomFontCss has 89 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function generateCustomFontCss(fonts: FontSelection) {
              let fontImports: string = '';
              let fontCSS: string = '';
          
              const importStrings = {
          Severity: Major
          Found in ghost/custom-fonts/src/index.ts - 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

              ModalPostPreviewSocialComponent has 29 functions (exceeds 20 allowed). Consider refactoring.
              Open

              export default class ModalPostPreviewSocialComponent extends Component {
                  @service settings;
                  @service ghostPaths;
              
                  @inject config;
              Severity: Minor
              Found in ghost/admin/app/components/editor/modals/preview/social.js - About 3 hrs to fix

                exports has 29 functions (exceeds 20 allowed). Consider refactoring.
                Open

                module.exports = class MemberRepository {
                    /**
                     * @param {object} deps
                     * @param {any} deps.Member
                     * @param {any} deps.MemberNewsletter
                Severity: Minor
                Found in ghost/members-api/lib/repositories/MemberRepository.js - About 3 hrs to fix

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

                      return async function Http(req, res, next) {
                          debug(`External API request to ${req.url}`);
                          let apiKey = null;
                          let integration = null;
                          let user = null;
                  Severity: Major
                  Found in ghost/api-framework/lib/http.js - About 3 hrs to fix

                    File posts.js has 311 lines of code (exceeds 250 allowed). Consider refactoring.
                    Open

                    const urlUtils = require('../../../shared/url-utils');
                    const models = require('../../models');
                    const getPostServiceInstance = require('../../services/posts/posts-service');
                    const allowedIncludes = [
                        'tags',
                    Severity: Minor
                    Found in ghost/core/core/server/api/endpoints/posts.js - About 3 hrs to fix

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

                          async getAggregatedClickEvents(options = {}, filter) {
                              let postId = '';
                      
                              if (filter && filter.$and) {
                                  // Case when there is an $and condition
                      Severity: Major
                      Found in ghost/members-api/lib/repositories/EventRepository.js - About 3 hrs to fix

                        File OEmbedService.js has 310 lines of code (exceeds 250 allowed). Consider refactoring.
                        Open

                        const errors = require('@tryghost/errors');
                        const tpl = require('@tryghost/tpl');
                        const logging = require('@tryghost/logging');
                        const _ = require('lodash');
                        const charset = require('charset');
                        Severity: Minor
                        Found in ghost/oembed-service/lib/OEmbedService.js - About 3 hrs to fix

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

                              fetchLinkData(site, member) {
                                  const qParams = new URLSearchParams(window.location.search);
                                  if (qParams.get('action') === 'unsubscribe') {
                                      // if the user is unsubscribing from a newsletter with an old unsubscribe link that we can't validate, push them to newsletter mgmt where they have to log in
                                      if (qParams.get('key') && qParams.get('uuid')) {
                          Severity: Major
                          Found in apps/portal/src/App.js - About 3 hrs to fix

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

                                add(apiConfig, frame, options = {add: true}) {
                                    debug('add');
                            
                                    if (_.get(frame,'options.source')) {
                                        const html = frame.data.posts[0].html;
                            Severity: Minor
                            Found in ghost/core/core/server/api/endpoints/utils/serializers/input/posts.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

                            Severity
                            Category
                            Status
                            Source
                            Language