Skip to content

/generate-best-practices

Description

Best Practices helps your team follow coding guidelines by integrating them into Qodo Gen's suggestions. Use this feature to enforce consistency and quality across your project.

Use the /generate-best-practices command to generate a best_practices.md file. This is a generic file automatically generated by Qodo Gen. You can modify or completely replace it to include the specific guidelines you want your team to follow.

How to Use

To use the /generate-best-practices command, follow these steps:

  1. Select Your Focus: Before using this command, set a Focus. While the Focus does not influence the content of the generated best_practices.md file, Qodo Gen requires a Focus to be set in order to execute any command.

  2. Initiate the Command: Type /best-practices in the chat interface. Qodo Gen will process your request and generate coding best practices and guidelines.

  3. Copy the Response as Markdown: Click the three dots button in the top-right corner of Qodo Gen's response message, and select Copy message as markdown. Paste the markdown content into a new file named best_practices.md.

  4. Customize best_practices.md: Modify the content of best_practices.md as needed. You can add new best practices, modify existing ones, or remove parts to better suit your team's requirements. You can also ask Qodo Chat to do that for you!

The best_practices.md File

Qodo Gen automatically reads a best_practices.md file located at the root of your project directory. This file should contain guidelines and standards that your team should follow when coding.

File Size Limit:

  • The best_practices.md file can contain up to 1,500 lines.
  • If the file exceeds this limit, Qodo Gen will process only the first 1,500 lines and ignore the rest.

Example

Best Practices File Example

# Qodo Gen Best Practices

## General Code Structure

- **Consistent Naming Conventions**: Use descriptive and consistent naming for variables, functions, and classes. For example, use camelCase for variables and functions, and PascalCase for class names.

- **Documentation and Comments**: Ensure all functions, classes, and modules have comprehensive docstrings. Use the `/docstring` command to generate or improve documentation.

- **Code Modularity**: Break down large functions into smaller, reusable components. This enhances readability and maintainability.

## YAML Configuration

- **Navigation Structure**: Organize navigation in YAML files using nested lists for hierarchical structures. Ensure each section is clearly defined and logically grouped.

  ```yaml
  nav: 
    - 'index.md'
    - Installation:
      - 'installation/index.md'
      - 'installation/vscode.md'
  ```

- **Theme Customization**: Define custom themes and palettes in the YAML configuration to maintain a consistent look and feel across the documentation.

  ```yaml
  theme:
    name: material
    palette:
      - media: "(prefers-color-scheme: light)"
        scheme: default
  ```

## Markdown and Documentation

- **Use of Admonitions**: Utilize admonitions for highlighting important information, such as tips, warnings, and examples. Use custom icons and colors to differentiate types.

  ```markdown
  !!! success "Available in"
      - [:fontawesome-solid-file-code: Current File focus](../focus/current-file.md)
  ```

- **Image Integration**: Include images in documentation to enhance understanding. Use lazy loading for performance optimization.

  ```markdown
  ![example-image](./assets/example.png){loading=lazy}
  ```

- **Code Blocks**: Use fenced code blocks for syntax highlighting and clarity. Ensure code snippets are relevant and concise.

  ```python
  def example_function(param1, param2):
      """Example function with parameters."""
      return param1 + param2
  ```

## Python Scripting

- **Error Handling**: Implement try-except blocks to handle exceptions gracefully. Log errors for debugging purposes.

  ```python
  try:
      with open(file_path, 'r') as file:
          content = file.read()
  except FileNotFoundError as e:
      print(f"Error: {e}")
  ```

- **Path Management**: Use `pathlib` for file and directory operations to ensure cross-platform compatibility.

  ```python
  from pathlib import Path

  docs_path = Path(__file__).parent / "docs"
  ```

## GitHub Actions

- **Workflow Configuration**: Define clear and concise workflows in `.yml` files. Use environment variables and secrets for sensitive information.

  ```yaml
  jobs:
    build:
      runs-on: ubuntu-latest
      steps:
        - uses: actions/checkout@v2
        - name: Set up Python
          uses: actions/setup-python@v2
  ```

- **Branch Management**: Use descriptive branch names for feature development and bug fixes. Automate pull request creation and notifications.

  ```yaml
  - name: Create pull request
    uses: actions/github-script@v6
    with:
      github-token: ${{ secrets.GITHUB_TOKEN }}
  ```

## Chat Commands

- **Command Usage**: Use chat commands to automate repetitive tasks such as generating commit messages or describing changesets.

  ```markdown
  ### Command:
  `/commit`
  ```

- **Focus Selection**: Select appropriate focus modes (e.g., Current File, Git-Diff) to tailor command responses to the relevant context.

  ```markdown
  - **Select Your Focus**: Choose between Current File or Git-Diff for contextually relevant responses.
  ```

## Test Generation

- **Behavior Analysis**: Leverage behavior analysis to identify and categorize test scenarios. Use the advanced panel for managing test generation.

  ```markdown
  ## Behavior Categories
  - **Happy Path**: Ideal and expected use cases.
  - **Edge Case**: Unusual or extreme scenarios.
  ```

- **Test Refinement**: Continuously refine and customize generated tests to align with project requirements. Use example tests to guide style and consistency.

  ```markdown
  ## Refining Your Tests
  - **Manual Editing**: Directly edit test code for quick adjustments.
  ```

## CSS Customization

- **Custom Styles**: Define custom CSS rules for branding and visual consistency. Use CSS variables for easy theme adjustments.

  ```css
  :root {
      --md-primary-fg-color: #765bfa;
  }
  ```

- **Responsive Design**: Ensure styles are responsive and adapt to different screen sizes. Use grid layouts for flexible content arrangement.

  ```css
  .md-typeset .grid {
      grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  }
  ```

By adhering to these best practices, you can maintain a consistent and high-quality codebase that is easy to understand, extend, and maintain.
Footer