maa123/mastodon

View on GitHub
app/javascript/mastodon/actions/compose.js

Summary

Maintainability
D
3 days
Test Coverage

File compose.js has 663 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { defineMessages } from 'react-intl';

import axios from 'axios';
import { throttle } from 'lodash';

Severity: Major
Found in app/javascript/mastodon/actions/compose.js - About 1 day to fix

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

    export function submitCompose(routerHistory) {
      return function (dispatch, getState) {
        const status   = getState().getIn(['compose', 'text'], '');
        const media    = getState().getIn(['compose', 'media_attachments']);
        const statusId = getState().getIn(['compose', 'id'], null);
    Severity: Major
    Found in app/javascript/mastodon/actions/compose.js - About 2 hrs to fix

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

      export function uploadCompose(files) {
        return function (dispatch, getState) {
          const uploadLimit = 4;
          const media = getState().getIn(['compose', 'media_attachments']);
          const pending = getState().getIn(['compose', 'pending_media_attachments']);
      Severity: Minor
      Found in app/javascript/mastodon/actions/compose.js - About 1 hr to fix

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

        export function selectComposeSuggestion(position, token, suggestion, path) {
          return (dispatch, getState) => {
            let completion, startPosition;
        
            if (suggestion.type === 'emoji') {
        Severity: Minor
        Found in app/javascript/mastodon/actions/compose.js - About 1 hr to fix

          Similar blocks of code found in 5 locations. Consider refactoring.
          Open

          const messages = defineMessages({
            uploadErrorLimit: { id: 'upload_error.limit', defaultMessage: 'File upload limit exceeded.' },
            uploadErrorPoll:  { id: 'upload_error.poll', defaultMessage: 'File upload not allowed with polls.' },
            open: { id: 'compose.published.open', defaultMessage: 'Open' },
            published: { id: 'compose.published.body', defaultMessage: 'Post published.' },
          Severity: Major
          Found in app/javascript/mastodon/actions/compose.js and 4 other locations - About 2 hrs to fix
          app/javascript/mastodon/components/status.jsx on lines 65..71
          app/javascript/mastodon/features/compose/components/compose_form.jsx on lines 33..39
          app/javascript/mastodon/features/directory/index.jsx on lines 23..29
          app/javascript/mastodon/features/list_timeline/index.jsx on lines 26..32

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 92.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

            return (dispatch, getState) => {
              const me = getState().getIn(['meta', 'me']);
              const history = tagHistory.get(me);
          
              if (history !== null) {
          Severity: Major
          Found in app/javascript/mastodon/actions/compose.js and 1 other location - About 1 hr to fix
          app/javascript/mastodon/actions/search.js on lines 203..210

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 66.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          export function replyCompose(status, routerHistory) {
            return (dispatch, getState) => {
              dispatch({
                type: COMPOSE_REPLY,
                status: status,
          Severity: Major
          Found in app/javascript/mastodon/actions/compose.js and 2 other locations - About 40 mins to fix
          app/javascript/mastodon/actions/compose.js on lines 144..153
          app/javascript/mastodon/actions/compose.js on lines 155..164

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 49.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          export function mentionCompose(account, routerHistory) {
            return (dispatch, getState) => {
              dispatch({
                type: COMPOSE_MENTION,
                account: account,
          Severity: Major
          Found in app/javascript/mastodon/actions/compose.js and 2 other locations - About 40 mins to fix
          app/javascript/mastodon/actions/compose.js on lines 112..121
          app/javascript/mastodon/actions/compose.js on lines 155..164

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 49.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 3 locations. Consider refactoring.
          Open

          export function directCompose(account, routerHistory) {
            return (dispatch, getState) => {
              dispatch({
                type: COMPOSE_DIRECT,
                account: account,
          Severity: Major
          Found in app/javascript/mastodon/actions/compose.js and 2 other locations - About 40 mins to fix
          app/javascript/mastodon/actions/compose.js on lines 112..121
          app/javascript/mastodon/actions/compose.js on lines 144..153

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 49.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          There are no issues that match your filters.

          Category
          Status