Repository navigation
feat: add scrap format - #144
Merged
Merged
Conversation
A format never reads the file back, so it no longer returns the failure of a check that could not read it.
The project is searched for from the first path, or from the directory holding it when it names a file. Every path is resolved through the filesystem, so a path spelled in another letter case where case is ignored, or through a link, names the file it reaches. A path that names nothing, or that lies in another project, is reported.
scrap format [<path>...] formats in place, with the clang-format found on PATH, the files of the project that the paths name, or all of them. The clang-format used is named with its version first. A named file the command does not cover is left out with a warning. A file clang-format fails on is reported with what clang-format wrote, and the other files are still formatted.
Each kind of failure has its own renderer, chosen with std::visit, so a kind added without one fails the build. The failures of clang-format share one renderer that takes the name of the tool, and the line for an empty path argument is written in one place.
scrap names the clang-format it found by the directory PATH lists. On macOS the temporary directory is reached through a symbolic link, so a canonical path is not what scrap names.
A named directory that holds nothing scrap format covers is left out with a warning, as a named file it does not cover is, so a format that had nothing to do there does not pass in silence.
When clang-format fails and writes nothing, the failure says the status it exited with, the one thing left to tell why.
A path argument that cannot be examined is shown as it was typed, as a path that names nothing already is, not joined to the working directory.
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.
Summary
Adds
scrap format [<path>...], which formats in place, with theclang-formatfound onPATH, the files of the project that the paths name, or all of them.--checkcomes in a later change.filesToFormatandselectFiles. A named file outside them is left out with a warning, and so is a named directory below which none of them lie. When nothing is left, the command exits with 0 without looking for clang-format. A project with no target still has its files belowsrc/andinclude/formatted.PATH, and named with its version before any file is formatted. When there is none:styleof[format]is passed to--styleas written.error: failed to format 'src/a.cpp': clang-format exited with status 1.formatFileno longer returns the failure of a check that could not read the file back, which onlycheckFilecan meet, so the command handles only what a format can return. Each kind of failure is rendered by its own function, chosen withstd::visit, so a kind added without one fails the build.The README describes the command and
[format].Tests
ProjectPathsTest, 12 tests: where the search starts for a file and a directory, the root named as a directory, a path that names nothing (first or later, through.., or below a file), a path that cannot be examined, an empty path, a project that cannot be found, a path in a nested project and outside any project, a symbolic link, and a path in another letter case. The last one runs only on a file system that ignores case.ProjectPathsTextTest, 6 tests, andFormatTextTest, 8 tests: the messages above, a signal, an exit status with nothing written, a clang-format that could not be started or did not give its version, and escaping what clang-format wrote.FileSelectionTest, 1 more test: a named directory that selects nothing is listed once, in the order named.CliE2ETest, 11 tests. Eight run a script that stands in for clang-format onPATH: formatting the project and leaving out a file outside it, named files and directories, a named directory that holds nothing to format, a path that names nothing, passing the style, an unknown key in[format], no clang-format, a failing file followed by the next, and a clang-format that cannot be started. Three run the clang-format of thePATHthe tests run with, and skip when there is none: following.clang-format, following the style ofscrap.tomlinstead, and a style clang-format rejects. In the checks of this pull request they ran on the Linux jobs of build-and-test and on diff-coverage, and skipped on macOS and in the package jobs.Each of these fails at least one test when taken out: starting the search from the directory of a file, the check that later paths are in the project, resolving paths through the file system, treating a path below a file as naming nothing, reporting a path that cannot be examined as given, listing a directory that selects nothing and its warning, the exit status with nothing written, going on after a failed file, the warning, passing the style, the exit without clang-format when nothing is left, stopping at a clang-format that cannot be started, the line naming clang-format, and going on to the next file after one is formatted.