Chocobozzz/PeerTube

View on GitHub
server/core/initializers/constants.ts

Summary

Maintainability
F
5 days
Test Coverage

File constants.ts has 1175 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { maxBy, minBy, randomInt } from '@peertube/peertube-core-utils'
import {
  AbuseState,
  AbuseStateType,
  ActivityPubActorType,
Severity: Major
Found in server/core/initializers/constants.ts - About 3 days to fix

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

    export async function buildLanguages () {
      const { iso6393 } = await import('iso-639-3')
    
      const languages: { [id: string]: string } = {}
    
    
    Severity: Minor
    Found in server/core/initializers/constants.ts - About 1 hr to fix

      Function buildVideoMimetypeExt has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function buildVideoMimetypeExt () {
        const data = {
          // streamable formats that warrant cross-browser compatibility
          'video/webm': '.webm',
          // We'll add .ogg if additional extensions are enabled
      Severity: Minor
      Found in server/core/initializers/constants.ts - About 1 hr to fix

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

        function buildVideoExtMimetype (obj: { [ id: string ]: string | string[] }) {
          const result: { [id: string]: string } = {}
        
          for (const mimetype of Object.keys(obj)) {
            const value = obj[mimetype]
        Severity: Minor
        Found in server/core/initializers/constants.ts - 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

          LOGS: {
            CLIENT_MESSAGE: { min: 1, max: 1000 }, // Length
            CLIENT_STACK_TRACE: { min: 1, max: 15000 }, // Length
            CLIENT_META: { min: 1, max: 15000 }, // Length
            CLIENT_USER_AGENT: { min: 1, max: 200 } // Length
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 2 hrs to fix
        server/core/initializers/constants.ts on lines 498..503

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

        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

          RUNNER_JOBS: {
            TOKEN: { min: 1, max: 1000 }, // Length
            REASON: { min: 1, max: 5000 }, // Length
            ERROR_MESSAGE: { min: 1, max: 5000 }, // Length
            PROGRESS: { min: 0, max: 100 } // Value
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 2 hrs to fix
        server/core/initializers/constants.ts on lines 487..492

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

        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

          RUNNERS: {
            TOKEN: { min: 1, max: 1000 }, // Length
            NAME: { min: 1, max: 100 }, // Length
            DESCRIPTION: { min: 1, max: 1000 } // Length
          },
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 1 hr to fix
        server/core/initializers/constants.ts on lines 510..514

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

        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

          WATCHED_WORDS: {
            LIST_NAME: { min: 1, max: 100 }, // Length
            WORDS: { min: 1, max: 500 }, // Number of total words
            WORD: { min: 1, max: 100 } // Length
          }
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 1 hr to fix
        server/core/initializers/constants.ts on lines 493..497

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

        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 const VIDEO_CHANNEL_SYNC_STATE: { [ id in VideoChannelSyncStateType ]: string } = {
          [VideoChannelSyncState.FAILED]: 'Failed',
          [VideoChannelSyncState.SYNCED]: 'Synchronized',
          [VideoChannelSyncState.PROCESSING]: 'Processing',
          [VideoChannelSyncState.WAITING_FIRST_RUN]: 'Waiting first run'
        Severity: Major
        Found in server/core/initializers/constants.ts and 2 other locations - About 1 hr to fix
        server/core/initializers/constants.ts on lines 655..660
        server/core/initializers/constants.ts on lines 662..667

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

        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 const USER_EXPORT_STATES: { [ id in UserExportStateType ]: string } = {
          [UserExportState.PENDING]: 'Pending',
          [UserExportState.PROCESSING]: 'Processing',
          [UserExportState.COMPLETED]: 'Completed',
          [UserExportState.ERRORED]: 'Failed'
        Severity: Major
        Found in server/core/initializers/constants.ts and 2 other locations - About 1 hr to fix
        server/core/initializers/constants.ts on lines 613..618
        server/core/initializers/constants.ts on lines 662..667

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

        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 const USER_IMPORT_STATES: { [ id in UserImportStateType ]: string } = {
          [UserImportState.PENDING]: 'Pending',
          [UserImportState.PROCESSING]: 'Processing',
          [UserImportState.COMPLETED]: 'Completed',
          [UserImportState.ERRORED]: 'Failed'
        Severity: Major
        Found in server/core/initializers/constants.ts and 2 other locations - About 1 hr to fix
        server/core/initializers/constants.ts on lines 613..618
        server/core/initializers/constants.ts on lines 655..660

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

        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

        export const PREVIEWS_SIZE = {
          width: maxBy(CONFIG.THUMBNAILS.SIZES, 'width').width,
          height: maxBy(CONFIG.THUMBNAILS.SIZES, 'width').height,
          minRemoteWidth: 400
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 1 hr to fix
        server/core/initializers/constants.ts on lines 901..905

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

        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

        export const THUMBNAILS_SIZE = {
          width: minBy(CONFIG.THUMBNAILS.SIZES, 'width').width,
          height: minBy(CONFIG.THUMBNAILS.SIZES, 'width').height,
          minRemoteWidth: 150
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 1 hr to fix
        server/core/initializers/constants.ts on lines 906..910

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

        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

        export const VIDEO_IMPORT_STATES: { [ id in VideoImportStateType ]: string } = {
          [VideoImportState.FAILED]: 'Failed',
          [VideoImportState.PENDING]: 'Pending',
          [VideoImportState.SUCCESS]: 'Success',
          [VideoImportState.REJECTED]: 'Rejected',
        Severity: Major
        Found in server/core/initializers/constants.ts and 1 other location - About 1 hr to fix
        client/src/app/menu/menu.component.ts on lines 78..85

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

        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 5 locations. Consider refactoring.
        Open

        export const VIDEO_COMMENTS_POLICY: { [ id in VideoCommentPolicyType ]: string } = {
          [VideoCommentPolicy.DISABLED]: 'Disabled',
          [VideoCommentPolicy.ENABLED]: 'Enabled',
          [VideoCommentPolicy.REQUIRES_APPROVAL]: 'Requires approval'
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 4 other locations - About 45 mins to fix
        packages/core-utils/src/users/user-role.ts on lines 3..7
        server/core/initializers/constants.ts on lines 620..624
        server/core/initializers/constants.ts on lines 626..630
        server/core/initializers/constants.ts on lines 632..636

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

        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 5 locations. Consider refactoring.
        Open

        export const VIDEO_PLAYLIST_PRIVACIES: { [ id in VideoPlaylistPrivacyType ]: string } = {
          [VideoPlaylistPrivacy.PUBLIC]: 'Public',
          [VideoPlaylistPrivacy.UNLISTED]: 'Unlisted',
          [VideoPlaylistPrivacy.PRIVATE]: 'Private'
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 4 other locations - About 45 mins to fix
        packages/core-utils/src/users/user-role.ts on lines 3..7
        server/core/initializers/constants.ts on lines 620..624
        server/core/initializers/constants.ts on lines 626..630
        server/core/initializers/constants.ts on lines 669..673

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

        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 5 locations. Consider refactoring.
        Open

        export const ABUSE_STATES: { [ id in AbuseStateType ]: string } = {
          [AbuseState.PENDING]: 'Pending',
          [AbuseState.REJECTED]: 'Rejected',
          [AbuseState.ACCEPTED]: 'Accepted'
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 4 other locations - About 45 mins to fix
        packages/core-utils/src/users/user-role.ts on lines 3..7
        server/core/initializers/constants.ts on lines 626..630
        server/core/initializers/constants.ts on lines 632..636
        server/core/initializers/constants.ts on lines 669..673

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

        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 5 locations. Consider refactoring.
        Open

        export const USER_REGISTRATION_STATES: { [ id in UserRegistrationStateType ]: string } = {
          [UserRegistrationState.PENDING]: 'Pending',
          [UserRegistrationState.REJECTED]: 'Rejected',
          [UserRegistrationState.ACCEPTED]: 'Accepted'
        }
        Severity: Major
        Found in server/core/initializers/constants.ts and 4 other locations - About 45 mins to fix
        packages/core-utils/src/users/user-role.ts on lines 3..7
        server/core/initializers/constants.ts on lines 620..624
        server/core/initializers/constants.ts on lines 632..636
        server/core/initializers/constants.ts on lines 669..673

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

        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