mashirozx/mastodon

View on GitHub

Showing 1,785 of 1,785 total issues

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

const mapDispatchToProps = (dispatch, { accountId }) => ({
  onRemove: () => dispatch(removeFromListEditor(accountId)),
  onAdd: () => dispatch(addToListEditor(accountId)),
});
app/javascript/mastodon/features/list_adder/components/list.js on lines 21..24

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

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

export function toShortNumber(sourceNumber) {
  if (sourceNumber < DECIMAL_UNITS.THOUSAND) {
    return [sourceNumber, DECIMAL_UNITS.ONE, 0];
  } else if (sourceNumber < DECIMAL_UNITS.MILLION) {
    return [
Severity: Minor
Found in app/javascript/mastodon/utils/numbers.js - About 45 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

Function addReaction has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

export const addReaction = (announcementId, name) => (dispatch, getState) => {
  const announcement = getState().getIn(['announcements', 'items']).find(x => x.get('id') === announcementId);

  let alreadyAdded = false;

Severity: Minor
Found in app/javascript/mastodon/actions/announcements.js - About 45 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

Avoid deeply nested control flow statements.
Open

        if (invisible) {
          if (str[i + 1] === '/') { // closing tag
            if (!--invisible) {
              tagChars = tagCharsWithEmojis;
            }
Severity: Major
Found in app/javascript/mastodon/features/emoji/emoji.js - About 45 mins to fix

    Function render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      render () {
        const { attachments, isLoading, hasMore, isAccount, multiColumn, blockedBy, suspended } = this.props;
        const { width } = this.state;
    
        if (!isAccount) {
    Severity: Minor
    Found in app/javascript/mastodon/features/account_gallery/index.js - About 45 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

    Avoid deeply nested control flow statements.
    Open

                if (subIndex !== -1) {
                  let score = subIndex + 1;
                  if (sub === id) score = 0;
    
                  aIndex.results.push(emojisList[id]);
    Severity: Major
    Found in app/javascript/mastodon/features/emoji/emoji_mart_search_light.js - About 45 mins to fix

      Function render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        render () {
          const { isLoading, results } = this.props;
          const { type } = this.state;
      
          let filteredResults = ImmutableList();
      Severity: Minor
      Found in app/javascript/mastodon/features/explore/results.js - About 45 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

      Function render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        render () {
          const { intl, onPaste, showSearch } = this.props;
          const disabled = this.props.isSubmitting;
      
          let publishText = '';
      Severity: Minor
      Found in app/javascript/mastodon/features/compose/components/compose_form.js - About 45 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

      Function recountUnread has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      const recountUnread = (state, last_read_id) => {
        return state.withMutations(mutable => {
          if (compareId(last_read_id, mutable.get('lastReadId')) > 0) {
            mutable.set('lastReadId', last_read_id);
          }
      Severity: Minor
      Found in app/javascript/mastodon/reducers/notifications.js - About 45 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

      Function render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        render () {
          const { emoji, emojiMap, hovered } = this.props;
      
          if (unicodeMapping[emoji]) {
            const { filename, shortCode } = unicodeMapping[this.props.emoji];

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

      export default function relationships(state = initialState, action) {
        switch(action.type) {
        case ACCOUNT_FOLLOW_REQUEST:
          return state.getIn([action.id, 'following']) ? state : state.setIn([action.id, action.locked ? 'requested' : 'following'], true);
        case ACCOUNT_FOLLOW_FAIL:
      Severity: Minor
      Found in app/javascript/mastodon/reducers/relationships.js - About 45 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

      Function render has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        render () {
          const { intl, myAccount, columns, multiColumn, unreadFollowRequests } = this.props;
      
          const navItems = [];
          let height = (multiColumn) ? 0 : 60;
      Severity: Minor
      Found in app/javascript/mastodon/features/getting_started/index.js - About 45 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

      Function updateReaction has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

      const updateReaction = (state, id, name, updater) => state.update('items', list => list.map(announcement => {
        if (announcement.get('id') === id) {
          return announcement.update('reactions', reactions => {
            const idx = reactions.findIndex(reaction => reaction.get('name') === name);
      
      
      Severity: Minor
      Found in app/javascript/mastodon/reducers/announcements.js - About 45 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

      Method merge_with! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def merge_with!(other_account)
          # Since it's the same remote resource, the remote resource likely
          # already believes we are following/blocking, so it's safe to
          # re-attribute the relationships too. However, during the presence
          # of the index bug users could have *also* followed the reference
      Severity: Minor
      Found in app/models/concerns/account_merging.rb - About 45 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

      Method fetch_resource has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def fetch_resource(uri, id, on_behalf_of = nil)
          unless id
            json = fetch_resource_without_id_validation(uri, on_behalf_of)
      
            return if !json.is_a?(Hash) || unsupported_uri_scheme?(json['id'])
      Severity: Minor
      Found in app/helpers/jsonld_helper.rb - About 45 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

      Method find_for_oauth has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def find_for_oauth(auth, signed_in_resource = nil)
            # EOLE-SSO Patch
            auth.uid = (auth.uid[0][:uid] || auth.uid[0][:user]) if auth.uid.is_a? Hashie::Array
            identity = Identity.find_for_oauth(auth)
      
      
      Severity: Minor
      Found in app/models/concerns/omniauthable.rb - About 45 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

      Method request_review has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def request_review
          preview_cards = PreviewCard.where(id: currently_trending_ids(false, -1))
      
          preview_cards.filter_map do |preview_card|
            next unless would_be_trending?(preview_card.id) && !preview_card.trendable? && preview_card.requires_review_notification?
      Severity: Minor
      Found in app/models/trends/links.rb - About 45 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

      Method cache_collection has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def cache_collection(raw, klass)
          return raw unless klass.respond_to?(:with_includes)
      
          raw = raw.cache_ids.to_a if raw.is_a?(ActiveRecord::Relation)
          return [] if raw.empty?
      Severity: Minor
      Found in app/controllers/concerns/cache_concern.rb - About 45 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

      Method register has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def register(status, at_time = Time.now.utc)
          original_status = status.proper
      
          return unless (original_status.public_visibility? && status.public_visibility?) &&
                        !(original_status.account.silenced? || status.account.silenced?) &&
      Severity: Minor
      Found in app/models/trends/links.rb - About 45 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

      Method next_page has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def next_page
          if only_other_accounts?
            # Only consider remote accounts
            return nil if @replies.size < DESCENDANTS_LIMIT
      
      
      Severity: Minor
      Found in app/controllers/activitypub/replies_controller.rb - About 45 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