कोड रिव्यू करने की स्टाइल गाइड

अगर आपके पास सबसे सही तरीकों या नियमों का कोई कस्टम सेट है और आपको GitHub पर Gemini Code Assist से कोड की समीक्षा करते समय, उन्हें जांचने या उनका पालन करने के लिए कहना है, तो .gemini/ अपनी रिपॉज़िटरी के रूट फ़ोल्डर में styleguide.md Markdown फ़ाइल जोड़ें. GitHub पर Gemini Code Assist के Enterprise वर्शन का इस्तेमाल करने वाले लोग, Google Cloud Console का इस्तेमाल करके, स्टाइल गाइड की जानकारी जोड़ सकते हैं. इससे वे इस जानकारी का इस्तेमाल कई रिपॉज़िटरी में कर पाएंगे. दोनों ही मामलों में, स्टाइल गाइड को सामान्य मार्कडाउन फ़ाइल के तौर पर माना जाता है. साथ ही, यह GitHub पर Gemini Code Assist के इस्तेमाल किए जाने वाले स्टैंडर्ड प्रॉम्प्ट को बड़ा करता है.

कोड की समीक्षा करने के स्टैंडर्ड पैटर्न

कस्टम स्टाइल गाइड तय न किए जाने पर, Gemini Code Assist इन मुख्य कैटगरी के कोड की समीक्षा करता है:

  • सही होना: यह पक्का करता है कि कोड, तय किए गए तरीके से काम करे और मुश्किल मामलों को हैंडल करे. साथ ही, लॉजिक से जुड़ी गड़बड़ियों, रेस कंडीशन या एपीआई के गलत इस्तेमाल की जांच करता है.

  • परफ़ॉर्मेंस: इससे परफ़ॉर्मेंस से जुड़ी संभावित समस्याओं या ऑप्टिमाइज़ेशन के लिए उपलब्ध क्षेत्रों का पता चलता है. जैसे, बहुत ज़्यादा लूप, मेमोरी लीक, डेटा स्ट्रक्चर का सही तरीके से इस्तेमाल न होना, बार-बार की जाने वाली कैलकुलेशन, बहुत ज़्यादा लॉगिंग, और स्ट्रिंग में बदलाव करने का सही तरीका इस्तेमाल न करना.

  • बनाए रखने की क्षमता: इससे कोड को पढ़ने में आसानी, मॉड्यूलरिटी, और भाषा के मुहावरों और सबसे सही तरीकों का पालन करने का आकलन किया जाता है. यह वैरिएबल, फ़ंक्शन, और क्लास के लिए खराब नामकरण, टिप्पणियों या दस्तावेज़ों की कमी, जटिल कोड, कोड डुप्लीकेट होने, फ़ॉर्मैटिंग में अंतर होने, और मैजिक नंबर को टारगेट करता है.

  • सुरक्षा: यह डेटा हैंडलिंग या इनपुट की पुष्टि करने में संभावित कमियों की पहचान करता है. जैसे, संवेदनशील डेटा को असुरक्षित तरीके से सेव करना, इंजेक्शन अटैक, ऐक्सेस कंट्रोल का सही तरीके से इस्तेमाल न करना, किसी दूसरी साइट से किए गए फ़र्ज़ी अनुरोध (सीएसआरएफ़), और असुरक्षित डायरेक्ट ऑब्जेक्ट रेफ़रंस (आईडीओआर).

  • अन्य: पुल अनुरोध की समीक्षा करते समय, अन्य विषयों पर भी विचार किया जाता है. जैसे, टेस्टिंग, परफ़ॉर्मेंस, स्केलेबिलिटी, मॉड्युलैरिटी और रीयूज़ेबिलिटी, और गड़बड़ी लॉगिंग और मॉनिटरिंग.

स्टाइल गाइड का उदाहरण

styleguide.md फ़ाइल में, स्कीमा तय नहीं किया गया है. इसके बजाय, यह एक सामान्य भाषा में बताया गया है कि आपको Gemini Code Assist से कोड की समीक्षा किस तरह करानी है. यहां दिए गए कोड स्निपेट में, styleguide.md फ़ाइल का उदाहरण दिया गया है:

# Company X Python Style Guide

## Introduction

This style guide outlines the coding conventions for Python code developed at
Company X. It's based on PEP 8, but with some modifications to address
specific needs and preferences within our organization.

## Key Principles

*   **Readability:** Code should be easy to understand for all team members.
*   **Maintainability:** Code should be easy to modify and extend.
*   **Consistency:** Adhering to a consistent style across all projects
    improves collaboration and reduces errors.
*   **Performance:** While readability is paramount, code should be efficient.

## Deviations from PEP 8

### Line Length

