Skip to content
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

(Added) Add Pint for Code Style Checking #9

Merged
merged 2 commits into from
Feb 24, 2024
Merged

(Added) Add Pint for Code Style Checking #9

merged 2 commits into from
Feb 24, 2024

Conversation

MarjovanLier
Copy link
Owner

@MarjovanLier MarjovanLier commented Feb 24, 2024

User description

Summary

This MR introduces Pint, Laravel's code stylist, as a new development dependency to enforce a consistent coding style across the project. By integrating Pint into the GitHub Actions workflow and the composer dependencies, we aim to automate code style checks, ensuring that all contributions adhere to our predefined coding standards. This addition represents a significant step towards maintaining code quality and readability.

Context and Background

As the project grows, maintaining a consistent code style becomes increasingly challenging. The introduction of Pint allows us to automate coding standards enforcement, reducing the time spent on manual reviews related to stylistic issues.

Problem Description

Before this MR, the project lacked an automated system for enforcing a consistent coding style. This absence led to varied coding styles across the codebase, making the code harder to read and maintain.

Solution Description

By integrating Pint into our development workflow, we automatically check code style against a predefined set of rules. This ensures all contributions follow the same stylistic guidelines, improving code readability and maintainability. The changes include adding Pint as a dependency in composer.json, configuring Pint in a new pint.json file, and updating the GitHub Actions workflow to run Pint checks.

List of Changes

  • Added: laravel/pint to composer.json as a development dependency for code style checking.
  • Added: test:code-style script in composer.json to run Pint checks.
  • Added: pint.json with a preset configuration for Pint to define the coding style rules.
  • Changed: .github/workflows/php.yml to include a step for running Pint checks after parallel linting and before PHPUnit tests.

Type

enhancement, configuration changes


Description

  • Adds laravel/pint as a development dependency in composer.json for enforcing code style consistency.
  • Introduces a new test:code-style script in composer.json to facilitate running Pint checks.
  • Configures Pint with a preset coding style in a newly added pint.json file.
  • Integrates Pint code style checks into the GitHub Actions workflow, adjusting subsequent test conditions.

Changes walkthrough

Relevant files
Configuration changes
php.yml
Integrate Pint Code Style Checks into GitHub Actions Workflow

