Commit Graph

301 Commits

Author SHA1 Message Date
bors
5c6fe68c00 Auto merge of #13376 - decryphe:source-ordering, r=llogiq
new lint: `source_item_ordering`

changelog: [`source_item_ordering`]: Introduced a new restriction lint that checks the ordering of items in Modules, Enums, Structs, Impls and Traits.

From the written documentation:

> Why restrict this?
> Keeping a consistent ordering throughout the codebase helps with working as a team, and possibly improves maintainability of the codebase. The idea is that by defining a consistent and enforceable rule for how source files are structured, less time will be wasted during reviews on a topic that is (under most circumstances) not relevant to the logic implemented in the code. Sometimes this will be referred to as "bike-shedding".
>
> Keep in mind, that ordering source code alphabetically can lead to reduced performance in cases where the most commonly used enum variant isn't the first entry anymore, and similar optimizations that can reduce branch misses, cache locality and such. Either don't use this lint if that's relevant, or disable the lint in modules or items specifically where it matters. Other solutions can be to use profile guided optimization (PGO), or other advanced optimization methods.

I tried to build it as configurable as possible, as such a highly opinionated lint should be adjustable to personal opinions.

I'm open to any input and will be available both here and on the zulip for communication. In the meantime I'll be testing this lint against my own code-bases, which I've (manually) kept ordered with the default config, to see how well it works in practice.

And lastly, a big thanks to the community for making clippy the best linter there is!
2024-11-02 11:03:30 +00:00
chrysn
bd4aa170ef Add 'CoAP' to doc-valid-idents 2024-10-30 12:57:24 +01:00
decryphe
f7ab2c9908 new lint: source_item_ordering 2024-10-30 10:03:16 +01:00
Robert Spencer
acc3842d43 Add new map_with_unused_argument_over_ranges lint
This lint checks for code that looks like
```rust
  let something : Vec<_> = (0..100).map(|_| {
    1 + 2 + 3
  }).collect();
```
which is more clear as
```rust
  let something : Vec<_> = std::iter::repeat_with(|| {
    1 + 2 + 3
  }).take(100).collect();
```
or
```rust
  let something : Vec<_> =
      std::iter::repeat_n(1 + 2 + 3, 100)
      .collect();
```

That is, a map over a range which does nothing with the parameter
passed to it is simply a function (or closure) being called `n`
times and could be more semantically expressed using `take`.
2024-10-29 21:32:00 +00:00
Samuel Tardieu
f152bcb72e Update the number of lints (over 700 → over 750) 2024-10-28 09:21:07 +01:00
bors
c2534dcc49 Auto merge of #13460 - ROMemories:feat/freq-units-allowed-idents, r=Centri3
Add units/unit prefixes of frequency to doc-valid-idents

These units/unit prefixes often come up in the embedded world.

Should this PR also modify the `test_units` test? It seems only concerned with data units currently; should it also test frequency units?

changelog: [`doc_markdown`]: Add MHz, GHz, and THz to `doc-valid-idents`.
2024-10-24 08:50:36 +00:00
GnomedDev
979e297189
Update book 2024-10-13 21:17:03 +01:00
GnomedDev
26994e2519
Reduce default 'large array' threshold 2024-10-04 19:07:40 +01:00
Yuri Astrakhan
73a16c10db Suggest Option<&T> instead of &Option<T> 2024-09-28 11:57:34 -04:00
ROMemories
62026c3228 Add units/unit prefixes of frequency to doc-valid-idents 2024-09-26 10:07:10 +02:00
Ruairidh Williamson
05ebce8e1a
Add lint unused_trait_names 2024-09-21 00:56:38 +01:00
Alex Macleod
a22ce2d005 Remove HashSets from Conf 2024-08-12 20:24:47 +00:00
Alex Macleod
182cd5f278 Replace the metadata collector with tests 2024-08-12 20:24:46 +00:00
Jason Newcomb
7422202ca5 Add missing default values 2024-07-27 23:34:16 -04:00
Jason Newcomb
84dc56923b Add docs for await_holding_invalid_types 2024-07-27 18:17:26 -04:00
xFrednet
e34db99b2e
Update version attribute for 1.80 lints 2024-07-18 20:13:39 +02:00
Jason Newcomb
e34c6dbae5 Refactor for using config values:
* Construct lint passes by taking `Conf` by reference.
* Use `HashSet` configs in less places
* Move some `check_crate` code into the pass constructor when possible.
2024-07-17 14:05:49 -04:00
Bruce Mitchener
39378cf4f4 Add more doc-valid-idents
* "AccessKit" is a commonly used accessibility toolkit used in Rust GUIs.
* "CoreFoundation", "CoreGraphics", "CoreText" are frameworks on Apple OSes.
* "Direct2D", "Direct3D", "DirectWrite" are frameworks on Windows
* "PostScript" is a programming language and is mentioned when talking about
  text and vector graphics.
