@@ -26,6 +26,10 @@ const REQUIRED: [(&str, &str); 14] = [
2626 ( "clippy" , "self_named_module_files" ) ,
2727] ;
2828
29+ /// Clippy's groups among them, which sit at priority -1 so single lints
30+ /// can override them.
31+ const GROUPS : [ ( & str , & str ) ; 2 ] = [ ( "clippy" , "all" ) , ( "clippy" , "pedantic" ) ] ;
32+
2933/// A lint the root manifest's `[workspace.lints]` sets.
3034pub ( super ) struct LintLevel {
3135 /// Its tool's table, such as `rust` or `clippy`.
@@ -77,7 +81,8 @@ impl Repository {
7781 /// Cargo allows only without lint tables of the crate's own; each lint
7882 /// the standard requires that the workspace doesn't set to `warn`; and
7983 /// each other workspace lint set to neither `warn` nor `allow`. It fixes
80- /// a missing `[lints]` and a `deny` or `forbid`, never an `allow`.
84+ /// a missing `[lints]`, a `deny` or `forbid`, and a missing required lint,
85+ /// which it adds at `warn`; never an `allow`.
8186 pub ( super ) fn workspace_lints ( & self ) -> Checked {
8287 let crates = self
8388 . manifests
@@ -124,21 +129,6 @@ impl Repository {
124129 message,
125130 } )
126131 } ) ;
127- let missing = REQUIRED
128- . iter ( )
129- . filter ( |( tool, name) | {
130- !self
131- . lint_levels
132- . iter ( )
133- . any ( |lint| lint. tool == * tool && lint. name == * name)
134- } )
135- . map ( |( tool, name) | Finding {
136- path : ROOT . into ( ) ,
137- line : 1 ,
138- message : format ! (
139- "the standard requires `{name} = \" warn\" ` in `[workspace.lints.{tool}]`"
140- ) ,
141- } ) ;
142132 let inherit = self
143133 . manifests
144134 . iter ( )
@@ -169,9 +159,60 @@ impl Repository {
169159 } ,
170160 )
171161 } ) ;
162+ let unset = self . unset_lints ( ) ;
163+ Checked {
164+ findings : crates. chain ( levels) . chain ( unset. findings ) . collect ( ) ,
165+ fixes : inherit. chain ( warn) . chain ( unset. fixes ) . collect ( ) ,
166+ }
167+ }
168+
169+ /// Each lint the standard requires that `[workspace.lints]` doesn't
170+ /// set, fixed by adding it at `warn` under its tool's table.
171+ fn unset_lints ( & self ) -> Checked {
172+ let unset: Vec < ( & str , & str ) > = REQUIRED
173+ . into_iter ( )
174+ . filter ( |( tool, name) | {
175+ !self
176+ . lint_levels
177+ . iter ( )
178+ . any ( |lint| lint. tool == * tool && lint. name == * name)
179+ } )
180+ . collect ( ) ;
181+ let missing = unset. iter ( ) . map ( |( tool, name) | Finding {
182+ path : ROOT . into ( ) ,
183+ line : 1 ,
184+ message : format ! (
185+ "the standard requires `{name} = \" warn\" ` in `[workspace.lints.{tool}]`"
186+ ) ,
187+ } ) ;
188+ let add = unset. iter ( ) . map ( |& ( tool, name) | {
189+ Fix :: new (
190+ ROOT ,
191+ format ! ( "add `{name} = \" warn\" ` to `[workspace.lints.{tool}]`" ) ,
192+ move |document| {
193+ let lints = & mut document[ "workspace" ] [ "lints" ] ;
194+ if lints. is_none ( ) {
195+ let mut implicit = toml_edit:: Table :: new ( ) ;
196+ implicit. set_implicit ( true ) ;
197+ * lints = toml_edit:: Item :: Table ( implicit) ;
198+ }
199+ if lints. get ( tool) . is_none ( ) {
200+ lints[ tool] = toml_edit:: table ( ) ;
201+ }
202+ lints[ tool] [ name] = if GROUPS . contains ( & ( tool, name) ) {
203+ let mut group = toml_edit:: InlineTable :: new ( ) ;
204+ group. insert ( "level" , "warn" . into ( ) ) ;
205+ group. insert ( "priority" , ( -1 ) . into ( ) ) ;
206+ toml_edit:: value ( group)
207+ } else {
208+ toml_edit:: value ( "warn" )
209+ } ;
210+ } ,
211+ )
212+ } ) ;
172213 Checked {
173- findings : crates . chain ( levels ) . chain ( missing) . collect ( ) ,
174- fixes : inherit . chain ( warn ) . collect ( ) ,
214+ findings : missing. collect ( ) ,
215+ fixes : add . collect ( ) ,
175216 }
176217 }
177218}
0 commit comments