CRBT-Team/Purplet

View on GitHub

Showing 65 of 129 total issues

Function transformContents has a Cognitive Complexity of 75 (exceeds 5 allowed). Consider refactoring.
Open

function transformContents({ contents, exportName, filename }) {
  const lines = contents.split('\n').concat('## EOF');

  let currentEndpoint = null;
  let tempMatch = null;
Severity: Minor
Found in packages/rest/scripts/gen-routes.js - About 1 day 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

File gen-routes.js has 290 lines of code (exceeds 250 allowed). Consider refactoring.
Open

#!/usr/bin/env node
import { execSync } from 'child_process';
import { existsSync, readFileSync, writeFileSync } from 'fs';
import { capitalize } from '@paperdave/utils';

Severity: Minor
Found in packages/rest/scripts/gen-routes.js - About 2 hrs to fix

    Function showHelp has 71 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      _showHelp.call(cli, data => {
        const isRoot = data.startsWith('purplet <command>');
    
        const lines = data.split('\n');
    
    
    Severity: Major
    Found in packages/purplet/src/cli/_cli.ts - About 2 hrs to fix

      Function writeAll has 69 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export async function writeAll(config: ProjectConfig, templatesRoot: string) {
        const { eslint, prettier, root, template } = config;
      
        const require = createRequire(import.meta.url);
      
      
      Severity: Major
      Found in packages/create-purplet/src/writeAll.ts - About 2 hrs to fix

        Function writeTSConfig has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        export async function writeTSConfig(config: ResolvedConfig) {
          const files = await readdir(config.root);
          const matched = searchPaths.filter(file => files.includes(file));
        
          const rootRelative = (file: string) => posixify(path.relative(config.root, file));
        Severity: Major
        Found in packages/purplet/src/config/tsconfig.ts - About 2 hrs to fix

          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

                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

                  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

                                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
                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language