* "OpenAL" is an audio framework / API.
* "OpenType" is a font format (TrueType is already mentioned).
* "WebRTC", "WebSocket", "WebTransport" are web networking technologies.
* "NetBSD" and "OpenBSD" are like the already included FreeBSD.
2024-07-13 15:50:29 +07:00
Philipp Krones
ae47b97655
needless-pass-by-ref-mut: Update conf documentation 2024-07-03 09:53:05 +02:00
Kornel
eb33c1ac74
Image-related valid idents 2024-06-29 12:18:09 +01:00
Philipp Krones
e9e7a815a7
Merge remote-tracking branch 'upstream/master' into rustup 2024-06-27 18:49:59 +02:00
Reilly Tucker Siemens
80b25b4c82
Fix doc_markdown DevOps false positive 2024-06-26 15:22:38 -07:00
xFrednet
1b4c281fe7 RFC 2383: Stabilize lint_reasons in Clippy 🖇️ 2024-06-25 17:50:48 +02:00
bors
6172178d22 Auto merge of #12938 - elijah-potter:patch-1, r=flip1995
Fix minor typo

changelog: none
2024-06-17 08:35:44 +00:00
Elijah Potter
bcc7b0e700 Fix minor typo 2024-06-15 13:59:35 -06:00
AurelienFT
63388cbab8 add MSRV for manual_pattern_char_comparison 2024-06-15 21:45:35 +02:00
Philipp Krones
3bff119f63 Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-subtree-update 2024-06-13 12:30:48 +02:00
Renato Lochetti
9173c58e68
Using Clippy as a proper noun when refering to the unique entity Clippy 2024-06-03 20:46:05 +01:00
Philipp Krones
f67f72695a Merge commit 'c9139bd546d9cd69df817faeab62c5f9b1a51337' into clippy-subtree-update 2024-05-30 10:49:05 +02:00
finga
e61288cbf0 book: Fix example code
Fix example code of the "Disabling evaluation of certain code" section
in the configuration chapter.
2024-05-25 21:36:49 +02:00
Kevin Reid
0f5338cd90 For restriction lints, replace “Why is this bad?” with “Why restrict this?”
The `restriction` group contains many lints which are not about
necessarily “bad” things, but style choices — perhaps even style choices
which contradict conventional Rust style — or are otherwise very
situational. This results in silly wording like “Why is this bad?
It isn't, but ...”, which I’ve seen confuse a newcomer at least once.

To improve this situation, this commit replaces the “Why is this bad?”
section heading with “Why restrict this?”, for most, but not all,
restriction lints. I left alone the ones whose placement in the
restriction group is more incidental.

In order to make this make sense, I had to remove the “It isn't, but”
texts from the contents of the sections. Sometimes further changes
were needed, or there were obvious fixes to make, and I went ahead
and made those changes without attempting to split them into another
commit, even though many of them are not strictly necessary for the
“Why restrict this?” project.
2024-05-23 15:51:33 -07:00
Daniel Sedlak
c342a61564 Add configuration option for ignoring panic!() in tests 2024-05-16 05:45:56 +00:00
y21
9747c80644 new lint: macro_metavars_in_unsafe 2024-05-12 17:03:30 +02:00
J-ZhengLi
46659acdbd add configuration to allow skipping on some certain traits & collect metadata 2024-05-12 22:13:17 +08:00
bors
d8e76ecaf1 Auto merge of #12596 - ARandomDev99:issue-12595, r=Alexendoo
Modify lint pass note for consistency with the book

This PR:
- removes the note which appears when an early lint pass is created using `cargo dev new_lint`.
- adds a note that encourages contributors to use an early pass unless type information is needed if a late lint pass is created using `cargo dev new_lint`.

Late pass remains the default value if no pass is specified as most lints use late pass.

Closes #12595

