Add clang-format cmake targets and formatting script#81
Closed
th1000s wants to merge 1 commit intoDescentDevelopers:mainfrom
Closed
Add clang-format cmake targets and formatting script#81th1000s wants to merge 1 commit intoDescentDevelopers:mainfrom
th1000s wants to merge 1 commit intoDescentDevelopers:mainfrom
Conversation
fmt: formats all modified files (what `git status` lists) fmtall: all files known to git checkfmt: checks that all files are formatted correctly Warn if the version does not match the one specified by the GitHub action.
Contributor
|
The problem is that the formatter causes issues (there was a PR to fix invalid code generated by the formatter) so I think this should be rethought a bit, maybe only apply to newly added lines or similar... |
Jayman2000
added a commit
to Jayman2000/Descent3-pr
that referenced
this pull request
Jun 30, 2024
This new script has several advantages over the old one. First, it’s directly executable. The previous script did not use a shebang, so users would have to invoke “sh tools/formatter.sh”. This new script does include a shebang, so users can just run “tools/formatter.sh”. Second, it’s available under the same license as the rest of the repo. The previous version of the script was released under the MIT License, but since it’s a part of a larger GPL’d work, users would potentially have to comply with two licenses at the same time. This new script is available under the same license as the rest of the repo in order to make the licensing situation simpler. Third, it’s a little bit easier to read. The old script put globs for every possible file extension on a single line, and escaped them in an unusual way. Additionally, that line in the previous script contained more than just globs. It also contained the find command and the start of a for loop. This new script stores the globs in a variable in order to make the code easier to read by decreasing the amount of stuff that’s happening on a single line. The new script also makes things easier to read by using single quotes to escape globs instead multiple backslashes. It also makes things easier to read by decreasing the total number of globs (See the final point for details). Fourth, this new script is more lenient when it comes to the user’s current working directory. The previous script would only work properly if the user’s current working directory was the root directory of the Descent3 repo. This new script will work properly if the user’s current working directory is any directory that’s part of the Descent3 repo. Fifth, this new script can handle more filenames. The previous script would fail if characters like spaces appeared in the names of files. This new script will work even if filenames contain spaces, newlines, etc. There’s no files in the Descent3 repo that currently use those characters in their names, but it’s possible that there will be in the future. Sixth, this new script will ignore the same files that Git ignores. The previous script would process all files, even if they were ignored by Git. Seventh, this new script has slightly better code style. The previous script used tabs for indentation. This new script uses two spaces for indentation, just like .editorconfig says we should use. The previous script used semicolons at the end of lines. This new version doesn’t because semicolons are unnecessary in shell scripts. Eighth, this new script avoids truncating files. Apparently, part of the old script was truncating files [1]. Ninth, this new script is agnostic to the version of clang-format that’s installed on your system. The previous script required clang-format-16 in particular. Tenth, this new script respects the style settings in .clang-format. The previous script used “--style=LLVM” which prevents .clang-format from being loaded [2]. Finally, this new script is faster than the old one. For one thing, this new script doesn’t waste time looking for files that don’t exist. For example, the previous script would look for .java files because clang-format can format code written in Java [2]. This new script doesn’t bother looking for .java files because there aren’t any in the Descent3 repo. More importantly, the old script would run clang-format serially. This new script runs many instances of clang-format in parallel. There is a potential disadvantage to this script. It adds additional dependencies. Specifically, this new script depends on /bin/sh and git. That being said, users are highly likely to have both of those installed anyway, so it’s probably not a disadvantage in practices. At the same time, this new script also removes a dependency (the find command), so the upsides of this change almost certainly outweigh the downsides. [1]: <DescentDevelopers#81> [2]: <https://clang.llvm.org/docs/ClangFormat.html#standalone-tool> TODO: • Proofread commit message. • Test on Linux. • Test on Windows.
Jayman2000
added a commit
to Jayman2000/Descent3-pr
that referenced
this pull request
Jun 30, 2024
This new script has several advantages over the old one. First, it’s directly executable. The previous script did not use a shebang, so users would have to invoke “sh tools/formatter.sh”. This new script does include a shebang, so users can just run “tools/formatter.sh”. Second, it’s available under the same license as the rest of the repo. The previous version of the script was released under the MIT License, but since it’s a part of a larger GPL’d work, users would potentially have to comply with two licenses at the same time. This new script is available under the same license as the rest of the repo in order to make the licensing situation simpler. Third, it’s a little bit easier to read. The old script put globs for every possible file extension on a single line, and escaped them in an unusual way. Additionally, that line in the previous script contained more than just globs. It also contained the find command and the start of a for loop. This new script stores the globs in a variable in order to make the code easier to read by decreasing the amount of stuff that’s happening on a single line. The new script also makes things easier to read by using single quotes to escape globs instead multiple backslashes. It also makes things easier to read by decreasing the total number of globs (See the final point for details). Fourth, this new script is more lenient when it comes to the user’s current working directory. The previous script would only work properly if the user’s current working directory was the root directory of the Descent3 repo. This new script will work properly if the user’s current working directory is any directory that’s part of the Descent3 repo. Fifth, this new script can handle more filenames. The previous script would fail if characters like spaces appeared in the names of files. This new script will work even if filenames contain spaces, newlines, etc. There’s no files in the Descent3 repo that currently use those characters in their names, but it’s possible that there will be in the future. Sixth, this new script will ignore the same files that Git ignores. The previous script would process all files, even if they were ignored by Git. Seventh, this new script has slightly better code style. The previous script used tabs for indentation. This new script uses two spaces for indentation, just like .editorconfig says we should use. The previous script used semicolons at the end of lines. This new version doesn’t because semicolons are unnecessary in shell scripts. Eighth, this new script avoids truncating files. Apparently, part of the old script was truncating files [1]. Ninth, this new script is agnostic to the version of clang-format that’s installed on your system. The previous script required clang-format-16 in particular. Tenth, this new script respects the style settings in .clang-format. The previous script used “--style=LLVM” which prevents .clang-format from being loaded [2]. Finally, this new script is faster than the old one. For one thing, this new script doesn’t waste time looking for files that don’t exist. For example, the previous script would look for .java files because clang-format can format code written in Java [2]. This new script doesn’t bother looking for .java files because there aren’t any in the Descent3 repo. More importantly, the old script would run clang-format serially. This new script runs many instances of clang-format in parallel. There is a potential disadvantage to this script. It adds additional dependencies. Specifically, this new script depends on /bin/sh and git. That being said, users are highly likely to have both of those installed anyway, so it’s probably not a disadvantage in practices. At the same time, this new script also removes a dependency (the find command), so the upsides of this change almost certainly outweigh the downsides. [1]: <DescentDevelopers#81> [2]: <https://clang.llvm.org/docs/ClangFormat.html#standalone-tool> TODO: • Proofread commit message. • Test on Windows.
Jayman2000
added a commit
to Jayman2000/Descent3-pr
that referenced
this pull request
Jul 2, 2024
This new script has several advantages over the old one. First, it’s directly executable. The previous script did not use a shebang, so users would have to invoke “sh tools/formatter.sh”. This new script does include a shebang, so users can just run “tools/formatter.sh”. Second, it’s available under the same license as the rest of the repo. The previous version of the script was released under the MIT License, but since it’s a part of a larger GPL’d work, users would potentially have to comply with two licenses at the same time. This new script is available under the same license as the rest of the repo in order to make the licensing situation simpler. Third, it’s a little bit easier to read. The old script put globs for every possible file extension on a single line, and escaped them in an unusual way. Additionally, that line in the previous script contained more than just globs. It also contained the find command and the start of a for loop. This new script stores the globs in a variable in order to make the code easier to read by decreasing the amount of stuff that’s happening on a single line. The new script also makes things easier to read by using single quotes to escape globs instead multiple backslashes. It also makes things easier to read by decreasing the total number of globs (See the final point for details). Fourth, this new script is more lenient when it comes to the user’s current working directory. The previous script would only work properly if the user’s current working directory was the root directory of the Descent3 repo. This new script will work properly if the user’s current working directory is any directory that’s part of the Descent3 repo. Fifth, this new script can handle more filenames. The previous script would fail if characters like spaces appeared in the names of files. This new script will work even if filenames contain spaces, newlines, etc. There’s no files in the Descent3 repo that currently use those characters in their names, but it’s possible that there will be in the future. Sixth, this new script will ignore the same files that Git ignores. The previous script would process all files, even if they were ignored by Git. Seventh, this new script has slightly better code style. The previous script used tabs for indentation. This new script uses two spaces for indentation, just like .editorconfig says we should use. The previous script used semicolons at the end of lines. This new version doesn’t because semicolons are unnecessary in shell scripts. Eighth, this new script avoids truncating files. Apparently, part of the old script was truncating files [1]. Ninth, this new script is agnostic to the version of clang-format that’s installed on your system. The previous script required clang-format-16 in particular. Tenth, this new script respects the style settings in .clang-format. The previous script used “--style=LLVM” which prevents .clang-format from being loaded [2]. Finally, this new script is faster than the old one. For one thing, this new script doesn’t waste time looking for files that don’t exist. For example, the previous script would look for .java files because clang-format can format code written in Java [2]. This new script doesn’t bother looking for .java files because there aren’t any in the Descent3 repo. More importantly, the old script would run clang-format serially. This new script runs many instances of clang-format in parallel. There is a potential disadvantage to this script. It adds additional dependencies. Specifically, this new script depends on /bin/sh and git. That being said, users are highly likely to have both of those installed anyway, so it’s probably not a disadvantage in practices. At the same time, this new script also removes a dependency (the find command), so the upsides of this change almost certainly outweigh the downsides. [1]: <DescentDevelopers#81> [2]: <https://clang.llvm.org/docs/ClangFormat.html#standalone-tool>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fmt: formats all modified files (what
git statuslists)fmtall: all files known to git
checkfmt: checks that all files are formatted correctly
Warn if the version does not match the one specified by the GitHub action.
(the removed version looked at every file, and also truncated them because of
$file > $file)