Skip to content

Disable clang format for CLI code#2815

Closed
Lestropie wants to merge 2 commits intodevfrom
disable_clang_format_cli
Closed

Disable clang format for CLI code#2815
Lestropie wants to merge 2 commits intodevfrom
disable_clang_format_cli

Conversation

@Lestropie
Copy link
Member

@Lestropie Lestropie commented Feb 21, 2024

Partial reversion of #2652; though it's not "reverted" so much as replaced with manually formatted code.

Upon attempting to commence #2138 I found the reformatted usage() code so unbearable that I committed to refactoring all of the affected code.

I've tried to follow something resembling standards in terms of code formatting, including reducing text width even if column size isn't going to be enforced within these blocks of code. I also took the opportunity to tweak certain command documentation as I was going; shouldn't be anything controversial.

Could do with a fresh set of eyes over the manifest changes to the online command documentation just to be sure I've not broken anything.

When clang-format, introduced in #2652, applied its changes to MRtrix3 code relating to the command-line interface (particularly the way that options and their arguments are concatenated through the addition operator), the resulting code was often quite ugly. This commit replaces code relating to CLI configuration (both the usage() function in cmd/*.cpp, and in definitions of options and option groups utilised by multiple commands) with manually formatted code, and includes comment fields to disable further manipulation of that code by clang-format.
@Lestropie Lestropie self-assigned this Feb 21, 2024
@Lestropie
Copy link
Member Author

Line count is a little gratuitous; will need to refactor and put the bulk of changes under the MRtrixBot account.

@daljit46
Copy link
Member

daljit46 commented Feb 21, 2024

LGTM, modulo the fact that sometimes you've missed a space in // clang-format off. I also recommend installing pre-commit locally and then run pre-commit install in the source directory to install a git hook that will catch if you have code that is not formatted (alternatively you can run python clang-format-all -e clang-format-16 after you made a commit and ensure that no file changes).

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 25 out of 91. Check the log or trigger a new build to see more.

Argument("option").type_choice(file_outputs)
+ Option ("files", "select how the resulting streamlines will be grouped in output files."
" Options are: per_edge, per_node, single (default: per_edge)")
+ Argument ("option").type_choice (file_outputs)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

      + Argument ("option").type_choice (file_outputs)
                                         ^

+ Argument ("input", "the input connectome.").type_text ()

+ Argument ("operation", "the operation to apply,"
" one of: " + join(operations, ", ") + ".").type_choice (operations)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

                           " one of: " + join(operations, ", ") + ".").type_choice (operations)
                                              ^

+ Argument ("input", "the input connectome.").type_text ()

+ Argument ("operation", "the operation to apply,"
" one of: " + join(operations, ", ") + ".").type_choice (operations)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

                           " one of: " + join(operations, ", ") + ".").type_choice (operations)
                                                                                    ^

join(algorithms, ", "))
.type_choice(algorithms)
+ Argument ("algorithm", "the algorithm to use in network-based clustering/enhancement."
" Options are: " + join(algorithms, ", ")).type_choice (algorithms)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

                           " Options are: " + join(algorithms, ", ")).type_choice (algorithms)
                                                   ^

join(algorithms, ", "))
.type_choice(algorithms)
+ Argument ("algorithm", "the algorithm to use in network-based clustering/enhancement."
" Options are: " + join(algorithms, ", ")).type_choice (algorithms)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

                           " Options are: " + join(algorithms, ", ")).type_choice (algorithms)
                                                                                   ^

+ Option ("transform", "transform vertices from one coordinate space to another,"
" based on a template image;"
" options are: " + join(transform_choices, ", "))
+ Argument ("mode").type_choice (transform_choices)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument ("mode").type_choice (transform_choices)
                                     ^

Argument("output", "the output mesh file").type_file_out();
+ Argument ("input", "the input mesh file").type_file_in()
+ Argument ("filter", "the filter to apply;"
" options are: smooth").type_choice (filters)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

                        " options are: smooth").type_choice (filters)
                                                             ^

"- 'mean': unbiased but loss of resolution for individual images possible; "
"- 'max': smallest voxel size of any input image defines the resolution."
" Default: mean")
+ Argument ("type").type_choice (resolution_choices)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument ("type").type_choice (resolution_choices)
                                     ^

colourmap_choices_std.push_back(lowercase(entry->name));
++entry;
} while (entry->name);
} while(entry->name);

Choose a reason for hiding this comment

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

warning: implicit conversion 'const char *' -> bool [readability-implicit-bool-conversion]

Suggested change
} while(entry->name);
} while(entry->name != nullptr);

" appropriate for images acquired using 2D stack-of-slices approaches."
" The 3d mode corresponds to the 3D volume-wise extension proposed by Bautista et al.,"
" which is appropriate for images acquired using 3D Fourier encoding.")
+ Argument ("type").type_choice(modes)

Choose a reason for hiding this comment

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

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

    + Argument ("type").type_choice(modes)
                                    ^

@Lestropie
Copy link
Member Author

I've put off installing the pre-commit hook / format on save because there's a lot of branches that I still need to explicitly transition from pre-clang-format code. I do however need to get into the habit of running it explicitly. Not so concerned on commits like this one; it's moreso not wanting 200 clang-format-related commits on 100 different branches all making their way into the history.

Lestropie added a commit that referenced this pull request Feb 26, 2024
Refinements to command documentation as discovered during the generation of 0cec87a as part of #2815. Here the changes to the command documentation has been separated from the changes relating to the disabling of clang-format for CLI-relevant code.
Lestropie pushed a commit that referenced this pull request Feb 26, 2024
When clang-format, introduced in #2652, applied its changes to MRtrix3 code relating to the command-line interface (particularly the way that options and their arguments are concatenated through the addition operator), the resulting code was often quite ugly. This commit replaces code relating to CLI configuration (both the usage() function in cmd/*.cpp, and in definitions of options and option groups utilised by multiple commands) with manually formatted code, and includes comment fields to disable further manipulation of that code by clang-format.
This commit is a refactor of 0cec87a generated as part of #2815, with the changes being to omit other modifications to the command documentation that are not directly related to clang-format (those changes are in the parent commit to this commit: 15e253c), and to change authorship of the commit.
@Lestropie
Copy link
Member Author

Replaced by #2818.

@Lestropie Lestropie closed this Feb 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants