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

Update the clang-format config for clang-format version 19. #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

LinZhihao-723
Copy link
Member

@LinZhihao-723 LinZhihao-723 commented Sep 25, 2024

Description

clang-format just released version 19.1 in PyPI which affects some of our linting workflows (as mentioned in y-scope/clp#545)
This PR updates the clang-format configuration to adapt the latest configuration changes:

  • Deprecated options:
    • Replace AlwaysBreakTemplateDeclarations with the equivalent BreakTemplateDeclarations
    • Replace AlwaysBreakAfterReturnType with the equivalent BreakAfterReturnType
    • Use KeepEmptyLines to replace deprecated option KeepEmptyLinesAtTheStartOfBlocks, and also add a new line to the end of file (which is not set in the old config)
  • New options introduced in clang-format 19:
    • Disable AllowShortCaseExpressionOnASingleLine
    • Diable ExceptDoubleParentheses under SpacesInParensOptions

References:
clang 19 release notes: https://releases.llvm.org/19.1.0/tools/clang/docs/ReleaseNotes.html#clang-format
clang-format 19 doc: https://releases.llvm.org/19.1.0/tools/clang/docs/

Validation performed

Use the updated config to format clp core and ensure the lint task can be successfully executed. Manually verified the refactored code pieces didn't introduce any unexpected behaviour.

Summary by CodeRabbit

  • Chores
    • Updated formatting rules for improved code consistency and readability.

Copy link

coderabbitai bot commented Sep 25, 2024

Walkthrough

The changes involve updates to the .clang-format configuration file, specifically modifying various formatting rules. Key alterations include the removal of certain options related to line breaking and the introduction of new options that dictate how return types and template declarations are formatted. Additionally, adjustments have been made to the handling of empty lines and spaces within parentheses, refining the overall formatting guidelines.

Changes

File Change Summary
lint-configs/.clang-format - Removed AlwaysBreakAfterReturnType
- Added BreakAfterReturnType: "Automatic"
- Removed AlwaysBreakTemplateDeclarations
- Added BreakTemplateDeclarations: "Yes"
- Removed KeepEmptyLinesAtTheStartOfBlocks
- Added KeepEmptyLines: { AtEndOfFile: true, AtStartOfBlock: false, AtStartOfFile: false }
- Updated SpacesInParensOptions to include ExceptDoubleParentheses: false

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2caa3dc and ea967a6.

Files selected for processing (1)
  • lint-configs/.clang-format (5 hunks)
Additional comments not posted (6)
lint-configs/.clang-format (6)

23-23: LGTM: New option correctly implemented

The addition of AllowShortCaseExpressionOnASingleLine: false aligns with the PR objectives and maintains consistency with the existing style guidelines that discourage short expressions on a single line.


63-63: LGTM: Deprecated option correctly replaced

The replacement of AlwaysBreakTemplateDeclarations with BreakTemplateDeclarations: "Yes" is in line with the PR objectives and maintains the existing behaviour of always breaking template declarations to a new line.


146-146: LGTM: New parentheses spacing option correctly implemented

The addition of ExceptDoubleParentheses: false under SpacesInParensOptions aligns with the PR objectives. This change ensures consistent spacing in all types of parentheses, including double parentheses.


91-94: LGTM: More granular empty line control implemented

The replacement of KeepEmptyLinesAtTheStartOfBlocks with the new KeepEmptyLines configuration aligns with the PR objectives. This change provides more precise control over empty lines in different parts of the file.

Please run the following script to verify the impact of this change on existing code:

#!/bin/bash
# Description: Check the impact of new KeepEmptyLines configuration on file structure

# Test: Search for files with empty lines at the start of blocks, start of file, and end of file
rg --type cpp '(^\s*$\n){2,}' -g '!*.clang-format'

Line range hint 23-146: Overall changes align well with PR objectives

The implemented changes in this .clang-format file consistently align with the stated PR objectives of updating the configuration for clang-format version 19. All mentioned replacements for deprecated options and additions of new options have been correctly implemented. The changes maintain the existing code style while adapting to the new version's capabilities.

To ensure these changes don't unexpectedly affect the codebase, it would be beneficial to run clang-format on a representative sample of the project's code and review the results.

Please run the following script to verify the overall impact of these changes:

#!/bin/bash
# Description: Apply new clang-format rules to a sample of the codebase and check for significant changes

# Test: Run clang-format on a sample of C++ files and compare with original
fd -e cpp -e h -e hpp | head -n 10 | while read -r file; do
    clang-format "$file" > "${file}.formatted"
    diff -u "$file" "${file}.formatted"
    rm "${file}.formatted"
done

54-54: LGTM: Deprecated option correctly replaced

The replacement of AlwaysBreakAfterReturnType with BreakAfterReturnType: "Automatic" aligns with the PR objectives and the latest clang-format version. This change allows for more flexible formatting of return types.

Please run the following script to verify the impact of this change on existing code:


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>, please review it.
    -- Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant