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

Add tasks to perform C++ linting with clang-format v18. #17

Merged
merged 2 commits into from
Oct 5, 2024

Conversation

kirkrodrigues
Copy link
Member

@kirkrodrigues kirkrodrigues commented Oct 4, 2024

Description

This PR adds the lint:cpp-check and lint:cpp-fix tasks to perform C++ linting. Currently, the tasks only run clang-format but clang-tidy will be added in a subsequent PR.

Validation performed

  • task lint:check succeeded.
  • task lint:fix succeeded.
  • task lint:cpp-check succeeded.
  • task lint:cpp-fix succeeded.
  • Added a lint violation in src/clp_ffi_js/ir/StreamReader.cpp and then:
    • task lint:check detected the violation.
    • task lint:cpp-check detected the violation.
    • task lint:fix fixed the violation.
    • task lint:cpp-fix fixed the violation.
  • Lint workflow succeeded.

Summary by CodeRabbit

  • New Features

    • Introduced C++ linting and formatting tasks to enhance code quality.
    • Added clang-format requirement for improved C++ code formatting.
    • New tasks for C++ and YAML checks and fixes have been implemented.
  • Improvements

    • Enhanced linting capabilities with new commands for C++ and YAML.

Copy link

coderabbitai bot commented Oct 4, 2024

Walkthrough

The changes in this pull request involve updates to the lint-requirements.txt and lint-tasks.yml files. A new requirement for clang-format is specified with a version constraint of 18.x, replacing the previous minimum version of 18.1.5. Additionally, the lint-tasks.yml file is modified to include new tasks and variables for C++ linting and formatting, enhancing the existing YAML linting capabilities.

Changes

File Change Summary
lint-requirements.txt Requirement updated: clang-format>=18.1.5clang-format~=18.1
lint-tasks.yml - Variable added: G_SRC_CLP_FFI_JS_DIR
- Tasks added: cpp-check, cpp-fix, clang-format
- Updated YAML section with new task aliases

Possibly related PRs

Suggested reviewers

  • junhaoliao

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between dd66383 and b42a5b3.

📒 Files selected for processing (1)
  • lint-requirements.txt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • lint-requirements.txt

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.

lint-requirements.txt Outdated Show resolved Hide resolved
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
lint-tasks.yml (2)

21-33: LGTM: C++ check task well-defined

The cpp-check task is well-structured and comprehensive. It correctly defines the source files to be checked and uses the clang-format task with the appropriate --dry-run flag. The use of an anchor for the source files list is a good practice for maintainability.

One minor suggestion:

Consider adding a comment explaining the purpose of including the .clang-format files in the sources list. This might not be immediately obvious to all developers.


56-69: LGTM: clang-format task well-implemented

The clang-format task is well-structured and flexible. It correctly uses a virtual environment, handles file types appropriately, and uses safe practices for dealing with filenames. The use of the FLAGS variable allows for reuse in both check and fix scenarios.

One suggestion for improvement:

Consider adding a set -euo pipefail at the beginning of the script to ensure it fails fast on any error. This can help catch issues early in the pipeline.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between be24868 and dd66383.

📒 Files selected for processing (2)
  • lint-requirements.txt (1 hunks)
  • lint-tasks.yml (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • lint-requirements.txt
🔇 Additional comments (6)
lint-tasks.yml (6)

4-4: LGTM: New variable for C++ source directory

The addition of G_SRC_CLP_FFI_JS_DIR is appropriate and follows the existing naming convention. This variable will be useful for specifying the source directory in C++ linting tasks.


10-11: LGTM: C++ check task added to main check command

The addition of the cpp-check task to the main check command is appropriate and aligns with the PR objective of introducing C++ linting. The task order and naming convention are consistent with the existing structure.


15-16: LGTM: C++ fix task added to main fix command

The addition of the cpp-fix task to the main fix command is appropriate and complements the cpp-check task. The task order and naming convention are consistent with the existing structure and the changes made to the check task.


34-40: LGTM: C++ fix task well-defined

The cpp-fix task is well-structured and consistent with the cpp-check task. It efficiently reuses the source files definition and correctly uses the clang-format task with the -i flag for in-place editing. This implementation aligns well with the fix functionality.


Line range hint 41-55: LGTM: YAML task reorganization

The repositioning of the yml task definition improves the overall organization of the file by grouping similar tasks together. The functionality remains unchanged, which is appropriate given the PR's focus on adding C++ linting.


Line range hint 1-69: Overall assessment: Well-implemented C++ linting integration

The changes in this file successfully implement C++ linting tasks using clang-format, as per the PR objectives. The new tasks are well-structured, consistent with existing patterns, and integrate smoothly with the existing YAML linting tasks. The use of variables and anchors promotes maintainability, and the task definitions are clear and logical.

A few minor suggestions were made for additional comments and error handling, but overall, this is a solid implementation that achieves the stated goals of the PR.

sources: &cpp_source_files
- "{{.G_SRC_CLP_FFI_JS_DIR}}/.clang-format"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.cpp"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.h"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious since I'm not too familiar with our C++ code conventions, if we're not sticking with *.hpp for headers, when do we use *.h?

Copy link
Member Author

Choose a reason for hiding this comment

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

.hpp are meant to be C++ headers. .h are meant to be C-compatible headers.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, are there cases we need our own C-compatible headers in src/clp-ffi-js?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I can think of, but this is more of a default setting in case we have them one day. I could see us forgetting about it and then the file doesn't get formatted properly, lol.

@@ -30,6 +53,20 @@ tasks:
lint-tasks.yml \
Taskfile.yml

clang-format:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just curious, is there a future plan to have this task moved into yscope-dev-utils and also have the venv setup task done from there?

Copy link
Member Author

Choose a reason for hiding this comment

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

I hadn't considered it, but yeah, it probably makes sense, especially now that we can specify maps/arrays as arguments to a task.

junhaoliao
junhaoliao previously approved these changes Oct 4, 2024
Copy link
Collaborator

@junhaoliao junhaoliao left a comment

Choose a reason for hiding this comment

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

Following the Validation steps in the PR description, validated by making lint violations and observing the violation by the lint:check / lint:cpp-check task. e.g.,

/path/to/clp-ffi-js/src/clp_ffi_js/ir/StreamReaderDataContext.hpp:30:56: error: code should be clang-formatted [-Wclang-format-violations]
              m_deserializer{std::move(deserializer)} {     }
                                                       ^
task: Failed to run task "lint:check": exit status 1

Running lint:fix or lint:cpp-fix fixed the violation inline.

The PR title is fine for the final message. If we're to upgrade clang-format in the near future, it might be good to mention the exact version in the title / message.

@kirkrodrigues kirkrodrigues changed the title Add tasks to perform C++ linting with clang-format. Add tasks to perform C++ linting with clang-format v18. Oct 5, 2024
@kirkrodrigues
Copy link
Member Author

If we're to upgrade clang-format in the near future, it might be good to mention the exact version in the title / message.

Sure, updated the title.

@kirkrodrigues kirkrodrigues merged commit 3457e37 into y-scope:main Oct 5, 2024
3 checks passed
@kirkrodrigues kirkrodrigues deleted the add-clang-format branch October 5, 2024 04:17
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.

2 participants