TryGhost/Ghost

View on GitHub

Showing 1,820 of 4,015 total issues

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

    constructor(mainRoute, object, RESOURCE_CONFIG, routerCreated) {
        super('CollectionRouter');

        this.RESOURCE_CONFIG = RESOURCE_CONFIG.QUERY.post;

Severity: Minor
Found in ghost/core/core/frontend/services/routing/CollectionRouter.js - About 1 hr to fix

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

            async add({uuid, key, postId, score}) {
                let url = endpointFor({type: 'members', resource: 'feedback'});
                if (uuid && key) { // only necessary if not logged in, and both are required if so
                    url = url + `?uuid=${uuid}&key=${key}`;
                }
    Severity: Minor
    Found in apps/portal/src/utils/api.js - About 1 hr to fix

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

      function serveFavicon() {
          let filePath;
      
          return function serveFaviconMiddleware(req, res, next) {
              if (req.path.match(/^\/favicon\.(ico|png|jpe?g)/i)) {
      Severity: Minor
      Found in ghost/core/core/frontend/web/middleware/serve-favicon.js - About 1 hr to fix

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

            renderFrameContainer() {
                const {member, site, customSiteUrl} = this.context;
                const Styles = StylesWrapper({member});
                const isMobile = window.innerWidth < 480;
        
        
        Severity: Minor
        Found in apps/portal/src/components/PopupModal.js - About 1 hr to fix

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

              getInputFields({state}) {
                  const {t} = this.context;
          
                  const errors = state.errors || {};
                  const fields = [
          Severity: Minor
          Found in apps/portal/src/components/pages/SigninPage.js - About 1 hr to fix

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

                async fetchData() {
                    const {site: apiSiteData, member} = await this.fetchApiData();
                    const {site: devSiteData, ...restDevData} = this.fetchDevData();
                    const {site: linkSiteData, ...restLinkData} = this.fetchLinkData(apiSiteData, member);
                    const {site: previewSiteData, ...restPreviewData} = this.fetchPreviewData();
            Severity: Minor
            Found in apps/portal/src/App.js - About 1 hr to fix

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

                  shouldGenerateRevision(current: PostLike, revisions: Revision[], options?: { isPublished?: boolean; forceRevision?: boolean; newStatus?: string; olderStatus?: string; }): RevisionResult {
                      const latestRevision = revisions[revisions.length - 1];
                      // If there's no revisions for this post, we should always save a revision
                      if (revisions.length === 0) {
                          return {value: true, reason: 'initial_revision'};
              Severity: Minor
              Found in ghost/post-revisions/src/PostRevisions.ts - About 1 hr to fix

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

                        onValidate: () => {
                            const newErrors : Record<string, string> = {};
                
                            if (!formState.name && formState.name.length === 0) {
                                newErrors.name = 'Name is required';

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

                      const confirmTierStatusChange = () => {
                          if (tier) {
                              const promptTitle = tier.active ? 'Archive tier' : 'Reactivate tier';
                              const prompt = tier.active ? <>
                                  <div className='mb-6'>Members will no longer be able to subscribe to <strong>{tier.name}</strong> and it will be removed from the list of available tiers in portal.</div>

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

                        const loadOptions: LoadMultiSelectOptions = async (input, callback) => {
                            const [tiersData, labelsData, offersData] = await Promise.all([tiers.loadData(input), labels.loadData(input), offers.loadData(input)]);
                    
                            const segmentOptionGroups: GroupBase<MultiSelectOption>[] = [
                                {

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

                          const onSort = async (id: string, overId?: string) => {
                              const fromIndex = sortedActiveNewsletters.findIndex(newsletter => newsletter.id === id);
                              const toIndex = sortedActiveNewsletters.findIndex(newsletter => newsletter.id === overId) || 0;
                              const newSortOrder = arrayMove(sortedActiveNewsletters, fromIndex, toIndex);
                      
                      
                      Severity: Minor
                      Found in apps/admin-x-settings/src/components/settings/email/Newsletters.tsx - About 1 hr to fix

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

                                onSave: async () => {
                                    let validatedUrl: URL;
                                    validatedUrl = new URL(formState.url);
                        
                                    // Use the hostname as fallback title

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

                          const Pagination = () => {
                              const {pagination, dispatchAction, t} = useAppContext();
                              const labs = useLabs();
                          
                              const loadMore = () => {
                          Severity: Minor
                          Found in apps/comments-ui/src/components/content/Pagination.tsx - About 1 hr to fix

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

                                const handleSave = useCallback<SaveHandler>(async (options = {}) => {
                                    if (!validate()) {
                                        setSaveState('error');
                                        return false;
                                    }
                            Severity: Minor
                            Found in apps/admin-x-framework/src/hooks/useForm.ts - About 1 hr to fix

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

                              export const getRelativeTimestamp = (date: Date): string => {
                                  const now = new Date();
                                  const seconds = Math.floor((now.getTime() - date.getTime()) / 1000);
                                
                                  let interval = Math.floor(seconds / 31536000);
                              Severity: Minor
                              Found in apps/admin-x-activitypub/src/utils/get-relative-timestamp.ts - About 1 hr to fix

                                Consider simplifying this complex logical expression.
                                Open

                                    if (!socketAddress || !socketAddress.host || !socketAddress.port || !logging || !logging.info || !logging.warn || !message) {
                                        return Promise.resolve();
                                    }
                                Severity: Major
                                Found in ghost/bootstrap-socket/lib/bootstrap-socket.js - About 1 hr to fix

                                  Function permissible has 8 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      async permissible(commentModelOrId, action, context, unsafeAttrs, loadedPermissions, hasUserPermission, hasApiKeyPermission, hasMemberPermission) {
                                  Severity: Major
                                  Found in ghost/core/core/server/models/comment.js - About 1 hr to fix

                                    Consider simplifying this complex logical expression.
                                    Open

                                            if (center) {
                                                const centerClasses = clsx(
                                                    'flex flex-auto items-center justify-center',
                                                    (left && right) && 'basis-1/3',
                                                    ((left && !right) || (!left && right)) && 'basis-1/2'
                                    Severity: Major
                                    Found in apps/admin-x-design-system/src/global/layout/PageHeader.tsx - About 1 hr to fix

                                      Consider simplifying this complex logical expression.
                                      Open

                                          if (previewToolbar) {
                                              let toolbarLeft = (<></>);
                                              if (previewToolbarURLs) {
                                                  toolbarLeft = (
                                                      <Select
                                      Severity: Major
                                      Found in apps/admin-x-design-system/src/global/modal/PreviewModal.tsx - About 1 hr to fix

                                        Function compare has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                        Open

                                            compare(postA, postB) {
                                                let updated1 = postA.get('updatedAtUTC');
                                                let updated2 = postB.get('updatedAtUTC');
                                                let idResult,
                                                    publishedAtResult,
                                        Severity: Minor
                                        Found in ghost/admin/app/models/post.js - About 55 mins 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