rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.49k stars 1.55k forks source link

Overindented lines lint (similar to `doc_lazy_continuation`) #13601

Open ojeda opened 1 month ago

ojeda commented 1 month ago

What it does

The lint reports overindented lines, for instance in bullet lists (and potentially elsewhere?).

This could perhaps be considered a false negative of doc_lazy_continuation, but "lazy continuation lines" only cover removing indentation, not adding it.

Advantage

The advantages would be similar to doc_lazy_continuation:

Drawbacks

No response

Example

/// - a
///    b
pub fn f() {}

Could be written as:

/// - a
///   b
pub fn f() {}
ohno418 commented 3 weeks ago

Just a quick report for future work.

I was working on this for a bit, and found some difficulties in automatically applying this rule.

For example, doc like

/// - First line. Here's an sample object:
///   {
///      'protocol': 25,
///      'data': 0xffff
///   }
/// - Second line.

would be fixed into:

/// - First line. Here's an sample object:
///   {
///   'protocol': 25,
///   'data': 0xffff
///   }
/// - Second line.

Similar UI test exists here: https://github.com/rust-lang/rust-clippy/blob/ccf7c88386be0f4bfd13bac2ffb616e09c033e55/tests/ui/doc/doc_lazy_list.rs#L54-L76

ojeda commented 3 weeks ago

Thanks for taking a look!

For example, doc like

If I understand correctly, that doc is wrong but for other reasons, which makes it hard to offer fixes for; i.e. it should be e.g.

/// - First line. Here's an sample object:
///   ```json
///   {
///      'protocol': 25,
///      'data': 0xffff
///   }
///   ```
/// - Second line.

In any case, please note that even if the lint does not offer fixes (automatic or not), it would still be valuable to have it!

For instance, here it would have detected that broken documentation text.

ohno418 commented 2 weeks ago

doc is wrong but for other reasons

Yeah, you're right. So, it seems like doc in tests/ui/doc/doc_lazy_list.rs test is also wrong, and we should modify it together.

In any case, please note that even if the lint does not offer fixes (automatic or not), it would still be valuable to have it!

Agreed.

I'll probably take another look later. Thanks!

ojeda commented 2 weeks ago

Yeah, that last example in tests/ui/doc/doc_lazy_list.rs looks broken to me; however, it seems it was added to test for an ICE (from the comment linked there), i.e. it may be intentionally broken, which would be fine since it is a test. Thanks!