File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 4
4
5
5
- [ Installation] ( installation.md )
6
6
- [ Usage] ( usage.md )
7
+ - [ Extending Clippy coverage] ( lib_usage.md )
7
8
- [ Configuration] ( configuration.md )
8
9
- [ Lint Configuration] ( lint_configuration.md )
9
10
- [ Clippy's Lints] ( lints.md )
Original file line number Diff line number Diff line change
1
+ # Modifying Clippy behavior with attributes
2
+
3
+ In some cases it is possible extend Clippy coverage to include 3rd party libraries.
4
+ At this moment, only one such modification is possible: adding a
5
+ ` #[clippy::format_args] ` attribute to a macro that supports ` format! ` -like syntax.
6
+
7
+ ## ` #[clippy::format_args] `
8
+
9
+ This attribute can be added to a macro that supports ` format! ` -like syntax.
10
+ It tells Clippy that the macro is a formatting macro, and that the arguments to the macro
11
+ should be linted as if they were arguments to ` format! ` . Any lint that would apply to a
12
+ ` format! ` call will also apply to the macro call. The macro may have additional arguments
13
+ before the format string, and these will be ignored.
14
+
15
+ ### Example
16
+
17
+ Note that the ` #[clippy::format_args] ` is only available in v1.84, and will
18
+ cause an ` error: usage of unknown attribute ` when running older ` clippy ` .
19
+ To avoid this, you can use the [ rustversion] ( https://github.com/dtolnay/rustversion )
20
+ crate to apply the attribute conditionally.
21
+
22
+ ``` rust
23
+ /// A macro that prints a message if a condition is true
24
+ #[macro_export]
25
+ #[rustversion:: attr(since(1. 84), clippy:: format_args)]
26
+ macro_rules! print_if {
27
+ ($ condition : expr , $ ($ args : tt )+ ) => {{
28
+ if $ condition {
29
+ println! ($ ($ args )+ )
30
+ }
31
+ }};
32
+ }
33
+ ```
You can’t perform that action at this time.
0 commit comments