.github/workflows/php.yml

  • Uncomments and enables the step to run Pint code style checks in the
    GitHub Actions workflow.
  • Adjusts the condition for running PHPUnit tests to depend on the
    success of the Pint code style checks.
  • +7/-7     
    pint.json
    Configure Pint with Preset Coding Style Rules                       

    pint.json

  • Creates a new pint.json file with a preset configuration for Pint.
  • +3/-0     
    Enhancement
    composer.json
    Add Pint as a Development Dependency and Define Test Script

    composer.json

  • Adds laravel/pint as a development dependency for code style checking.
  • Introduces a new script test:code-style to run Pint checks.
  • +3/-0     

    PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    Summary by CodeRabbit

    • New Features

      • Introduced a new code style checking tool to enhance code quality and consistency.
    • Chores

      • Updated the workflow to improve the efficiency of automated tests.
      • Added necessary configurations for the new code style checking tool.

    Pint, Laravel's code stylist, has been incorporated as a part of the continuous integration process. Now, consistent styling convention will be enforced in the project through Pint's code style tests included in the GitHub workflow. A new test command for this purpose has been added to composer.json.
    @MarjovanLier MarjovanLier self-assigned this Feb 24, 2024
    Copy link

    coderabbitai bot commented Feb 24, 2024

    Walkthrough

    The overall changes involve integrating a new code style checking tool, Laravel Pint, into the project's development workflow. This update includes modifying the GitHub Actions workflow to depend on code style checks instead of linting results for running PHPUnit tests. Additionally, the project's composer.json is updated to include Laravel Pint in the development dependencies and a new script for checking code style. A pint.json file is also introduced to set a preset configuration for the style checks.

    Changes

    File(s) Change Summary
    .github/workflows/php.yml Modified to run PHPUnit tests based on code-style check outcome instead of parallel-lint.
    composer.json Added laravel/pint to require-dev, and new script test:code-style for style checks.
    pint.json Introduced with a preset configuration named "per" for code style checks.

    Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

    Share

    Tips

    Chat

    There are 3 ways to chat with CodeRabbit:

    • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
      • I pushed a fix in commit <commit_id>.
      • Generate unit-tests for this file.
    • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
      • @coderabbitai generate unit tests for this file.
      • @coderabbitai modularize this function.
    • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
      • @coderabbitai generate interesting stats about this repository from git and render them as a table.
      • @coderabbitai show all the console.log statements in this repository.
      • @coderabbitai read src/utils.ts and generate unit tests.
      • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

    Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

    CodeRabbit Commands (invoked as PR comments)

    • @coderabbitai pause to pause the reviews on a PR.
    • @coderabbitai resume to resume the paused reviews.
    • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
    • @coderabbitai resolve resolve all the CodeRabbit review comments.
    • @coderabbitai help to get help.

    Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

    CodeRabbit Configration File (.coderabbit.yaml)

    • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
    • The JSON schema for the configuration file is available here.
    • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

    CodeRabbit Discord Community

    Join our Discord Community to get help, request features, and share feedback.

    Copy link

    codiumai-pr-agent-pro bot commented Feb 24, 2024

    PR Description updated to latest commit (b7e9a04)

    Copy link

    Changelog updates:

    2024-02-24

    Added

    • Introduced Pint, Laravel's code stylist, as a new development dependency to enforce a consistent coding style across the project.
    • Integrated Pint into the GitHub Actions workflow and the composer dependencies to automate code style checks.
    • Added laravel/pint to composer.json as a development dependency for code style checking.
    • Added test:code-style script in composer.json to run Pint checks.
    • Added pint.json with a preset configuration for Pint to define the coding style rules.

    Changed

    • Updated the GitHub Actions workflow to include a step for running Pint checks after parallel linting and before PHPUnit tests.

    to commit the new content to the CHANGELOG.md file, please type:
    '/update_changelog --pr_update_changelog.push_changelog_changes=true'

    Copy link

    codiumai-pr-agent-pro bot commented Feb 24, 2024

    PR Code Suggestions

    Suggestions                                                                                                                                                     
    best practice
    Add a failure condition for the Pint code style check step.                  

    Consider adding a failure condition for the Pint code style check step to ensure that
    subsequent steps are only executed if the code style check passes successfully.

    .github/workflows/php.yml [85-88]

     - name: Run tests with Pint
       id: code-style
       if: steps.parallel-lint.outcome == 'success'
       run: composer test:code-style
    +  continue-on-error: false
     
    Pin "laravel/pint" to a more specific version.                               

    Pin the version of "laravel/pint" to a more specific version or range to avoid potential
    compatibility issues with future releases.

    composer.json [50]

    -"laravel/pint": "^1.14",
    +"laravel/pint": "~1.14",
     
    enhancement
    Add a script for automatically fixing code style issues.                     

    Add a script for fixing code style issues automatically using Pint, which can be helpful
    for developers to quickly adhere to the project's coding standards.

    composer.json [62]

     "test:code-style": "pint --test",
    +"fix:code-style": "pint",
     
    Add a step to install dependencies before the Pint code style check.         

    Ensure consistency in the workflow by adding a step to install dependencies with Composer
    before running the Pint code style check, similar to other steps that might require vendor
    dependencies.

    .github/workflows/php.yml [85-88]

    +- name: Install dependencies
    +  run: composer install --prefer-dist --no-progress --no-suggest
     - name: Run tests with Pint
       id: code-style
       if: steps.parallel-lint.outcome == 'success'
       run: composer test:code-style
     
    possible issue
    Correct the "preset" value in pint.json to a valid option.                   

    The "preset" value in the pint.json file seems to be a typo. Correct the preset value to a
    valid option, such as "laravel" or "psr".

    pint.json [2]

     {
    -  "preset": "per"
    +  "preset": "laravel"
     }
     

    ✨ Improve tool usage guide:

    Overview:
    The improve tool scans the PR code changes, and automatically generates suggestions for improving the PR code. The tool can be triggered automatically every time a new PR is opened, or can be invoked manually by commenting on a PR.
    When commenting, to edit configurations related to the improve tool (pr_code_suggestions section), use the following template:

    /improve --pr_code_suggestions.some_config1=... --pr_code_suggestions.some_config2=...
    

    With a configuration file, use the following template:

    [pr_code_suggestions]
    some_config1=...
    some_config2=...
    
    Enabling\disabling automation

    When you first install the app, the default mode for the improve tool is:

    pr_commands = ["/improve --pr_code_suggestions.summarize=true", ...]
    

    meaning the improve tool will run automatically on every PR, with summarization enabled. Delete this line to disable the tool from running automatically.

    Utilizing extra instructions

    Extra instructions are very important for the improve tool, since they enable to guide the model to suggestions that are more relevant to the specific needs of the project.

    Be specific, clear, and concise in the instructions. With extra instructions, you are the prompter. Specify relevant aspects that you want the model to focus on.

    Examples for extra instructions:

    [pr_code_suggestions] # /improve #
    extra_instructions="""
    Emphasize the following aspects:
    - Does the code logic cover relevant edge cases?
    - Is the code logic clear and easy to understand?
    - Is the code logic efficient?
    ...
    """
    

    Use triple quotes to write multi-line instructions. Use bullet points to make the instructions more readable.

    A note on code suggestions quality
    • While the current AI for code is getting better and better (GPT-4), it's not flawless. Not all the suggestions will be perfect, and a user should not accept all of them automatically.
    • Suggestions are not meant to be simplistic. Instead, they aim to give deep feedback and raise questions, ideas and thoughts to the user, who can then use his judgment, experience, and understanding of the code base.
    • Recommended to use the 'extra_instructions' field to guide the model to suggestions that are more relevant to the specific needs of the project, or use the custom suggestions 💎 tool
    • With large PRs, best quality will be obtained by using 'improve --extended' mode.
    More PR-Agent commands

    To invoke the PR-Agent, add a comment using one of the following commands:

    • /review: Request a review of your Pull Request.
    • /describe: Update the PR title and description based on the contents of the PR.
    • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
    • /ask <QUESTION>: Ask a question about the PR.
    • /update_changelog: Update the changelog based on the PR's contents.
    • /add_docs 💎: Generate docstring for new components introduced in the PR.
    • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
    • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

    See the tools guide for more details.
    To list the possible configuration parameters, add a /config comment.

    See the improve usage page for a more comprehensive guide on using this tool.

    Copy link

    @coderabbitai coderabbitai bot left a comment

    Choose a reason for hiding this comment

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

    Review Status

    Actionable comments generated: 0

    Configuration used: .coderabbit.yaml

    Commits Files that changed from the base of the PR and between 5ae3e86 and b7e9a04.
    Files selected for processing (3)
    • .github/workflows/php.yml (2 hunks)
    • composer.json (2 hunks)
    • pint.json (1 hunks)
    Files skipped from review due to trivial changes (1)
    • pint.json
    Additional comments: 5
    composer.json (3)
    • 50-50: Adding "laravel/pint": "^1.14" to require-dev is a good practice for ensuring that the project uses a specific, tested version of Pint. This addition aligns with the PR objectives of enforcing a consistent coding style across the codebase.
    • 62-62: The introduction of the "test:code-style": "pint --test" script in the scripts section is a practical way to facilitate the running of Pint checks. This makes it easy for developers to manually check code style consistency before pushing changes.
    • 68-68: The description for the "test:code-style" script, "Check code for stylistic consistency," is clear and concise. It effectively communicates the purpose of the script to developers.
    .github/workflows/php.yml (2)
    • 84-88: The addition of the Pint check step in the GitHub Actions workflow is well-implemented. It ensures that code style checks are performed automatically as part of the CI process, aligning with the PR objectives. Placing this step after parallel-lint and before PHPUnit tests is logical, as it prioritizes code style adherence early in the CI pipeline.
    • 99-99: Changing the condition for running PHPUnit tests to depend on the successful completion of the code-style check is a strategic move. It emphasizes the importance of code style consistency by ensuring that tests are only run if the code adheres to the project's coding standards. This change effectively integrates Pint into the CI process, enhancing the overall code quality.

    Copy link

    Auto-approved PR

    @MarjovanLier MarjovanLier enabled auto-merge (squash) February 24, 2024 23:53
    @MarjovanLier MarjovanLier merged commit bbdce37 into main Feb 24, 2024
    5 checks passed
    @MarjovanLier MarjovanLier deleted the Add-Pint branch February 24, 2024 23:55
    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.

    1 participant