* **Maximum line length:** 100 characters (instead of PEP 8's 79).
    *   Modern screens allow for wider lines, improving code readability in
        many cases.
    *   Many common patterns in our codebase, like long strings or URLs, often
        exceed 79 characters.

### Indentation

*   **Use 4 spaces per indentation level.** (PEP 8 recommendation)

### Imports

*   **Group imports:**
    *   Standard library imports
    *   Related third party imports
    *   Local application/library specific imports
*   **Absolute imports:** Always use absolute imports for clarity.
*   **Import order within groups:**  Sort alphabetically.

### Naming Conventions

*   **Variables:** Use lowercase with underscores (snake_case): `user_name`, `total_count`
*   **Constants:**  Use uppercase with underscores: `MAX_VALUE`, `DATABASE_NAME`
*   **Functions:** Use lowercase with underscores (snake_case): `calculate_total()`, `process_data()`
*   **Classes:** Use CapWords (CamelCase): `UserManager`, `PaymentProcessor`
*   **Modules:** Use lowercase with underscores (snake_case): `user_utils`, `payment_gateway`

### Docstrings

*   **Use triple double quotes (`"""Docstring goes here."""`) for all docstrings.**
*   **First line:** Concise summary of the object's purpose.
*   **For complex functions/classes:** Include detailed descriptions of
    parameters, return values, attributes, and exceptions.
*   **Use Google style docstrings:** This helps with automated documentation generation.
    ```python
    def my_function(param1, param2):
        """Single-line summary.

        More detailed description, if necessary.

        Args:
            param1 (int): The first parameter.
            param2 (str): The second parameter.

        Returns:
            bool: The return value. True for success, False otherwise.

        Raises:
            ValueError: If `param2` is invalid.
        """
        # function body here
    ```

### Type Hints

*   **Use type hints:**  Type hints improve code readability and help catch
    errors early.
*   **Follow PEP 484:**  Use the standard type hinting syntax.

### Comments

*   **Write clear and concise comments:** Explain the "why" behind the code,
    not just the "what".
*   **Comment sparingly:** Well-written code should be self-documenting where
    possible.
*   **Use complete sentences:** Start comments with a capital letter and use
    proper punctuation.

### Logging

*   **Use a standard logging framework:**  Company X uses the built-in
    `logging` module.
*   **Log at appropriate levels:** DEBUG, INFO, WARNING, ERROR, CRITICAL
*   **Provide context:** Include relevant information in log messages to aid
    debugging.

### Error Handling

*   **Use specific exceptions:** Avoid using broad exceptions like `Exception`.
*   **Handle exceptions gracefully:** Provide informative error messages and
    avoid crashing the program.
*   **Use `try...except` blocks:**  Isolate code that might raise exceptions.

## Tooling

*   **Code formatter:**  [Specify formatter, e.g., Black] - Enforces
    consistent formatting automatically.
*   **Linter:**  [Specify linter, e.g., Flake8, Pylint] - Identifies potential
    issues and style violations.

एक से ज़्यादा रिपॉज़िटरी में स्टाइल गाइड मैनेज करना

अगर आपके पास GitHub पर Gemini Code Assist का Enterprise वर्शन है, तो एक स्टाइल गाइड को कई रिपॉज़िटरी पर लागू किया जा सकता है. रिपॉज़िटरी को डेवलपर कनेक्ट कनेक्शन के हिसाब से ग्रुप किया जाता है. साथ ही, उनकी स्टाइल गाइड को Google Cloud console के ज़रिए मैनेज किया जाता है.

अगर किसी रिपॉज़िटरी को किसी ग्रुप के हिस्से के तौर पर मैनेज किया जाता है, लेकिन उसकी अपनी styleguide.md फ़ाइल भी होती है, तो रिपॉज़िटरी की styleguide.md को ग्रुप स्टाइल गाइड के साथ जोड़ दिया जाता है.

यहां दिए गए चरणों में बताया गया है कि एंटरप्राइज़ वर्शन के उपयोगकर्ता, एक से ज़्यादा रिपॉज़िटरी में एक स्टाइल गाइड को कैसे कंट्रोल कर सकते हैं. इन चरणों में यह माना गया है कि आपने पहले से ही GitHub पर Gemini Code Assist सेट अप किया हुआ है.

  1. Google Cloud Console में, Gemini Code Assist Agents & Tools पेज पर जाएं.

    एजेंट और टूल पर जाएं

  2. एजेंट सेक्शन में, कोड असिस्ट सोर्स कोड मैनेजमेंट कार्ड ढूंढें. इसके बाद, ऐडवांस पर क्लिक करें.

    Code Assist की सोर्स कोड मैनेजमेंट सुविधा में बदलाव करें पैनल खुलता है.

  3. कनेक्शन टेबल में, उस कनेक्शन के नाम पर क्लिक करें जिस पर आपको स्टाइल गाइड लागू करनी है.

    कनेक्शन की जानकारी वाला पेज खुलता है.

  4. स्टाइल गाइड टैब में, वह स्टाइल गाइड जोड़ें जिसका इस्तेमाल इस कनेक्शन से जुड़ी रिपॉज़िटरी को करना है.

  5. सेव करें पर क्लिक करें.

आगे क्या करना है