changelog: none
2024-04-30 12:51:27 +00:00
Andre Bogus
87efce4fa2 configurably allow useless_vec in tests
This adds a `àllow-useless-vec-in-test` configuration which, when set
to `true` will allow the `useless_vec` lint in `#[test]` functions and
code within `#[cfg(test)]`. It also moves a `is_in_test` helper to
`clippy_utils`.
2024-04-28 22:07:56 +02:00
Aneesh Kadiyala
e2861d5652 Encourage using LateLintPass 2024-04-29 00:30:23 +05:30
Alex Macleod
f7aef635c1 Rework interior mutability detection 2024-04-18 17:33:39 +00:00
Alex Macleod
1fff3bef4d Add cargo dev setup toolchain 2024-04-16 18:28:07 +00:00
bors
832fdb6d30 Auto merge of #12573 - modelflat:recognize-common-prepositions-in-module-name-repetitions, r=Jarcho
[`module_name_repetition`] Recognize common prepositions

Fixes #12544

changelog: [`module_name_repetition`]: don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`). Prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
2024-04-12 18:53:03 +00:00
Philipp Krones
23225e15d0
Consistent lint group table in book and README
The lint table and the restriction group description was improved in #10385,
but only in the README. Apply the same changes to the book.
2024-04-09 10:48:29 +02:00
modelflat
3705073a71 Recognize common prefixes when checking for items with module name suffix
Fixes #12544.

- don't report an item name if it consists only of a prefix from `allowed-prefixes` list and a module name (e.g. `AsFoo` in module `foo`).
- configured by `allowed-prefixes` config entry
- prefixes allowed by default: [`to`, `from`, `into`, `as`, `try_into`, `try_from`]
- update docs
2024-04-09 09:47:54 +02:00
Philipp Krones
277303b210
Merge remote-tracking branch 'upstream/master' into rustup 2024-04-04 19:48:31 +02:00
Francisco Salgueiro
b6486fae5c
add missing links in development guide 2024-04-03 17:07:12 +01:00
bors
cebf879de8 Auto merge of #12312 - pitaj:legacy_numeric_constants, r=xFrednet
new lint `legacy_numeric_constants`

Rework of #10997

- uses diagnostic items
- does not lint imports of the float modules (`use std::f32`)
- does not lint usage of float constants that look like `f32::MIN`

I chose to make the float changes because the following pattern is actually pretty useful
```rust
use std::f32;
let omega = freq * 2 * f32::consts::PI;
```
and the float modules are not TBD-deprecated like the integer modules.

Closes #10995

---

changelog: New lint [`legacy_numeric_constants`]
[#12312](https://github.com/rust-lang/rust-clippy/pull/12312)
2024-03-30 17:50:36 +00:00
bors
13ef8457be Auto merge of #12481 - xFrednet:add-team-docs, r=flip1995
RFC: Document Clippy's teams and team duties

First the big announcement:

**We want to add a new subteam for regular contributors to give them triage rights.**

---

This PR adds a new section to the book which describes the Clippy and Clippy-Contributor teams, with their duties and membership requirements. This is just an initial draft, that outlines what, I think, their responsibilities should be.

I hope everyone in the team is okay with me posting this directly to GitHub. I think a PR makes collaboration a bit easier.

[🖼️ Rendered 🖼️](https://github.com/xFrednet/rust-clippy/blob/add-team-docs/book/src/development/the_team.md)

---

Once we've decided on this document, I'll create a PR to add the new team on GitHub. As part of this, we'll also reach out to some active contributors, to ask if they would like to join the new team.

---

cc: `@rust-lang/clippy`

cc: #6627

changelog: none

r? `@flip1995`
2024-03-26 09:01:41 +00:00
León Orell Valerian Liehr
b7026f87f5 Update (doc) comments
Several (doc) comments were super outdated or didn't provide enough context.

Some doc comments shoved everything in a single paragraph without respecting
the fact that the first paragraph should be a single sentence because rustdoc
treats these as item descriptions / synopses on module pages.
2024-03-22 06:31:51 +01:00
Catherine
0c392d918a new lint legacy_numeric_constants 2024-03-21 17:10:02 -06:00
Philipp Krones
0e62b18435 Merge commit '9d6f41691ed9dbfaec2a2df2661c42451f2fe0d3' into clippy-subtree-update 2024-03-21 22:20:40 +01:00
humannum14916
7c0b2dd352 Add assigning_clones to MSRV config option docs 2024-03-19 17:12:16 -04:00