Skip to content

feat(config): Add .revu.yml config file and its loader #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2025

Conversation

RealVidy
Copy link
Contributor

@RealVidy RealVidy commented Apr 28, 2025

#27

Copy link

socket-security bot commented Apr 28, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​js-yaml@​4.0.91001006977100
Addedts-deepmerge@​7.0.310010010084100

View full report

@RealVidy RealVidy changed the title Vidy/revu config file feat(config): Add .revu.yml config file and its loader Apr 28, 2025
@RealVidy RealVidy force-pushed the vidy/revu-config-file branch from 8ea28bc to 061060c Compare April 28, 2025 23:27
@revu-bot
Copy link

revu-bot bot commented Apr 30, 2025

Pull Request Analysis

Overview

This PR adds a configuration system to the Revu application, allowing users to define custom coding guidelines through a .revu.yml file. The implementation includes a configuration handler module, tests, and documentation updates. The configuration system supports hierarchical structure, user overrides, and is designed to be extensible for future configuration options.

The changes effectively solve the intended problem by providing a clean, well-structured way to define and manage coding guidelines that will be used during code reviews.

Code Quality Review

Strengths

  • Well-structured code: The config-handler.ts module is well-organized with clear separation of concerns.
  • Comprehensive error handling: The code gracefully handles missing configuration files and parsing errors.
  • Type safety: Proper TypeScript interfaces are used for configuration objects.
  • Thorough testing: The implementation includes comprehensive tests covering various scenarios including missing files, parsing errors, and different configuration formats.
  • Default configuration: Sensible defaults are provided when no configuration file exists.
  • Documentation: Functions are well-documented with JSDoc comments.
  • Immutability: The getDefaultConfig() function returns a copy of the default config to prevent mutation.

Areas for Improvement

  • Configuration validation: There's no schema validation for the configuration file. While TypeScript interfaces provide some type safety, runtime validation would be more robust.

    // Consider adding schema validation with zod
    import { z } from 'zod';
    
    const CodingGuidelinesSchema = z.object({
      codingGuidelines: z.array(z.string()),
      reviewSettings: z.record(z.unknown())
    });
    
    function validateConfig(config: unknown): CodingGuidelinesConfig {
      return CodingGuidelinesSchema.parse(config);
    }
  • Merge strategy: The current implementation uses ts-deepmerge which concatenates arrays. This might lead to unexpected behavior if users expect array replacement rather than concatenation.

    // Consider adding an option to control merge behavior
    function readConfig(
      configPath = path.join(process.cwd(), '.revu.yml'),
      options = { concatArrays: true }
    ): Promise<CodingGuidelinesConfig> {
      // ...
      return options.concatArrays 
        ? merge(DEFAULT_CONFIG, config) 
        : { ...DEFAULT_CONFIG, ...config };
    }
  • Logging: The code uses console.log and console.error directly. Consider using a proper logging system that can be configured for different environments.

Security Assessment

  • File path handling: The code uses path.join correctly to handle file paths, which helps prevent path traversal attacks.

  • YAML parsing: The code uses js-yaml for parsing YAML files, which is generally safe, but there's no explicit protection against YAML deserialization attacks. Consider using safeLoad explicitly.

    const config = yaml.load(configContent, { schema: yaml.SAFE_SCHEMA }) as CodingGuidelinesConfig;
  • No sensitive data: The configuration doesn't appear to handle sensitive data, so there are no immediate concerns about data exposure.

Best Practices Evaluation

  • Test coverage: The tests are comprehensive and cover the main functionality, including edge cases.
  • Documentation: The code is well-documented with JSDoc comments, and the README has been updated to explain the new feature.
  • Maintainability: The code is modular and follows the single responsibility principle.
  • Extensibility: The configuration system is designed to be extensible with the [key: string]: unknown index signature.
  • Dependency management: The PR adds appropriate dependencies (js-yaml, ts-deepmerge) and their corresponding type definitions.

Recommendations

  1. Add schema validation: Implement runtime validation of the configuration file using a schema validation library like Zod, which is already a dependency of the project.

  2. Improve error handling: Provide more specific error messages when configuration parsing fails, to help users debug their configuration files.

    try {
      const config = yaml.load(configContent) as CodingGuidelinesConfig;
      // ...
    } catch (error) {
      console.error(`Error parsing .revu.yml: ${error instanceof Error ? error.message : 'Unknown error'}`);
      return DEFAULT_CONFIG;
    }
  3. Add configuration documentation: Consider adding a schema documentation or examples in the README to help users understand all available configuration options.

  4. Consider caching: For performance optimization, consider caching the parsed configuration to avoid reading and parsing the file multiple times.

    let cachedConfig: CodingGuidelinesConfig | null = null;
    
    export async function readConfig(...): Promise<CodingGuidelinesConfig> {
      if (cachedConfig) return cachedConfig;
      // ... existing implementation
      cachedConfig = result;
      return result;
    }
    
    export function clearConfigCache(): void {
      cachedConfig = null;
    }
  5. Add configuration validation command: Consider adding a CLI command to validate configuration files without running the full application.

Additional Notes

  • The PR integrates well with the existing codebase and follows the established patterns.
  • The feature enhances the application's flexibility and user experience by allowing customization of coding guidelines.
  • In the future, consider expanding the configuration system to include other aspects of the application, such as model parameters, review thresholds, or integration settings.
  • The implementation is forward-compatible with potential future configuration needs due to its extensible design.

@RealVidy RealVidy force-pushed the vidy/revu-config-file branch from 5aa6f81 to be3db6b Compare May 13, 2025 15:18
Copy link
Contributor

@gary-van-woerkens gary-van-woerkens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Peut être remplacer le mergeConfigs par une librairie.

@RealVidy RealVidy force-pushed the vidy/revu-config-file branch from be3db6b to a47ed46 Compare May 13, 2025 16:11
Copy link

@RealVidy RealVidy merged commit 5d0704d into main May 13, 2025
6 checks passed
@RealVidy RealVidy deleted the vidy/revu-config-file branch May 13, 2025 16:13
@tokenbureau
Copy link

tokenbureau bot commented May 13, 2025

🎉 This PR is included in version 1.6.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@tokenbureau tokenbureau bot added the released label May 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants