15 Commits

Author SHA1 Message Date
Seiichi Uchida
d4ffd1efa4 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.
2021-09-14 21:22:26 -05:00
Matthias Krüger
4c2959fb12 fix a bunch of clippy warnings
clippy::bind_instead_of_map
clippy::branches_sharing_code
clippy::collapsible_match
clippy::inconsistent_struct_constructor
clippy::int_plus_one
clippy::iter_count
clippy::iter_nth_zero
clippy::manual_range_contains
clippy::match_like_matches_macro
clippy::needless::collect
clippy::needless_question_mark
clippy::needless_return
clippy::op_ref
clippy::option_as_ref_deref
clippy::ptr_arg
clippy::redundant_clone
clippy::redundant_closure
clippy::redundant_static_lifetimes
clippy::search_is_some
clippy::#single_char_add_str
clippy::single_char_pattern
clippy::single_component_path_imports
clippy::single_match
clippy::skip_while_next
clippy::unnecessary_lazy_evaluations
clippy::unnecessary_unwrap
clippy::useless_conversion
clippy::useless_format
2021-07-25 22:53:32 -05:00
Ruben Schmidmeister
821a370417
Add tests to cover more edge cases 2019-05-09 17:51:02 +02:00
Ruben Schmidmeister
1f09d94cbb
Make sure windows newlines don't gain an extra carriage return 2019-05-09 17:44:52 +02:00
Ruben Schmidmeister
f54fc2f2fc
Implement conversion to unix newlines 2019-05-09 17:22:16 +02:00
Ruben Schmidmeister
7556c420ab
Use more descriptive names 2019-04-24 21:58:50 +02:00
Ruben Schmidmeister
19bd1a44ce
Preserve standalone carriage returns on windows also 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
2e77f2bca7
Split apply with auto detection tests into separate fns 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
0f1d5760ba
Fix auto detection of windows newlines for inputs with multibyte chars 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
20c8d8aabc
Split auto_detect tests into seperate fns 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
764cdf60fa
Extract conversion to windows newlines into fn 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
58d7b2cc66
Extract literals into constants 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
add473667a
Introduce effective newline style 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
8849273efb
Convert to free standing functions 2019-04-24 21:01:09 +02:00
Ruben Schmidmeister
ba5b2e9c9b
Extract applying of newline style into own mod 2019-04-24 21:01:09 +02:00