CRBT-Team/Purplet

View on GitHub

Showing 129 of 129 total issues

Consider simplifying this complex logical expression.
Open

      if (currentEndpoint) {
        const camelCasedName = (
          currentEndpoint[1][0].toLowerCase() +
          currentEndpoint[1].slice(1).replace(/\s+(\w)/g, (match, p1) => p1.toUpperCase())
        )
Severity: Critical
Found in packages/rest/scripts/gen-routes.js - About 1 hr to fix

    Function resolveCreateMessageData has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function resolveCreateMessageData(input: CreateMessageData): CreateMessageResult {
      const data = toJSONValue(input as JSONResolvable<CreateMessageObject>);
    
      // String
      if (typeof data === 'string') {
    Severity: Minor
    Found in packages/purplet/src/structures/resolve/create-message.ts - About 1 hr to fix

      Function toJSONValue has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export function toJSONValue<T extends JSONValue>(
        o: JSONResolvable<T>,
        locale: string = process.env['LOCALE'] ?? 'unknown'
      ): T {
        if (Array.isArray(o)) {
      Severity: Minor
      Found in packages/utils/src/json.ts - About 1 hr 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 toJSONValue has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

      export function toJSONValue<T extends JSONValue>(
        o: JSONResolvable<T>,
        locale: string = process.env['LOCALE'] ?? 'unknown'
      ): T {
        if (Array.isArray(o)) {
      Severity: Minor
      Found in packages/purplet/src/utils/json.ts - About 1 hr 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 onClose has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private onClose({ code }: CloseEvent) {
          if (code === 1000) {
            return;
          }
      
      
      Severity: Minor
      Found in packages/gateway/src/Gateway.ts - About 1 hr to fix

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

        export function $slashCommand<T>(options: SlashCommandData<T>) {
          const commandOptions = toJSONValue(options.options ?? []);
          const autocompleteHandlers = getOptionBuilderAutocompleteHandlers(options.options);
        
          return $merge([
        Severity: Minor
        Found in packages/purplet/src/hooks/command-slash.ts - About 1 hr to fix

          Function load has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                load(id) {
                  const toInclude = id.split('+').filter(x => hookIDs.includes(x));
                  if (toInclude.length === 0) {
                    return `export default []`;
                  }
          Severity: Minor
          Found in packages/purplet/src/build/rollup-plugin-purplet-features.ts - About 1 hr to fix

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

                write(value, buffer) {
                  const sign = value < 0;
                  if (sign) {
                    value += signBit;
                  }
            Severity: Major
            Found in packages/serialize/src/serializers.ts and 1 other location - About 1 hr to fix
            packages/serialize/src/serializers.ts on lines 102..109

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

            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

                write(value, buffer) {
                  const sign = value < 0;
                  if (sign) {
                    value += signBit;
                  }
            Severity: Major
            Found in packages/serialize/src/serializers.ts and 1 other location - About 1 hr to fix
            packages/serialize/src/serializers.ts on lines 59..66

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

            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 function errorNoToken() {
              return new CLIError(
                'Missing DISCORD_TOKEN environment variable!',
                dedent`
                  Please create an ${cyan('.env')} file with the following contents:
            Severity: Major
            Found in packages/purplet/src/cli/errors.ts and 1 other location - About 1 hr to fix
            packages/purplet/src/cli/errors.ts on lines 26..37

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

            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 function errorNoPublicKey() {
              return new CLIError(
                'Missing DISCORD_PUBLIC_KEY environment variable!',
                dedent`
                  Please create an ${cyan('.env')} file with the following contents:
            Severity: Major
            Found in packages/purplet/src/cli/errors.ts and 1 other location - About 1 hr to fix
            packages/purplet/src/cli/errors.ts on lines 13..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 64.

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

            export async function deploy(options: DeployOptions) {
              Logger.info(`Preparing to ${options.delete ? 'delete' : 'deploy'} commands.`);
            
              const config = await loadConfig(options.root);
              const token = env.DISCORD_TOKEN;
            Severity: Minor
            Found in packages/purplet/src/cli/deploy.ts - About 1 hr 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 onRawPacket has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

              private onRawPacket(buf: string | Uint8Array) {
                let raw: Uint8Array | string;
                if (this.inflate) {
                  const l = buf.length;
                  // TODO: use a single equals check instead of four separate ones.
            Severity: Minor
            Found in packages/gateway/src/Gateway.ts - About 1 hr 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 prettierConfig has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export async function prettierConfig(config: ProjectConfig) {
              if (config.lang !== 'js') {
                // This config is based off of prettier-config-dave
                return {
                  arrowParens: 'avoid',
            Severity: Minor
            Found in packages/create-purplet/src/options/prettier.ts - About 1 hr to fix

              Function deploy has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export async function deploy(options: DeployOptions) {
                Logger.info(`Preparing to ${options.delete ? 'delete' : 'deploy'} commands.`);
              
                const config = await loadConfig(options.root);
                const token = env.DISCORD_TOKEN;
              Severity: Minor
              Found in packages/purplet/src/cli/deploy.ts - About 1 hr to fix

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

                  static matches(raw: APIInteraction): raw is APIMessageComponentButtonInteraction {
                    return ComponentInteraction.matches(raw) && raw.data.component_type === ComponentType.Button;
                  }
                packages/purplet/src/structures/interaction/command-message.ts on lines 17..19
                packages/purplet/src/structures/interaction/command-slash.ts on lines 16..18
                packages/purplet/src/structures/interaction/command-user.ts on lines 17..19
                packages/purplet/src/structures/interaction/component-select.ts on lines 16..20

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

                  static matches(raw: APIInteraction): raw is APIMessageComponentSelectMenuInteraction {
                    return (
                      ComponentInteraction.matches(raw) && raw.data.component_type === ComponentType.SelectMenu
                    );
                  }
                packages/purplet/src/structures/interaction/command-message.ts on lines 17..19
                packages/purplet/src/structures/interaction/command-slash.ts on lines 16..18
                packages/purplet/src/structures/interaction/command-user.ts on lines 17..19
                packages/purplet/src/structures/interaction/component-button.ts on lines 12..14

                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

                Function mergePresence has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                export function mergePresence(presences: PresenceHookData[]): GatewayPresenceUpdateData {
                  const obj: GatewayPresenceUpdateData = {
                    afk: false,
                    activities: [],
                    since: null,
                Severity: Minor
                Found in packages/purplet/src/lib/hook-core-merge.ts - About 1 hr 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 5 locations. Consider refactoring.
                Open

                  static matches(raw: APIInteraction): raw is APIUserApplicationCommandInteraction {
                    return CommandInteraction.matches(raw) && raw.data.type === ApplicationCommandType.User;
                  }
                packages/purplet/src/structures/interaction/command-message.ts on lines 17..19
                packages/purplet/src/structures/interaction/command-slash.ts on lines 16..18
                packages/purplet/src/structures/interaction/component-button.ts on lines 12..14
                packages/purplet/src/structures/interaction/component-select.ts on lines 16..20

                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

                Function $messageComponent has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                Open

                function $messageComponent<
                  Context,
                  CreateProps,
                  ComponentType extends APIMessageActionRowComponent
                >(options: MessageComponentOptions<Context, CreateProps, ComponentType>) {
                Severity: Minor
                Found in packages/purplet/src/hooks/component.ts - About 1 hr 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