CRBT-Team/Purplet

View on GitHub

Showing 129 of 129 total issues

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

  async showMessage(message: CreateInteractionMessageData) {
    const { message: data, files } = resolveCreateInteractionMessageData(message);
    await this.respond({
      type: InteractionResponseType.ChannelMessageWithSource,
      data,
Severity: Major
Found in packages/purplet/src/structures/interaction/response.ts and 1 other location - About 2 hrs to fix
packages/purplet/src/structures/interaction/response.ts on lines 80..88

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

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 updateMessage(message: CreateInteractionMessageData) {
    const { message: data, files } = resolveCreateInteractionMessageData(message);
    await this.respond({
      type: InteractionResponseType.UpdateMessage,
      data,
Severity: Major
Found in packages/purplet/src/structures/interaction/response.ts and 1 other location - About 2 hrs to fix
packages/purplet/src/structures/interaction/response.ts on lines 45..53

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

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 createConfig has 66 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export async function createConfig(templatesRoot: string) {
  const config = {} as ProjectConfig;

  // Calculate initial directory based off of if this directory is 'empty' or not
  // Empty is a loose check that allows some stuff like `.git`
Severity: Major
Found in packages/create-purplet/src/prompts.ts - About 2 hrs to fix

    File serializers.ts has 270 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import type { Dict } from '@paperdave/utils';
    import type { BitBuffer } from './BitBuffer';
    import { BitSerializer } from './BitSerializer';
    import type { Generic } from './utils';
    import { fillArray } from './utils';
    Severity: Minor
    Found in packages/serialize/src/serializers.ts - About 2 hrs to fix

      Function $messageComponent has 61 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function $messageComponent<
        Context,
        CreateProps,
        ComponentType extends APIMessageActionRowComponent
      >(options: MessageComponentOptions<Context, CreateProps, ComponentType>) {
      Severity: Major
      Found in packages/purplet/src/hooks/component.ts - About 2 hrs to fix

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

          async deferMessage(options?: DeferMessageOptions) {
            // Note: ephemeral is the only thing we can use (well so can suppress embeds, but can't we set those when we edit?)
            await this.respond({
              type: InteractionResponseType.DeferredChannelMessageWithSource,
              data: {
        Severity: Major
        Found in packages/purplet/src/structures/interaction/response.ts and 1 other location - About 2 hrs to fix
        packages/purplet/src/structures/interaction/response.ts on lines 97..106

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

        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 deferUpdateMessage(options?: DeferMessageOptions) {
            // Note: ephemeral is the only thing we can use (well so can suppress embeds, but can't we set those when we edit?)
            await this.respond({
              type: InteractionResponseType.DeferredMessageUpdate,
              data: {
        Severity: Major
        Found in packages/purplet/src/structures/interaction/response.ts and 1 other location - About 2 hrs to fix
        packages/purplet/src/structures/interaction/response.ts on lines 62..71

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

        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 Home has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export default function Home(): JSX.Element {
          return (
            <Layout title={`Home`} description='Description will go into a meta tag in <head />'>
              <header className={clsx('hero hero--primary', styles.heroBanner)}>
                <div className={clsx('container', styles.header)}>
        Severity: Major
        Found in sites/purplet.js.org/src/pages/index.tsx - About 2 hrs to fix

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

                cmd.options = merged.map(x => ({
                  name: x.name.split(' ')[1],
                  type: ApplicationCommandOptionType.Subcommand,
                  description: x.description,
                  name_localizations: x.name_localizations,
          Severity: Major
          Found in packages/purplet/src/lib/hook-core-merge.ts and 1 other location - About 2 hrs to fix
          packages/purplet/src/lib/hook-core-merge.ts on lines 109..118

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

          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

                    options: merged
                      .filter(y => y.name.startsWith(name + ' ' + x.name.split(' ')[1] + ' '))
                      .map(y => ({
                        name: y.name.split(' ')[2],
                        type: ApplicationCommandOptionType.Subcommand,
          Severity: Major
          Found in packages/purplet/src/lib/hook-core-merge.ts and 1 other location - About 2 hrs to fix
          packages/purplet/src/lib/hook-core-merge.ts on lines 121..128

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

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

            async request<Output>(endpoint: string, options: RequestOptionsWithMethod): Promise<Output> {
              const query = Object.entries(options.query ?? {})
                .filter(([, value]) => value !== undefined)
                .map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
                .join('&');
          Severity: Minor
          Found in packages/rest/src/Rest.ts - About 2 hrs 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 mergeCommands has 53 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          export function mergeCommands(_list: ApplicationCommandResolvable[]) {
            /** I am sorry... */
            const list: any[] = _list;
          
            const groups = list.filter(x => 'isSlashCommandGroup' in x && !x.name.includes(' '));
          Severity: Major
          Found in packages/purplet/src/lib/hook-core-merge.ts - About 2 hrs to fix

            Function handleInteraction has 50 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            export async function handleInteraction(
              request: Request,
              publicKey: Uint8Array
            ): Promise<Response> {
              const signature = request.headers.get('X-Signature-Ed25519');
            Severity: Minor
            Found in packages/purplet/src/internal-runtime.ts - About 2 hrs to fix

              Function start has 48 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async start() {
                  const spinner = new Spinner({
                    text: this.firstRun ? 'Initializing development mode...' : 'Reloading...',
                  });
                  this.firstRun = false;
              Severity: Minor
              Found in packages/purplet/src/cli/dev.ts - About 1 hr to fix

                Function createRollupConfig has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                Open

                export function createRollupConfig({ input, cli = false, plugins = [], cjs = true }) {
                  const outputRoot = path.resolve('./dist');
                
                  let version = '0.0.0-unknown';
                  let pname = undefined;
                Severity: Minor
                Found in packages/shared-config/rollup.js - 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 request has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  async request<Output>(endpoint: string, options: RequestOptionsWithMethod): Promise<Output> {
                    const query = Object.entries(options.query ?? {})
                      .filter(([, value]) => value !== undefined)
                      .map(([key, value]) => `${key}=${encodeURIComponent(String(value))}`)
                      .join('&');
                Severity: Minor
                Found in packages/rest/src/Rest.ts - About 1 hr to fix

                  Function loadConfig has 44 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  export async function loadConfig(root: string) {
                    const files = await readdir(root);
                    const matched = searchPaths.filter(file => files.includes(file));
                  
                    if (matched.length === 0) {
                  Severity: Minor
                  Found in packages/purplet/src/config/index.ts - About 1 hr to fix

                    Function dynamicVirtual has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                    export default function dynamicVirtual(name: string, entries: VirtualEntry[]): Plugin {
                      const log = new Logger('build:dynamic', { debug: true });
                      const PREFIX = `\0virtual:${name}:`;
                      return {
                        name: `purplet-${name}`,
                    Severity: Minor
                    Found in packages/purplet/src/build/rollup-plugin-dynamic-virtual.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 buildPurpletBot has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                    export async function buildPurpletBot(config: ResolvedConfig, spinner?: Spinner) {
                      const debug = new Logger('build', { debug: true });
                    
                      config.adapter ??= gateway();
                    
                    
                    Severity: Minor
                    Found in packages/purplet/src/build/index.ts - About 1 hr to fix

                      Function onPacket has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        private onPacket(packet: GatewayReceivePayload) {
                          if (packet.s) {
                            this.seq = packet.s;
                          }
                      
                      
                      Severity: Minor
                      Found in packages/gateway/src/Gateway.ts - About 1 hr to fix
                        Severity
                        Category
                        Status
                        Source
                        Language