glitch-soc/mastodon

View on GitHub
app/javascript/flavours/glitch/entrypoints/admin.tsx

Summary

Maintainability
F
1 wk
Test Coverage

File admin.tsx has 315 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import '@/entrypoints/public-path';
import { createRoot } from 'react-dom/client';

import Rails from '@rails/ujs';

Severity: Minor
Found in app/javascript/flavours/glitch/entrypoints/admin.tsx - About 3 hrs to fix

    Function onChangeRegistrationMode has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    const onChangeRegistrationMode = (target: HTMLSelectElement) => {
      const enabled = target.value === 'approved';
    
      document
        .querySelectorAll<HTMLElement>(
    Severity: Minor
    Found in app/javascript/flavours/glitch/entrypoints/admin.tsx - About 1 hr to fix

      Function onDomainBlockSeverityChange has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

      const onDomainBlockSeverityChange = (target: HTMLSelectElement) => {
        const rejectMediaDiv = document.querySelector(
          '.input.with_label.domain_block_reject_media',
        );
        const rejectReportsDiv = document.querySelector(
      Severity: Minor
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx - About 35 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

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

      ready(() => {
        const domainBlockSeveritySelect = document.querySelector<HTMLSelectElement>(
          'select#domain_block_severity',
        );
        if (domainBlockSeveritySelect)
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 3 days to fix
      app/javascript/entrypoints/admin.tsx on lines 288..368

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

      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

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

      const onChangeRegistrationMode = (target: HTMLSelectElement) => {
        const enabled = target.value === 'approved';
      
        document
          .querySelectorAll<HTMLElement>(
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 1 day to fix
      app/javascript/entrypoints/admin.tsx on lines 209..240

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

      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

      Rails.delegate(document, '.batch-table__select-all button', 'click', () => {
        const hiddenField = document.querySelector<HTMLInputElement>(
          '#select_all_matching',
        );
      
      
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 1 day to fix
      app/javascript/entrypoints/admin.tsx on lines 88..114

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

      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

      Rails.delegate(document, batchCheckboxClassName, 'change', () => {
        const checkAllElement = document.querySelector<HTMLInputElement>(
          'input#batch_checkbox_all',
        );
        const selectAllMatchingElement = document.querySelector(
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 7 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 116..141

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

      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

      async function mountReactComponent(element: Element) {
        const componentName = element.getAttribute('data-admin-component');
        const stringProps = element.getAttribute('data-props');
      
        if (!stringProps) return;
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 7 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 263..286

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

      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

      const onEnableBootstrapTimelineAccountsChange = (target: HTMLInputElement) => {
        const bootstrapTimelineAccountsField =
          document.querySelector<HTMLInputElement>(
            '#form_admin_settings_bootstrap_timeline_accounts',
          );
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 6 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 175..197

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

      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

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

      const setAnnouncementEndsAttributes = (target: HTMLInputElement) => {
        const valid = target.value && target.validity.valid;
        const element = document.querySelector<HTMLInputElement>(
          'input[type="datetime-local"]#announcement_ends_at',
        );
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 6 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 8..25

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

      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

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

      const convertUTCDateTimeToLocal = (value: string) => {
        const date = new Date(value + 'Z');
        const twoChars = (x: number) => x.toString().padStart(2, '0');
        return `${date.getFullYear()}-${twoChars(date.getMonth() + 1)}-${twoChars(date.getDate())}T${twoChars(date.getHours())}:${twoChars(date.getMinutes())}`;
      };
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 5 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 242..246

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

      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

      const hideSelectAll = () => {
        const selectAllMatchingElement = document.querySelector(
          '.batch-table__select-all',
        );
        const hiddenField = document.querySelector<HTMLInputElement>(
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 5 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 46..64

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

      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

      const onDomainBlockSeverityChange = (target: HTMLSelectElement) => {
        const rejectMediaDiv = document.querySelector(
          '.input.with_label.domain_block_reject_media',
        );
        const rejectReportsDiv = document.querySelector(
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 5 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 152..169

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

      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

      Rails.delegate(document, '#batch_checkbox_all', 'change', ({ target }) => {
        if (!(target instanceof HTMLInputElement)) return;
      
        const selectAllMatchingElement = document.querySelector(
          '.batch-table__select-all',
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 4 hrs to fix
      app/javascript/entrypoints/admin.tsx on lines 66..86

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

      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

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

      function convertLocalDatetimeToUTC(value: string) {
        const date = new Date(value);
        const fullISO8601 = date.toISOString();
        return fullISO8601.slice(0, fullISO8601.indexOf('T') + 6);
      }
      Severity: Major
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 1 hr to fix
      app/javascript/entrypoints/admin.tsx on lines 248..252

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

      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

      Rails.delegate(
        document,
        '.filter-subset--with-select select',
        'change',
        ({ target }) => {
      Severity: Minor
      Found in app/javascript/flavours/glitch/entrypoints/admin.tsx and 1 other location - About 40 mins to fix
      app/javascript/entrypoints/admin.tsx on lines 143..150

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

      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