# All files / lib/analyzers convention-analyzer.js

0% Statements 0/291
0% Branches 0/216
0% Functions 0/48
0% Lines 0/276

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673

     import fs from 'fs-extra';
    import path from 'path';
    import chalk from 'chalk';

    /**
     * Analyzes project conventions, patterns, and coding standards.
     * Returns convention metadata for ideation scoring.
     */

    /**
     * Main function to analyze project conventions.
     */
    export async function analyzeConventions(projectPath) {
      const conventions = {
        // Naming conventions
        naming: await analyzeNamingConventions(projectPath),

        // Code organization patterns
        organization: await analyzeOrganizationPatterns(projectPath),

        // Documentation practices
        documentation: await analyzeDocumentationPatterns(projectPath),

        // Testing conventions
        testing: await analyzeTestingConventions(projectPath),

        // Configuration patterns
        configuration: await analyzeConfigurationPatterns(projectPath),

        // Custom patterns specific to the project
        custom: await detectCustomPatterns(projectPath)
      };

      return conventions;
    }

    /**
     * Analyze naming conventions used in the project.
     */
    async function analyzeNamingConventions(projectPath) {
      const naming = {
        directories: { style: 'unknown', consistency: 0, examples: [] },
        files: { style: 'unknown', consistency: 0, examples: [] },
        variables: { style: 'unknown', consistency: 0, examples: [] },
        components: { style: 'unknown', consistency: 0, examples: [] }
      };

      // Analyze directory naming
      const entries = await fs.readdir(projectPath, { withFileTypes: true });
      const subdirs = entries.filter(e => e.isDirectory()).map(e => e.name);

      if (subdirs.length > 0) {
        const dirStyles = analyzeDirectoryNameStyles(subdirs);
        naming.directories = dirStyles;
      }

      // Analyze file naming in source directories
      const sourceDirs = subdirs.filter(d =>
        ['src', 'lib', 'app', 'components', 'pages', 'utils'].includes(d)
      );

      if (sourceDirs.length > 0) {
        for (const dir of sourceDirs.slice(0, 2)) { // Check up to 2 source dirs
          const dirPath = path.join(projectPath, dir);
          if (await fs.pathExists(dirPath)) {
            const files = await fs.readdir(dirPath);
            const sourceFiles = files.filter(f => {
              const ext = path.extname(f).toLowerCase();
              return ['.js', '.ts', '.jsx', '.tsx', '.py', '.go', '.rs'].includes(ext);
            });

            if (sourceFiles.length > 0) {
              const fileStyles = analyzeFileNameStyles(sourceFiles);
              naming.files = fileStyles;
              break;
            }
          }
        }
      }

      // Analyze component naming (for React/Vue/etc projects)
      const componentsDir = path.join(projectPath, 'components');
      if (await fs.pathExists(componentsDir)) {
        const componentFiles = await fs.readdir(componentsDir);
        const comps = componentFiles.filter(f =>
          f.endsWith('.tsx') || f.endsWith('.jsx') || f.endsWith('.vue')
        );

        if (comps.length > 0) {
          const compStyles = analyzeComponentNamingStyles(comps);
          naming.components = compStyles;
        }
      }

      return naming;
    }

    /**
     * Analyze organization patterns and architectural conventions.
     */
    async function analyzeOrganizationPatterns(projectPath) {
      const organization = {
        pattern: 'unknown',
        usesBarrels: false,
        barrelFiles: [],
        usesIndexExports: false,
        usesBarrel: false,
        groupingStrategy: 'unknown',
        featureBased: false,
        layerBased: false
      };

      const entries = await fs.readdir(projectPath, { withFileTypes: true });
      const subdirs = entries.filter(e => e.isDirectory()).map(e => e.name);

      // Check for barrel files (index.js/ts exports)
      const srcPath = path.join(projectPath, 'src');
      if (await fs.pathExists(srcPath)) {
        await scanForBarrelFiles(srcPath, organization);
      }

      // Detect grouping strategy
      const hasFeatureDirs = subdirs.some(d =>
        /^(features|modules|domains|entities)/.test(d)
      );
      const hasLayerDirs = subdirs.some(d =>
        /^(components|services|models|controllers|views|utils)/.test(d)
      );

      if (hasFeatureDirs) {
        organization.groupingStrategy = 'feature-based';
        organization.featureBased = true;
      } else if (hasLayerDirs) {
        organization.groupingStrategy = 'layer-based';
        organization.layerBased = true;
      } else {
        organization.groupingStrategy = 'mixed or flat';
      }

      // Check for index.ts/js exports pattern (TypeScript/JavaScript)
      const indexPath = path.join(projectPath, 'src', 'index.ts');
      if (await fs.pathExists(indexPath)) {
        organization.usesIndexExports = true;
      }

      return organization;
    }

    /**
     * Analyze documentation patterns and practices.
     */
    async function analyzeDocumentationPatterns(projectPath) {
      const documentation = {
        hasReadme: false,
        readmeFormat: 'none',
        hasChangelog: false,
        hasContributing: false,
        hasDocsDir: false,
        hasInlineDocs: false,
        hasApiDocs: false,
        docStandard: 'unknown',
        docTools: []
      };

      const entries = await fs.readdir(projectPath, { withFileTypes: true });

      // Check for README
      const readmeFile = entries.find(e =>
        e.isFile() && e.name.toLowerCase().startsWith('readme')
      );
      if (readmeFile) {
        documentation.hasReadme = true;
        const readmePath = path.join(projectPath, readmeFile.name);
        const content = await fs.readFile(readmePath, 'utf8');

        // Detect README format
        if (content.includes('```') || content.includes('```typescript')) {
          documentation.readmeFormat = 'markdown-with-code';
        } else if (content.includes('<!--') || content.includes('<h')) {
          documentation.readmeFormat = 'html';
        } else {
          documentation.readmeFormat = 'markdown';
        }

        // Check for common sections
        if (content.includes('## Installation') || content.includes('# Installation')) {
          documentation.docStandard = 'structured';
        }
      }

      // Check for CHANGELOG
      const changelogFile = entries.find(e =>
        e.isFile() && e.name.toLowerCase().includes('changelog')
      );
      if (changelogFile) {
        documentation.hasChangelog = true;
      }

      // Check for CONTRIBUTING
      const contributingFile = entries.find(e =>
        e.isFile() && e.name.toLowerCase().includes('contributing')
      );
      if (contributingFile) {
        documentation.hasContributing = true;
      }

      // Check for docs directory
      const docsDir = entries.find(e =>
        e.isDirectory() && (e.name === 'docs' || e.name === 'documentation')
      );
      if (docsDir) {
        documentation.hasDocsDir = true;
      }

      // Check for API docs tools
      const packageJsonPath = path.join(projectPath, 'package.json');
      if (await fs.pathExists(packageJsonPath)) {
        try {
          const pkg = await fs.readJson(packageJsonPath);
          const deps = { ...pkg.dependencies, ...pkg.devDependencies };

          if (deps['@storybook/react'] || deps['@storybook/vue'] || deps['@storybook/nextjs']) {
            documentation.docTools.push('storybook');
          }
          if (deps.swagger || deps['@apidevtools/swagger-cli']) {
            documentation.docTools.push('swagger');
          }
          if (deps['@docusaurus/core']) {
            documentation.docTools.push('docusaurus');
          }
          if (deps['vuepress']) {
            documentation.docTools.push('vuepress');
          }
        } catch (err) {
          // Ignore parse errors
        }
      }

      // Check for inline documentation patterns
      const srcPath = path.join(projectPath, 'src');
      if (await fs.pathExists(srcPath)) {
        const hasJSDoc = await checkForJSDocPatterns(srcPath);
        documentation.hasInlineDocs = hasJSDoc;
      }

      return documentation;
    }

    /**
     * Analyze testing conventions and patterns.
     */
    async function analyzeTestingConventions(projectPath) {
      const testing = {
        framework: 'unknown',
        namingPattern: 'unknown',
        locationStrategy: 'unknown',
        usesTestDoubles: false,
        hasTestUtils: false,
        coverageConfigured: false,
        testStructure: 'unknown'
      };

      const entries = await fs.readdir(projectPath, { withFileTypes: true });

      // Detect test framework from package.json
      const packageJsonPath = path.join(projectPath, 'package.json');
      if (await fs.pathExists(packageJsonPath)) {
        try {
          const pkg = await fs.readJson(packageJsonPath);
          const deps = { ...pkg.dependencies, ...pkg.devDependencies };

          if (deps.jest || deps['@jest/globals']) {
            testing.framework = 'jest';
          } else if (deps.mocha) {
            testing.framework = 'mocha';
          } else if (deps.vitest) {
            testing.framework = 'vitest';
          } else if (deps['@playwright/test']) {
            testing.framework = 'playwright';
          } else if (deps.cypress) {
            testing.framework = 'cypress';
          }
        } catch (err) {
          // Ignore parse errors
        }
      }

      // Detect test naming pattern
      const testDirs = entries.filter(e =>
        e.isDirectory() && (e.name.includes('test') || e.name.includes('spec'))
      );

      if (testDirs.length > 0) {
        for (const testDir of testDirs.slice(0, 1)) { // Check first test dir
          const dirPath = path.join(projectPath, testDir.name);
          const files = await fs.readdir(dirPath);
          const testFiles = files.filter(f =>
            f.endsWith('.test.js') || f.endsWith('.test.ts') ||
            f.endsWith('.spec.js') || f.endsWith('.spec.ts')
          );

          if (testFiles.length > 0) {
            if (testFiles.some(f => f.includes('.test.'))) {
              testing.namingPattern = '*.test.*';
            } else if (testFiles.some(f => f.includes('.spec.'))) {
              testing.namingPattern = '*.spec.*';
            }
          }
        }
      }

      // Detect test location strategy
      const srcPath = path.join(projectPath, 'src');
      if (await fs.pathExists(srcPath)) {
        const hasCoLocated = await scanForCoLocatedTests(srcPath);
        const hasSeparate = testDirs.length > 0;

        if (hasCoLocated && hasSeparate) {
          testing.locationStrategy = 'mixed';
        } else if (hasCoLocated) {
          testing.locationStrategy = 'co-located';
        } else if (hasSeparate) {
          testing.locationStrategy = 'separate';
        }
      }

      // Check for test utilities
      const testUtilsPath = path.join(projectPath, 'test-utils');
      const testHelpersPath = path.join(projectPath, 'tests', 'helpers');

      if (await fs.pathExists(testUtilsPath) || await fs.pathExists(testHelpersPath)) {
        testing.hasTestUtils = true;
      }

      // Check for coverage configuration
      const jestConfigPath = path.join(projectPath, 'jest.config.js');
      const vitestConfigPath = path.join(projectPath, 'vitest.config.js');

      if (await fs.pathExists(jestConfigPath) || await fs.pathExists(vitestConfigPath)) {
        testing.coverageConfigured = true;
      }

      return testing;
    }

    /**
     * Analyze configuration patterns.
     */
    async function analyzeConfigurationPatterns(projectPath) {
      const configuration = {
        style: 'unknown',
        hasEnvFiles: false,
        envFiles: [],
        usesConfigFiles: false,
        configFiles: [],
        usesJsonConfig: false,
        usesYamlConfig: false,
        hasBuildConfig: false,
        hasLintConfig: false
      };

      const entries = await fs.readdir(projectPath, { withFileTypes: true });

      // Check for environment files
      const envFiles = entries.filter(e =>
        e.isFile() && e.name.startsWith('.env')
      );

      if (envFiles.length > 0) {
        configuration.hasEnvFiles = true;
        configuration.envFiles = envFiles.map(f => f.name);
        configuration.style = 'env-based';
      }

      // Check for configuration files
      const configExtensions = ['.json', '.js', '.ts', '.yaml', '.yml', '.toml', '.ini'];
      const configFiles = entries.filter(e =>
        e.isFile() && configExtensions.includes(path.extname(e.name).toLowerCase())
      );

      if (configFiles.length > 0) {
        configuration.usesConfigFiles = true;
        configuration.configFiles = configFiles.map(f => f.name);

        // Determine config style
        const hasJson = configFiles.some(f => f.name.endsWith('.json'));
        const hasYaml = configFiles.some(f => f.name.endsWith('.yaml') || f.name.endsWith('.yml'));

        if (hasJson) {
          configuration.usesJsonConfig = true;
          configuration.style = 'json-based';
        }
        if (hasYaml) {
          configuration.usesYamlConfig = true;
          configuration.style = 'yaml-based';
        }
      }

      // Check for build configuration
      const buildConfigs = ['webpack.config.js', 'vite.config.js', 'rollup.config.js',
        'tsconfig.json', 'next.config.js', 'angular.json'];
      const hasBuildConfig = entries.some(e =>
        e.isFile() && buildConfigs.includes(e.name)
      );

      if (hasBuildConfig) {
        configuration.hasBuildConfig = true;
      }

      // Check for lint configuration
      const lintConfigs = ['.eslintrc.js', '.eslintrc.json', '.eslintrc.yml',
        '.prettierrc', 'prettier.config.js', '.pylintrc'];
      const hasLintConfig = entries.some(e =>
        e.isFile() && lintConfigs.includes(e.name)
      );

      if (hasLintConfig) {
        configuration.hasLintConfig = true;
      }

      return configuration;
    }

    /**
     * Detect custom patterns specific to the project.
     */
    async function detectCustomPatterns(projectPath) {
      const custom = {
        patterns: [],
        uniqueDirectories: [],
        uniqueFiles: [],
        unusualConfigurations: []
      };

      const entries = await fs.readdir(projectPath, { withFileTypes: true });
      const subdirs = entries.filter(e => e.isDirectory()).map(e => e.name);
      const files = entries.filter(e => e.isFile()).map(e => e.name);

      // Detect unusual directories (not in common patterns)
      const commonDirs = ['src', 'lib', 'app', 'test', 'tests', 'docs', 'config',
        'node_modules', '.git', 'dist', 'build', 'public', 'static',
        'components', 'pages', 'api', 'utils', 'services', 'models',
        'controllers', 'views', 'assets', 'styles', 'scripts'];

      const unusualDirs = subdirs.filter(d => !commonDirs.includes(d));
      if (unusualDirs.length > 0) {
        custom.uniqueDirectories = unusualDirs;
      }

      // Detect unusual configuration files
      const unusualConfigs = files.filter(f =>
        f.includes('config') && !f.startsWith('.') &&
        !['package.json', 'package-lock.json', 'yarn.lock'].includes(f)
      );
      if (unusualConfigs.length > 0) {
        custom.unusualConfigurations = unusualConfigs;
      }

      // Detect custom scripts
      const scripts = files.filter(f =>
        f.endsWith('.sh') || f.startsWith('Makefile') || f === 'Rakefile'
      );
      if (scripts.length > 0) {
        custom.patterns.push('Custom build scripts');
      }

      // Detect monorepo patterns
      if (subdirs.includes('packages') || subdirs.includes('apps') || subdirs.includes('services')) {
        custom.patterns.push('Monorepo structure');
      }

      // Detect docker usage
      if (files.includes('Dockerfile') || subdirs.includes('docker')) {
        custom.patterns.push('Docker containerization');
      }

      // Detect CI/CD
      if (subdirs.includes('.github') || subdirs.includes('.gitlab-ci') ||
        files.includes('.travis.yml') || files.includes('circleci.config.yml')) {
        custom.patterns.push('CI/CD pipeline');
      }

      return custom;
    }

    /**
     * Helper: Analyze directory name styles.
     */
    function analyzeDirectoryNameStyles(dirNames) {
      const styles = {
        kebabCase: 0,
        camelCase: 0,
        snakeCase: 0,
        PascalCase: 0
      };

      dirNames.forEach(name => {
        if (/^[a-z]+(-[a-z]+)*$/.test(name)) {
          styles.kebabCase++;
        } else if (/^[a-z]+([A-Z][a-z]*)*$/.test(name)) {
          styles.camelCase++;
        } else if (/^[a-z]+(_[a-z]+)*$/.test(name)) {
          styles.snakeCase++;
        } else if (/^[A-Z][a-z]+([A-Z][a-z]*)*$/.test(name)) {
          styles.PascalCase++;
        }
      });

      // Determine dominant style
      let dominantStyle = 'unknown';
      let maxCount = 0;
      for (const [style, count] of Object.entries(styles)) {
        if (count > maxCount) {
          maxCount = count;
          dominantStyle = style;
        }
      }

      const consistency = maxCount / dirNames.length;

      return {
        style: dominantStyle,
        consistency: consistency.toFixed(2),
        examples: dirNames.slice(0, 3)
      };
    }

    /**
     * Helper: Analyze file name styles.
     */
    function analyzeFileNameStyles(fileNames) {
      const styles = {
        kebabCase: 0,
        camelCase: 0,
        PascalCase: 0
      };

      fileNames.forEach(name => {
        const baseName = path.basename(name, path.extname(name));
        if (/^[a-z]+(-[a-z]+)*$/.test(baseName)) {
          styles.kebabCase++;
        } else if (/^[a-z]+([A-Z][a-z]*)*$/.test(baseName)) {
          styles.camelCase++;
        } else if (/^[A-Z][a-z]+([A-Z][a-z]*)*$/.test(baseName)) {
          styles.PascalCase++;
        }
      });

      // Determine dominant style
      let dominantStyle = 'unknown';
      let maxCount = 0;
      for (const [style, count] of Object.entries(styles)) {
        if (count > maxCount) {
          maxCount = count;
          dominantStyle = style;
        }
      }

      const consistency = fileNames.length > 0 ? maxCount / fileNames.length : 0;

      return {
        style: dominantStyle,
        consistency: consistency.toFixed(2),
        examples: fileNames.slice(0, 3)
      };
    }

    /**
     * Helper: Analyze component naming styles.
     */
    function analyzeComponentNamingStyles(fileNames) {
      const styles = {
        PascalCase: 0,
        lowercase: 0,
        other: 0
      };

      fileNames.forEach(name => {
        const baseName = path.basename(name, path.extname(name));
        if (/^[A-Z][a-z]+([A-Z][a-z]*)*$/.test(baseName)) {
          styles.PascalCase++;
        } else if (/^[a-z]+$/.test(baseName)) {
          styles.lowercase++;
        } else {
          styles.other++;
        }
      });

      let dominantStyle = 'unknown';
      let maxCount = 0;
      for (const [style, count] of Object.entries(styles)) {
        if (count > maxCount) {
          maxCount = count;
          dominantStyle = style;
        }
      }

      const consistency = fileNames.length > 0 ? maxCount / fileNames.length : 0;

      return {
        style: dominantStyle,
        consistency: consistency.toFixed(2),
        examples: fileNames.slice(0, 3)
      };
    }

    /**
     * Helper: Scan for barrel files.
     */
    async function scanForBarrelFiles(dirPath, organization) {
      try {
        const entries = await fs.readdir(dirPath, { withFileTypes: true });

        for (const entry of entries) {
          if (entry.isFile() && (entry.name === 'index.js' || entry.name === 'index.ts')) {
            organization.barrelFiles.push(path.relative(process.cwd(), dirPath));
            organization.usesBarrels = true;
          }

          if (entry.isDirectory() && !['node_modules', '.git', 'dist', 'build'].includes(entry.name)) {
            await scanForBarrelFiles(path.join(dirPath, entry.name), organization);
          }
        }
      } catch (err) {
        // Ignore errors
      }
    }

    /**
     * Helper: Check for JSDoc patterns.
     */
    async function checkForJSDocPatterns(dirPath) {
      try {
        const entries = await fs.readdir(dirPath, { withFileTypes: true });

        for (const entry of entries) {
          if (entry.isFile() && (entry.name.endsWith('.js') || entry.name.endsWith('.ts'))) {
            try {
              const content = await fs.readFile(path.join(dirPath, entry.name), 'utf8');
              if (content.includes('/**') && content.includes('* @')) {
                return true;
              }
            } catch (err) {
              // Skip unreadable files
            }
          }
        }
      } catch (err) {
        // Ignore errors
      }

      return false;
    }

    /**
     * Helper: Scan for co-located tests.
     */
    async function scanForCoLocatedTests(srcPath) {
      try {
        const entries = await fs.readdir(srcPath, { withFileTypes: true });

        for (const entry of entries) {
          if (entry.isFile() && (entry.name.includes('.test.') || entry.name.includes('.spec.'))) {
            return true;
          }
        }
      } catch (err) {
        // Ignore errors
      }

      return false;
    }