diff options
| author | Seiichi Uchida <seuchida@gmail.com> | 2020-07-10 11:23:12 +0900 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2021-09-14 21:22:26 -0500 |
| commit | d4ffd1efa4c83084f05f6e83585ae0a70450bcfd (patch) | |
| tree | d44f5cb3e989ba0a9eb6c1fef730ec807fac96f3 /src/test | |
| parent | 67a59f6ee35c3cfd75e2aab5a8475608e167840b (diff) | |
Support @generated marker to skip code formatting
This is a copy of #4296 with these changes: * file is not reopened again to find if the file is generated * first five lines are scanned for `@generated` marker instead of one * no attempt is made to only search for marker in comments `@generated` marker is used by certain tools to understand that the file is generated, so it should be treated differently than a file written by a human: * linters should not be invoked on these files, * diffs in these files are less important, * and these files should not be reformatted. This PR proposes builtin support for `@generated` marker. I have not found a standard for a generated file marker, but: * Facebook [uses `@generated` marker](https://tinyurl.com/fb-generated) * Phabricator tool which was spawned from Facebook internal tool [also understands `@generated` marker](https://git.io/JnVHa) * Cargo inserts `@generated` marker into [generated Cargo.lock files](https://git.io/JnVHP) My personal story is that rust-protobuf project which I maintain was broken twice because of incompatibilities/bugs in rustfmt marker handling: [one](https://github.com/stepancheg/rust-protobuf/issues/493), [two](https://github.com/stepancheg/rust-protobuf/issues/551). (Also, rust-protobuf started generating `@generated` marker [6 years ago](https://git.io/JnV5h)). While rustfmt AST markers are useful to apply to a certain AST elements, disable whole-file-at-once all-tools-at-once text level marker might be easier to use and more reliable for generated code.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/test/mod.rs b/src/test/mod.rs index cb52346a13a..ece1b91bfd7 100644 --- a/src/test/mod.rs +++ b/src/test/mod.rs @@ -694,7 +694,7 @@ fn read_significant_comments(file_name: &Path) -> HashMap<String, String> { reader .lines() .map(|line| line.expect("failed getting line")) - .take_while(|line| line_regex.is_match(line)) + .filter(|line| line_regex.is_match(line)) .filter_map(|line| { regex.captures_iter(&line).next().map(|capture| { ( |
