1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
[]
= "commented"
= "If you want to comment a line for an unknown file type, this crate is what you want"
= "0.1.0"
= "2024"
= ["Nik Revenco <pm@nikrev.com>"]
= "https://github.com/"
= "MIT OR Apache-2.0"
= ["comment"]
= []
[]
= ["dep:globset"]
[]
= [".", "script"]
= ["."]
[]
= { = "0.4.16", = true }
# ============================
#
# Lints
#
# - strict set of lints for a
# more consistent codebase
#
# - delegate as much as possible
# to automated tooling
#
# ============================
[]
# do not import if its already in scope
# e.g. `use std::option::Option::None`
= "warn"
# Documentation for all public items
= "warn"
# `foo::bar::baz` => `bar::baz` if `bar` is in scope
= "warn"
# detects rules of macros that weren't used
= "warn"
# lints against e.g. undefined meta variables
= "warn"
# all types must `#[derive(Copy)]`
= "warn"
# all types must `#[derive(Debug)]`
= "warn"
[]
= { = -1, = "warn" }
# --- more consistent ways of writing code
#
# `if $a { Some($b) } else { None }` => `$a.then(|| $b)`
= "warn"
# `use Trait` => `use Trait as _`
= "warn"
# `foo.rs` => `foo/mod.rs`
= "warn"
# omit `test_` prefix in tests: `fn test_foo` => `fn foo`
= "warn"
# `123832i64` => `123832_i64`
= "warn"
# `Foo { a: _, b: 0, .. }` => `Foo { b: 0, .. }`
# do not bind unused by `_` when pattern matching, bind by `..` instead
= "warn"
# `Err(x)?` => `return Err(x)`
= "warn"
# `#[test] fn` must be in `#[cfg(test)]`
= "warn"
# functions ending in `.and_then` could be better expressed as `?`
= "warn"
# `match (A { a }) { A { a, .. } => () }` => `match (A { a: 5 }) { A { a } => () }`
= "warn"
# do not use differing names from the trait itself when implementing its method
= "warn"
# `0x2345 & 0xF000 >> 12` => `0x2345 & (0xF000 >> 12)`
= "warn"
# omitting type annotations make code easier to modify
= "warn"
# `assert!(r.is_ok())` => `r.unwrap()`
= "warn"
# `fs::read_to_string` requires much less steps than `File::read_to_string`
= "warn"
# `use std::io::{self}` => `use std::io`
= "warn"
# do not lose type information about NonZero numbers
= "warn"
# exit obscures flow of the program
= "warn"
# no need for a `SAFETY:` comment on safe code
= "warn"
# each `unsafe` block must contain only 1 unsafe operation
= "warn"
# ---
# --- explain more things
#
# `#[allow]` => `#[allow, reason = "why"]`
= "warn"
# `unsafe` blocks need a `SAFETY:` comment
= "warn"
# `.unwrap()` => `.expect("why")`
= "warn"
# `arr[4]` => `arr.get(4).expect("why")`
= "warn"
# `assert!(...)` => `assert!(..., "why")`
= "warn"
# documentation for everything
= "warn"
# `path_buf.push("foo")` => `... = PathBuf::new().join("foo")`
= "warn"
# explicitly mark return type as `!` for infinite loop fns
= "warn"
# ---
# --- catch debug remnants
#
= "warn"
= "warn"
= "warn"
= "warn"
# explicitly `#[allow]` functions to print to stdout
= "warn"
# explicitly `#[allow]` functions to print to stderr
= "warn"
# ---
# --- prevent bugs
# new variants added by libraries become errors
# instead of being silently ignored
= "warn"
# if function and trait provide method of same name, it is confusing
= "warn"
# `create_dir(...)` => `create_dir_all(...)`
# usually, failing when dir already exists is
# not what we want
= "warn"
# ---
# --- allowed lints
#
# `$a * $b + $c` is slower and less precise than `$a.mul_add($b, $c)`
# but it is more readable, the gain in speed / precision
# will be negligible in most situations
= "allow"
# arbitrary limit imposes unnecessary
# restriction and can make code harder to follow
= "allow"
# if we need it const, make it const.
# no need to make everything that can be const, const
= "allow"
# ---