Skip to content

Commit 1edac66

Browse files
committed
Document lint configuration values in Clippy's book
Signed-off-by: Tyler Weaver <maybe@tylerjw.dev>
1 parent d43dce1 commit 1edac66

File tree

6 files changed

+121
-6
lines changed

6 files changed

+121
-6
lines changed

.github/workflows/remark.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ jobs:
3333
echo `pwd`/mdbook >> $GITHUB_PATH
3434
3535
# Run
36+
- name: cargo collect-metadata
37+
run: cargo collect-metadata
38+
3639
- name: Check *.md files
3740
run: git ls-files -z '*.md' | xargs -0 -n 1 -I {} ./node_modules/.bin/remark {} -u lint -f > /dev/null
3841

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ disallowed-names = ["toto", "tata", "titi"]
199199
See the [list of configurable lints](https://rust-lang.github.io/rust-clippy/master/index.html#Configuration),
200200
the lint descriptions contain the names and meanings of these configuration variables.
201201

202+
See [table of lint configurations](https://doc.rust-lang.org/nightly/clippy/lint_configuration.html)
203+
to see what configuration options you can set and the lints they configure.
204+
202205
For configurations that are a list type with default values such as
203206
[disallowed-names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names),
204207
you can use the unique value `".."` to extend the default values instead of replacing them.

book/src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [Installation](installation.md)
66
- [Usage](usage.md)
77
- [Configuration](configuration.md)
8+
- [Lint Configuration](lint_configuration.md)
89
- [Clippy's Lints](lints.md)
910
- [Continuous Integration](continuous_integration/README.md)
1011
- [GitHub Actions](continuous_integration/github_actions.md)

book/src/configuration.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ disallowed-names = ["toto", "tata", "titi"]
1313
See the [list of configurable lints](https://rust-lang.github.io/rust-clippy/master/index.html#Configuration),
1414
the lint descriptions contain the names and meanings of these configuration variables.
1515

16+
See [table of lint configurations](./lint_configuration.md)
17+
to see what configuration options you can set and the lints they configure.
18+
1619
For configurations that are a list type with default values such as
1720
[disallowed-names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names),
1821
you can use the unique value `".."` to extend the default values instead of replacing them.

book/src/lint_configuration.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Configuration Options
2+
3+
| Option | Default | Description | Lints |
4+
|--|--|--|--|
5+
| arithmetic-side-effects-allowed | `{}` | Suppress checking of the passed type names in all types of operations | [arithmetic_side_effects](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) |
6+
| arithmetic-side-effects-allowed-binary | `[]` | Suppress checking of the passed type pair names in binary operations like addition or multiplication | [arithmetic_side_effects](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) |
7+
| arithmetic-side-effects-allowed-unary | `{}` | Suppress checking of the passed type names in unary operations like "negation" (`-`) | [arithmetic_side_effects](https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects) |
8+
| avoid-breaking-exported-api | `true` | Suppress lints whenever the suggested change would cause breakage for other crates | [enum_variant_names](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names) [large_types_passed_by_value](https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value) [trivially_copy_pass_by_ref](https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref) [unnecessary_wraps](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps) [unused_self](https://rust-lang.github.io/rust-clippy/master/index.html#unused_self) [upper_case_acronyms](https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms) [wrong_self_convention](https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention) [box_collection](https://rust-lang.github.io/rust-clippy/master/index.html#box_collection) [redundant_allocation](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation) [rc_buffer](https://rust-lang.github.io/rust-clippy/master/index.html#rc_buffer) [vec_box](https://rust-lang.github.io/rust-clippy/master/index.html#vec_box) [option_option](https://rust-lang.github.io/rust-clippy/master/index.html#option_option) [linkedlist](https://rust-lang.github.io/rust-clippy/master/index.html#linkedlist) [rc_mutex](https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex) |
9+
| msrv | `None` | The minimum rust version that the project supports | [manual_split_once](https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once) [manual_str_repeat](https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat) [cloned_instead_of_copied](https://rust-lang.github.io/rust-clippy/master/index.html#cloned_instead_of_copied) [redundant_field_names](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names) [redundant_static_lifetimes](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes) [filter_map_next](https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next) [checked_conversions](https://rust-lang.github.io/rust-clippy/master/index.html#checked_conversions) [manual_range_contains](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains) [use_self](https://rust-lang.github.io/rust-clippy/master/index.html#use_self) [mem_replace_with_default](https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default) [manual_non_exhaustive](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive) [option_as_ref_deref](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref) [map_unwrap_or](https://rust-lang.github.io/rust-clippy/master/index.html#map_unwrap_or) [match_like_matches_macro](https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro) [manual_strip](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip) [missing_const_for_fn](https://rust-lang.github.io/rust-clippy/master/index.html#missing_const_for_fn) [unnested_or_patterns](https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns) [from_over_into](https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into) [ptr_as_ptr](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr) [if_then_some_else_none](https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none) [approx_constant](https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant) [deprecated_cfg_attr](https://rust-lang.github.io/rust-clippy/master/index.html#deprecated_cfg_attr) [index_refutable_slice](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) [map_clone](https://rust-lang.github.io/rust-clippy/master/index.html#map_clone) [borrow_as_ptr](https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr) [manual_bits](https://rust-lang.github.io/rust-clippy/master/index.html#manual_bits) [err_expect](https://rust-lang.github.io/rust-clippy/master/index.html#err_expect) [cast_abs_to_unsigned](https://rust-lang.github.io/rust-clippy/master/index.html#cast_abs_to_unsigned) [uninlined_format_args](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) [manual_clamp](https://rust-lang.github.io/rust-clippy/master/index.html#manual_clamp) [manual_let_else](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) [unchecked_duration_subtraction](https://rust-lang.github.io/rust-clippy/master/index.html#unchecked_duration_subtraction) |
10+
| cognitive-complexity-threshold | `25` | The maximum cognitive complexity a function can have | [cognitive_complexity](https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity) |
11+
| disallowed-names | `["foo", "baz", "quux"]` | The list of disallowed names to lint about | [disallowed_names](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_names) |
12+
| doc-valid-idents | `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]` | The list of words this lint should not consider as identifiers needing ticks | [doc_markdown](https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown) |
13+
| too-many-arguments-threshold | `7` | The maximum number of argument a function or method can have | [too_many_arguments](https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments) |
14+
| type-complexity-threshold | `250` | The maximum complexity a type can have | [type_complexity](https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity) |
15+
| single-char-binding-names-threshold | `4` | The maximum number of single char bindings a scope may have | [many_single_char_names](https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names) |
16+
| too-large-for-stack | `200` | The maximum size of objects (in bytes) that will be linted | [boxed_local](https://rust-lang.github.io/rust-clippy/master/index.html#boxed_local) [useless_vec](https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec) |
17+
| enum-variant-name-threshold | `3` | The minimum number of enum variants for the lints about variant names to trigger | [enum_variant_names](https://rust-lang.github.io/rust-clippy/master/index.html#enum_variant_names) |
18+
| enum-variant-size-threshold | `200` | The maximum size of an enum's variant to avoid box suggestion | [large_enum_variant](https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant) |
19+
| verbose-bit-mask-threshold | `1` | The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros' | [verbose_bit_mask](https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask) |
20+
| literal-representation-threshold | `16384` | The lower bound for linting decimal literals | [decimal_literal_representation](https://rust-lang.github.io/rust-clippy/master/index.html#decimal_literal_representation) |
21+
| trivial-copy-size-limit | `None` | The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by reference | [trivially_copy_pass_by_ref](https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref) |
22+
| pass-by-value-size-limit | `256` | The minimum size (in bytes) to consider a type for passing by reference instead of by value | [large_type_pass_by_move](https://rust-lang.github.io/rust-clippy/master/index.html#large_type_pass_by_move) |
23+
| too-many-lines-threshold | `100` | The maximum number of lines a function or method can have | [too_many_lines](https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines) |
24+
| array-size-threshold | `512000` | The maximum allowed size for arrays on the stack | [large_stack_arrays](https://rust-lang.github.io/rust-clippy/master/index.html#large_stack_arrays) [large_const_arrays](https://rust-lang.github.io/rust-clippy/master/index.html#large_const_arrays) |
25+
| vec-box-size-threshold | `4096` | The size of the boxed type in bytes, where boxing in a `Vec` is allowed | [vec_box](https://rust-lang.github.io/rust-clippy/master/index.html#vec_box) |
26+
| max-trait-bounds | `3` | The maximum number of bounds a trait can have to be linted | [type_repetition_in_bounds](https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds) |
27+
| max-struct-bools | `3` | The maximum number of bool fields a struct can have | [struct_excessive_bools](https://rust-lang.github.io/rust-clippy/master/index.html#struct_excessive_bools) |
28+
| max-fn-params-bools | `3` | The maximum number of bool parameters a function can have | [fn_params_excessive_bools](https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools) |
29+
| warn-on-all-wildcard-imports | `false` | Whether to allow certain wildcard imports (prelude, super in tests) | [wildcard_imports](https://rust-lang.github.io/rust-clippy/master/index.html#wildcard_imports) |
30+
| disallowed-macros | `[]` | The list of disallowed macros, written as fully qualified paths | [disallowed_macros](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_macros) |
31+
| disallowed-methods | `[]` | The list of disallowed methods, written as fully qualified paths | [disallowed_methods](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods) |
32+
| disallowed-types | `[]` | The list of disallowed types, written as fully qualified paths | [disallowed_types](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types) |
33+
| unreadable-literal-lint-fractions | `true` | Should the fraction of a decimal be linted to include separators | [unreadable_literal](https://rust-lang.github.io/rust-clippy/master/index.html#unreadable_literal) |
34+
| upper-case-acronyms-aggressive | `false` | Enables verbose mode | [upper_case_acronyms](https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms) |
35+
| matches-for-let-else | `WellKnownTypes` | Whether the matches should be considered by the lint, and whether there should be filtering for common types | [manual_let_else](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else) |
36+
| cargo-ignore-publish | `false` | For internal testing only, ignores the current `publish` settings in the Cargo manifest | [_cargo_common_metadata](https://rust-lang.github.io/rust-clippy/master/index.html#_cargo_common_metadata) |
37+
| standard-macro-braces | `[]` | Enforce the named macros always use the braces specified | [nonstandard_macro_braces](https://rust-lang.github.io/rust-clippy/master/index.html#nonstandard_macro_braces) |
38+
| enforced-import-renames | `[]` | The list of imports to always rename, a fully qualified path followed by the rename | [missing_enforced_import_renames](https://rust-lang.github.io/rust-clippy/master/index.html#missing_enforced_import_renames) |
39+
| allowed-scripts | `["Latin"]` | The list of unicode scripts allowed to be used in the scope | [disallowed_script_idents](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_script_idents) |
40+
| enable-raw-pointer-heuristic-for-send | `true` | Whether to apply the raw pointer heuristic to determine if a type is `Send` | [non_send_fields_in_send_ty](https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty) |
41+
| max-suggested-slice-pattern-length | `3` | When Clippy suggests using a slice pattern, this is the maximum number of elements allowed in the slice pattern that is suggested | [index_refutable_slice](https://rust-lang.github.io/rust-clippy/master/index.html#index_refutable_slice) |
42+
| await-holding-invalid-types | `[]` | [ERROR] MALFORMED DOC COMMENT | |
43+
| max-include-file-size | `1000000` | The maximum size of a file included via `include_bytes!()` or `include_str!()`, in bytes | [large_include_file](https://rust-lang.github.io/rust-clippy/master/index.html#large_include_file) |
44+
| allow-expect-in-tests | `false` | Whether `expect` should be allowed within `#[cfg(test)]` | [expect_used](https://rust-lang.github.io/rust-clippy/master/index.html#expect_used) |
45+
| allow-unwrap-in-tests | `false` | Whether `unwrap` should be allowed in test cfg | [unwrap_used](https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used) |
46+
| allow-dbg-in-tests | `false` | Whether `dbg!` should be allowed in test functions | [dbg_macro](https://rust-lang.github.io/rust-clippy/master/index.html#dbg_macro) |
47+
| allow-print-in-tests | `false` | Whether print macros (ex | [print_stdout](https://rust-lang.github.io/rust-clippy/master/index.html#print_stdout) [print_stderr](https://rust-lang.github.io/rust-clippy/master/index.html#print_stderr) |
48+
| large-error-threshold | `128` | The maximum size of the `Err`-variant in a `Result` returned from a function | [result_large_err](https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err) |
49+
| ignore-interior-mutability | `["bytes::Bytes"]` | A list of paths to types that should be treated like `Arc`, i | [mutable_key](https://rust-lang.github.io/rust-clippy/master/index.html#mutable_key) |
50+
| allow-mixed-uninlined-format-args | `true` | Whether to allow mixed uninlined format args, e | [uninlined_format_args](https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args) |
51+
| suppress-restriction-lint-in-const | `false` | In same cases the restructured operation might not be unavoidable, as the suggested counterparts are unavailable in constant code | [indexing_slicing](https://rust-lang.github.io/rust-clippy/master/index.html#indexing_slicing) |
52+

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use clippy_utils::diagnostics::span_lint;
1414
use clippy_utils::ty::{match_type, walk_ptrs_ty_depth};
1515
use clippy_utils::{last_path_segment, match_def_path, match_function_call, match_path, paths};
1616
use if_chain::if_chain;
17+
use itertools::Itertools;
1718
use rustc_ast as ast;
1819
use rustc_data_structures::fx::FxHashMap;
1920
use rustc_hir::{
@@ -34,8 +35,10 @@ use std::path::Path;
3435
use std::path::PathBuf;
3536
use std::process::Command;
3637

37-
/// This is the output file of the lint collector.
38-
const OUTPUT_FILE: &str = "../util/gh-pages/lints.json";
38+
/// This is the json output file of the lint collector.
39+
const JSON_OUTPUT_FILE: &str = "../util/gh-pages/lints.json";
40+
/// This is the markdown output file of the lint collector.
41+
const MARKDOWN_OUTPUT_FILE: &str = "../book/src/lint_configuration.md";
3942
/// These lints are excluded from the export.
4043
const BLACK_LISTED_LINTS: &[&str] = &["lint_author", "dump_hir", "internal_metadata_collector"];
4144
/// These groups will be ignored by the lint group matcher. This is useful for collections like
@@ -176,6 +179,17 @@ This lint has the following configuration variables:
176179
)
177180
})
178181
}
182+
183+
fn get_markdown_table(&self) -> String {
184+
format!(
185+
"{}",
186+
self.config
187+
.iter()
188+
.filter(|config| config.deprecation_reason.is_none())
189+
.map(|config| config.to_markdown_table_entry())
190+
.join("\n")
191+
)
192+
}
179193
}
180194

181195
impl Drop for MetadataCollector {
@@ -199,12 +213,32 @@ impl Drop for MetadataCollector {
199213

200214
collect_renames(&mut lints);
201215

202-
// Outputting
203-
if Path::new(OUTPUT_FILE).exists() {
204-
fs::remove_file(OUTPUT_FILE).unwrap();
216+
// Outputting json
217+
if Path::new(JSON_OUTPUT_FILE).exists() {
218+
fs::remove_file(JSON_OUTPUT_FILE).unwrap();
205219
}
206-
let mut file = OpenOptions::new().write(true).create(true).open(OUTPUT_FILE).unwrap();
220+
let mut file = OpenOptions::new()
221+
.write(true)
222+
.create(true)
223+
.open(JSON_OUTPUT_FILE)
224+
.unwrap();
207225
writeln!(file, "{}", serde_json::to_string_pretty(&lints).unwrap()).unwrap();
226+
227+
// Outputting markdown
228+
if Path::new(MARKDOWN_OUTPUT_FILE).exists() {
229+
fs::remove_file(MARKDOWN_OUTPUT_FILE).unwrap();
230+
}
231+
let mut file = OpenOptions::new()
232+
.write(true)
233+
.create(true)
234+
.open(MARKDOWN_OUTPUT_FILE)
235+
.unwrap();
236+
writeln!(
237+
file,
238+
"## Lint Configuration\n\n| Option | Default | Description | Lints |\n|--|--|--|--|\n{}\n",
239+
self.get_markdown_table()
240+
)
241+
.unwrap();
208242
}
209243
}
210244

@@ -505,6 +539,25 @@ impl ClippyConfiguration {
505539
deprecation_reason,
506540
}
507541
}
542+
543+
fn to_markdown_table_entry(&self) -> String {
544+
format!(
545+
"| {} | `{}` | {} | {} |",
546+
self.name,
547+
self.default,
548+
self.doc
549+
.split('.')
550+
.next()
551+
.unwrap_or("")
552+
.replace("|", "\\|")
553+
.replace("\n ", " "),
554+
self.lints
555+
.iter()
556+
.map(|name| name.to_string().split_whitespace().next().unwrap().to_string())
557+
.map(|name| format!("[{name}](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"))
558+
.join(" ")
559+
)
560+
}
508561
}
509562

510563
fn collect_configs() -> Vec<ClippyConfiguration> {

0 commit comments

Comments
 (0)