Skip to content

chore: fix doxygen formatting #289

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

Merged
merged 6 commits into from
Jan 8, 2024
Merged

Conversation

vishwa2710
Copy link
Contributor

@vishwa2710 vishwa2710 commented Dec 1, 2023

Because of how our doxygen comments are formatted, they don't appear as tooltips with autocompletion in VSCode, nor when you hover over the functions etc.

Now, when we write code we can get these tool tips:

Screen Shot 2023-11-30 at 4 34 53 PM

I used the following script to batch update all the files in the repo to follow the proper format.

import os
import glob
import re

# Get a list of all header files in the repository
header_files = glob.glob(os.path.join(".", "**/*.hpp"), recursive=True)

# Regular expression to match function definitions and their preceding docstrings
license_pattern = re.compile(r"\/{3} Apache.*", re.MULTILINE)
pattern = re.compile(r".*\/{3}.*", re.MULTILINE)
next_line_pattern = re.compile(r"^\s$")
extra_space_pattern = re.compile(r"\/{3}\s{18}")

for header_file in header_files:
    with open(header_file, "r") as file:
        content = file.readlines()

    # Process each line
    new_content = []
    skip_next_line = False
    for i in range(len(content)):
        if skip_next_line:
            skip_next_line = False
            continue

        line = content[i]

        if license_pattern.match(line):
            new_content.append(line)
            continue

        line = re.sub(r"@brief\s{,18}", "@brief ", line)
        line = re.sub(r"@param\s{,18}", "@param ", line)
        line = re.sub(r"\[in\] ", "", line)
        line = re.sub(r"@return\s{,18}", "@return ", line)
        line = re.sub(r"///\s{8}", "/// ", line)
        line = re.sub(r"@code", "@code{.cpp}", line)
        next_line = content[i + 1] if i + 1 < len(content) else ""

        # Check if the current and next line match the pattern
        if pattern.match(line) and next_line_pattern.match(next_line):
            new_content.append(
                line.rstrip() + "\n"
            )  # Remove trailing spaces and add one newline
            skip_next_line = (
                True  # Skip the next line as it is part of the matched pattern
            )
        else:
            new_content.append(line)

    # Write the modified content back to the file
    with open(header_file, "w") as file:
        file.writelines(new_content)

@vishwa2710 vishwa2710 self-assigned this Dec 1, 2023
Copy link

codecov bot commented Dec 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (bf8bd6d) 86.21% compared to head (7a00aa1) 86.21%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #289   +/-   ##
=======================================
  Coverage   86.21%   86.21%           
=======================================
  Files          74       74           
  Lines        6491     6491           
=======================================
  Hits         5596     5596           
  Misses        895      895           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@Derollez Derollez left a comment

Choose a reason for hiding this comment

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

Awesome! Let's merge and apply to other folders (sharing the load)?

@vishwa2710 vishwa2710 force-pushed the users/vishwa/fix-comment-formatting branch from ca94d15 to cb50a4e Compare January 3, 2024 01:06
@vishwa2710 vishwa2710 force-pushed the users/vishwa/fix-comment-formatting branch from 63f8be8 to 8eeb76b Compare January 4, 2024 03:59
@vishwa2710 vishwa2710 force-pushed the users/vishwa/fix-comment-formatting branch from 8eeb76b to 7a00aa1 Compare January 8, 2024 07:45
@vishwa2710 vishwa2710 enabled auto-merge (squash) January 8, 2024 07:46
@vishwa2710 vishwa2710 merged commit 785fbb5 into main Jan 8, 2024
@vishwa2710 vishwa2710 deleted the users/vishwa/fix-comment-formatting branch January 8, 2024 08:03
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.

3 participants