mashirozx/mastodon

View on GitHub

Showing 1,785 of 1,785 total issues

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

  def collection_presenter
    if page_requested?
      ActivityPub::CollectionPresenter.new(
        id: account_followers_url(@account, page: params.fetch(:page, 1)),
        type: :ordered,
Severity: Major
Found in app/controllers/follower_accounts_controller.rb and 1 other location - About 1 hr to fix
app/controllers/following_accounts_controller.rb on lines 66..83

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 55.

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

  def collection_presenter
    if page_requested?
      ActivityPub::CollectionPresenter.new(
        id: account_following_index_url(@account, page: params.fetch(:page, 1)),
        type: :ordered,
Severity: Major
Found in app/controllers/following_accounts_controller.rb and 1 other location - About 1 hr to fix
app/controllers/follower_accounts_controller.rb on lines 63..80

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 55.

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

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

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

    export function expandTimeline(timelineId, path, params = {}, done = noOp) {
      return (dispatch, getState) => {
        const timeline = getState().getIn(['timelines', timelineId], ImmutableMap());
        const isLoadingMore = !!params.max_id;
    
    
    Severity: Minor
    Found in app/javascript/mastodon/actions/timelines.js - About 1 hr to fix

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

        render () {
          const { src, width, height, alt } = this.props;
          const { loading } = this.state;
      
          return (
      Severity: Minor
      Found in app/javascript/mastodon/components/gifv.js - About 1 hr to fix

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

        const expandNormalizedNotifications = (state, notifications, next, isLoadingRecent, usePendingItems) => {
          const lastReadId = state.get('lastReadId');
          let items = ImmutableList();
        
          notifications.forEach((n, i) => {
        Severity: Minor
        Found in app/javascript/mastodon/reducers/notifications.js - About 1 hr to fix

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

            render () {
              const { value, intl } = this.props;
              const { open, placement } = this.state;
          
              const valueOption = this.options.find(item => item.value === value);

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

            export default function push_subscriptions(state = initialState, action) {
              switch(action.type) {
              case STORE_HYDRATE: {
                const push_subscription = action.state.get('push_subscription');
            
            
            Severity: Minor
            Found in app/javascript/mastodon/reducers/push_notifications.js - About 1 hr to fix

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

                render () {
                  const { isPollMultiple, title, index, autoFocus, intl } = this.props;
              
                  return (
                    <li>
              Severity: Minor
              Found in app/javascript/mastodon/features/compose/components/poll_form.js - About 1 hr to fix

                Method remotable_attachment has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def remotable_attachment(attachment_name, limit, suppress_errors: true, download_on_assign: true, attribute_name: nil)
                      attribute_name ||= "#{attachment_name}_remote_url".to_sym
                
                      define_method("download_#{attachment_name}!") do |url = nil|
                        url ||= self[attribute_name]
                Severity: Minor
                Found in app/models/concerns/remotable.rb - About 1 hr to fix

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

                    render () {
                      const { value, suggestions, disabled, placeholder, onKeyUp, autoFocus, className, id, maxLength } = this.props;
                      const { suggestionsHidden } = this.state;
                  
                      return (
                  Severity: Minor
                  Found in app/javascript/mastodon/components/autosuggest_input.js - About 1 hr to fix

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

                      renderVideo () {
                        const { card, intl }  = this.props;
                        const content   = { __html: this.addAutoPlay(card.get('html')) };
                        const { width } = this.state;
                        const ratio     = card.get('width') / card.get('height');
                    Severity: Minor
                    Found in app/javascript/mastodon/features/status/components/card.js - About 1 hr to fix

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

                        onChange (path, checked) {
                          if (path[0] === 'push') {
                            if (checked && typeof window.Notification !== 'undefined' && Notification.permission !== 'granted') {
                              dispatch(requestBrowserPermission((permission) => {
                                if (permission === 'granted') {

                        Method update_count! has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def update_count!(key, value)
                            raise ArgumentError, "Invalid key #{key}" unless ALLOWED_COUNTER_KEYS.include?(key)
                            raise ArgumentError, 'Do not call update_count! on dirty objects' if association(:account_stat).loaded? && account_stat&.changed? && account_stat.changed_attribute_names_to_save == %w(id)
                        
                            value = value.to_i
                        Severity: Minor
                        Found in app/models/concerns/account_counters.rb - About 1 hr to fix

                          Method calculate_scores has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def calculate_scores(preview_cards, at_time)
                              global_items = []
                              locale_items = Hash.new { |h, key| h[key] = [] }
                          
                              preview_cards.each do |preview_card|
                          Severity: Minor
                          Found in app/models/trends/links.rb - About 1 hr to fix

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

                            export default function conversations(state = initialState, action) {
                              switch (action.type) {
                              case CONVERSATIONS_FETCH_REQUEST:
                                return state.set('isLoading', true);
                              case CONVERSATIONS_FETCH_FAIL:
                            Severity: Minor
                            Found in app/javascript/mastodon/reducers/conversations.js - About 1 hr to fix

                              Method process_update has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                def process_update
                                  user.settings['notification_emails'] = merged_notification_emails if change?('notification_emails')
                                  user.settings['interactions']        = merged_interactions if change?('interactions')
                                  user.settings['default_privacy']     = default_privacy_preference if change?('setting_default_privacy')
                                  user.settings['default_sensitive']   = default_sensitive_preference if change?('setting_default_sensitive')
                              Severity: Minor
                              Found in app/lib/user_settings_decorator.rb - About 1 hr to fix

                                Method call has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                  def call(username, domain, json, options = {})
                                    return if json['inbox'].blank? || unsupported_uri_scheme?(json['id']) || domain_not_allowed?(domain)
                                
                                    @options     = options
                                    @json        = json
                                Severity: Minor
                                Found in app/services/activitypub/process_account_service.rb - About 1 hr to fix

                                  Method klass has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                      def klass
                                        case @json['type']
                                        when 'Create'
                                          ActivityPub::Activity::Create
                                        when 'Announce'
                                  Severity: Minor
                                  Found in app/lib/activitypub/activity.rb - About 1 hr to fix

                                    Method perform has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                      def perform
                                        # Maintaining a materialized view speeds-up subsequent queries significantly
                                        AccountSummary.refresh
                                        FollowRecommendation.refresh
                                    
                                    
                                    Severity: Minor
                                    Found in app/workers/scheduler/follow_recommendations_scheduler.rb - About 1 hr to fix
                                      Severity
                                      Category
                                      Status
                                      Source
                                      Language