]> git.lizzy.rs Git - rust.git/blob - clippy_dev/src/update_lints.rs
Merge commit 'a98e7ab8b94485be6bd03e0c6b8682ecab5b52e6' into clippyup
[rust.git] / clippy_dev / src / update_lints.rs
1 use itertools::Itertools;
2 use regex::Regex;
3 use std::collections::HashMap;
4 use std::ffi::OsStr;
5 use std::fs;
6 use std::lazy::SyncLazy;
7 use std::path::Path;
8 use walkdir::WalkDir;
9
10 use crate::clippy_project_root;
11
12 const GENERATED_FILE_COMMENT: &str = "// This file was generated by `cargo dev update_lints`.\n\
13      // Use that command to update this file and do not edit by hand.\n\
14      // Manual edits will be overwritten.\n\n";
15
16 static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
17     Regex::new(
18         r#"(?x)
19     declare_clippy_lint!\s*[\{(]
20     (?:\s+///.*)*
21     (?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
22     \s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
23     (?P<cat>[a-z_]+)\s*,\s*
24     "(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
25 "#,
26     )
27     .unwrap()
28 });
29
30 static DEC_DEPRECATED_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {
31     Regex::new(
32         r#"(?x)
33     declare_deprecated_lint!\s*[{(]\s*
34     (?:\s+///.*)*
35     (?:\s*\#\[clippy::version\s*=\s*"[^"]*"\])?
36     \s+pub\s+(?P<name>[A-Z_][A-Z_0-9]*)\s*,\s*
37     "(?P<desc>(?:[^"\\]+|\\(?s).(?-s))*)"\s*[})]
38 "#,
39     )
40     .unwrap()
41 });
42 static NL_ESCAPE_RE: SyncLazy<Regex> = SyncLazy::new(|| Regex::new(r#"\\\n\s*"#).unwrap());
43
44 static DOCS_LINK: &str = "https://rust-lang.github.io/rust-clippy/master/index.html";
45
46 #[derive(Clone, Copy, PartialEq)]
47 pub enum UpdateMode {
48     Check,
49     Change,
50 }
51
52 /// Runs the `update_lints` command.
53 ///
54 /// This updates various generated values from the lint source code.
55 ///
56 /// `update_mode` indicates if the files should be updated or if updates should be checked for.
57 ///
58 /// # Panics
59 ///
60 /// Panics if a file path could not read from or then written to
61 #[allow(clippy::too_many_lines)]
62 pub fn run(update_mode: UpdateMode) {
63     let lint_list: Vec<Lint> = gather_all().collect();
64
65     let internal_lints = Lint::internal_lints(&lint_list);
66     let deprecated_lints = Lint::deprecated_lints(&lint_list);
67     let usable_lints = Lint::usable_lints(&lint_list);
68     let mut sorted_usable_lints = usable_lints.clone();
69     sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
70
71     let usable_lint_count = round_to_fifty(usable_lints.len());
72
73     let mut file_change = false;
74
75     file_change |= replace_region_in_file(
76         Path::new("README.md"),
77         &format!(
78             r#"\[There are over \d+ lints included in this crate!\]\({}\)"#,
79             DOCS_LINK
80         ),
81         "",
82         true,
83         update_mode == UpdateMode::Change,
84         || {
85             vec![format!(
86                 "[There are over {} lints included in this crate!]({})",
87                 usable_lint_count, DOCS_LINK
88             )]
89         },
90     )
91     .changed;
92
93     file_change |= replace_region_in_file(
94         Path::new("CHANGELOG.md"),
95         "<!-- begin autogenerated links to lint list -->",
96         "<!-- end autogenerated links to lint list -->",
97         false,
98         update_mode == UpdateMode::Change,
99         || gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())),
100     )
101     .changed;
102
103     // This has to be in lib.rs, otherwise rustfmt doesn't work
104     file_change |= replace_region_in_file(
105         Path::new("clippy_lints/src/lib.rs"),
106         "begin lints modules",
107         "end lints modules",
108         false,
109         update_mode == UpdateMode::Change,
110         || gen_modules_list(usable_lints.iter()),
111     )
112     .changed;
113
114     if file_change && update_mode == UpdateMode::Check {
115         exit_with_failure();
116     }
117
118     process_file(
119         "clippy_lints/src/lib.register_lints.rs",
120         update_mode,
121         &gen_register_lint_list(internal_lints.iter(), usable_lints.iter()),
122     );
123     process_file(
124         "clippy_lints/src/lib.deprecated.rs",
125         update_mode,
126         &gen_deprecated(deprecated_lints.iter()),
127     );
128
129     let all_group_lints = usable_lints.iter().filter(|l| {
130         matches!(
131             &*l.group,
132             "correctness" | "suspicious" | "style" | "complexity" | "perf"
133         )
134     });
135     let content = gen_lint_group_list("all", all_group_lints);
136     process_file("clippy_lints/src/lib.register_all.rs", update_mode, &content);
137
138     for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
139         let content = gen_lint_group_list(&lint_group, lints.iter());
140         process_file(
141             &format!("clippy_lints/src/lib.register_{}.rs", lint_group),
142             update_mode,
143             &content,
144         );
145     }
146 }
147
148 pub fn print_lints() {
149     let lint_list: Vec<Lint> = gather_all().collect();
150     let usable_lints = Lint::usable_lints(&lint_list);
151     let usable_lint_count = usable_lints.len();
152     let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
153
154     for (lint_group, mut lints) in grouped_by_lint_group {
155         if lint_group == "Deprecated" {
156             continue;
157         }
158         println!("\n## {}", lint_group);
159
160         lints.sort_by_key(|l| l.name.clone());
161
162         for lint in lints {
163             println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
164         }
165     }
166
167     println!("there are {} lints", usable_lint_count);
168 }
169
170 fn round_to_fifty(count: usize) -> usize {
171     count / 50 * 50
172 }
173
174 fn process_file(path: impl AsRef<Path>, update_mode: UpdateMode, content: &str) {
175     if update_mode == UpdateMode::Check {
176         let old_content =
177             fs::read_to_string(&path).unwrap_or_else(|e| panic!("Cannot read from {}: {}", path.as_ref().display(), e));
178         if content != old_content {
179             exit_with_failure();
180         }
181     } else {
182         fs::write(&path, content.as_bytes())
183             .unwrap_or_else(|e| panic!("Cannot write to {}: {}", path.as_ref().display(), e));
184     }
185 }
186
187 fn exit_with_failure() {
188     println!(
189         "Not all lints defined properly. \
190                  Please run `cargo dev update_lints` to make sure all lints are defined properly."
191     );
192     std::process::exit(1);
193 }
194
195 /// Lint data parsed from the Clippy source code.
196 #[derive(Clone, PartialEq, Debug)]
197 struct Lint {
198     name: String,
199     group: String,
200     desc: String,
201     deprecation: Option<String>,
202     module: String,
203 }
204
205 impl Lint {
206     #[must_use]
207     fn new(name: &str, group: &str, desc: &str, deprecation: Option<&str>, module: &str) -> Self {
208         Self {
209             name: name.to_lowercase(),
210             group: group.to_string(),
211             desc: NL_ESCAPE_RE.replace(&desc.replace("\\\"", "\""), "").to_string(),
212             deprecation: deprecation.map(ToString::to_string),
213             module: module.to_string(),
214         }
215     }
216
217     /// Returns all non-deprecated lints and non-internal lints
218     #[must_use]
219     fn usable_lints(lints: &[Self]) -> Vec<Self> {
220         lints
221             .iter()
222             .filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
223             .cloned()
224             .collect()
225     }
226
227     /// Returns all internal lints (not `internal_warn` lints)
228     #[must_use]
229     fn internal_lints(lints: &[Self]) -> Vec<Self> {
230         lints.iter().filter(|l| l.group == "internal").cloned().collect()
231     }
232
233     /// Returns all deprecated lints
234     #[must_use]
235     fn deprecated_lints(lints: &[Self]) -> Vec<Self> {
236         lints.iter().filter(|l| l.deprecation.is_some()).cloned().collect()
237     }
238
239     /// Returns the lints in a `HashMap`, grouped by the different lint groups
240     #[must_use]
241     fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
242         lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
243     }
244 }
245
246 /// Generates the code for registering a group
247 fn gen_lint_group_list<'a>(group_name: &str, lints: impl Iterator<Item = &'a Lint>) -> String {
248     let mut details: Vec<_> = lints.map(|l| (&l.module, l.name.to_uppercase())).collect();
249     details.sort_unstable();
250
251     let mut output = GENERATED_FILE_COMMENT.to_string();
252
253     output.push_str(&format!(
254         "store.register_group(true, \"clippy::{0}\", Some(\"clippy_{0}\"), vec![\n",
255         group_name
256     ));
257     for (module, name) in details {
258         output.push_str(&format!("    LintId::of({}::{}),\n", module, name));
259     }
260     output.push_str("])\n");
261
262     output
263 }
264
265 /// Generates the module declarations for `lints`
266 #[must_use]
267 fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
268     lints
269         .map(|l| &l.module)
270         .unique()
271         .map(|module| format!("mod {};", module))
272         .sorted()
273         .collect::<Vec<String>>()
274 }
275
276 /// Generates the list of lint links at the bottom of the CHANGELOG
277 #[must_use]
278 fn gen_changelog_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
279     lints
280         .sorted_by_key(|l| &l.name)
281         .map(|l| format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
282         .collect()
283 }
284
285 /// Generates the `register_removed` code
286 #[must_use]
287 fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> String {
288     let mut output = GENERATED_FILE_COMMENT.to_string();
289     output.push_str("{\n");
290     for Lint { name, deprecation, .. } in lints {
291         output.push_str(&format!(
292             concat!(
293                 "    store.register_removed(\n",
294                 "        \"clippy::{}\",\n",
295                 "        \"{}\",\n",
296                 "    );\n"
297             ),
298             name,
299             deprecation.as_ref().expect("`lints` are deprecated")
300         ));
301     }
302     output.push_str("}\n");
303
304     output
305 }
306
307 /// Generates the code for registering lints
308 #[must_use]
309 fn gen_register_lint_list<'a>(
310     internal_lints: impl Iterator<Item = &'a Lint>,
311     usable_lints: impl Iterator<Item = &'a Lint>,
312 ) -> String {
313     let mut details: Vec<_> = internal_lints
314         .map(|l| (false, &l.module, l.name.to_uppercase()))
315         .chain(usable_lints.map(|l| (true, &l.module, l.name.to_uppercase())))
316         .collect();
317     details.sort_unstable();
318
319     let mut output = GENERATED_FILE_COMMENT.to_string();
320     output.push_str("store.register_lints(&[\n");
321
322     for (is_public, module_name, lint_name) in details {
323         if !is_public {
324             output.push_str("    #[cfg(feature = \"internal\")]\n");
325         }
326         output.push_str(&format!("    {}::{},\n", module_name, lint_name));
327     }
328     output.push_str("])\n");
329
330     output
331 }
332
333 /// Gathers all files in `src/clippy_lints` and gathers all lints inside
334 fn gather_all() -> impl Iterator<Item = Lint> {
335     lint_files().flat_map(|f| gather_from_file(&f))
336 }
337
338 fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item = Lint> {
339     let content = fs::read_to_string(dir_entry.path()).unwrap();
340     let path = dir_entry.path();
341     let filename = path.file_stem().unwrap();
342     let path_buf = path.with_file_name(filename);
343     let mut rel_path = path_buf
344         .strip_prefix(clippy_project_root().join("clippy_lints/src"))
345         .expect("only files in `clippy_lints/src` should be looked at");
346     // If the lints are stored in mod.rs, we get the module name from
347     // the containing directory:
348     if filename == "mod" {
349         rel_path = rel_path.parent().unwrap();
350     }
351
352     let module = rel_path
353         .components()
354         .map(|c| c.as_os_str().to_str().unwrap())
355         .collect::<Vec<_>>()
356         .join("::");
357
358     parse_contents(&content, &module)
359 }
360
361 fn parse_contents(content: &str, module: &str) -> impl Iterator<Item = Lint> {
362     let lints = DEC_CLIPPY_LINT_RE
363         .captures_iter(content)
364         .map(|m| Lint::new(&m["name"], &m["cat"], &m["desc"], None, module));
365     let deprecated = DEC_DEPRECATED_LINT_RE
366         .captures_iter(content)
367         .map(|m| Lint::new(&m["name"], "Deprecated", &m["desc"], Some(&m["desc"]), module));
368     // Removing the `.collect::<Vec<Lint>>().into_iter()` causes some lifetime issues due to the map
369     lints.chain(deprecated).collect::<Vec<Lint>>().into_iter()
370 }
371
372 /// Collects all .rs files in the `clippy_lints/src` directory
373 fn lint_files() -> impl Iterator<Item = walkdir::DirEntry> {
374     // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
375     // Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
376     let path = clippy_project_root().join("clippy_lints/src");
377     WalkDir::new(path)
378         .into_iter()
379         .filter_map(Result::ok)
380         .filter(|f| f.path().extension() == Some(OsStr::new("rs")))
381 }
382
383 /// Whether a file has had its text changed or not
384 #[derive(PartialEq, Debug)]
385 struct FileChange {
386     changed: bool,
387     new_lines: String,
388 }
389
390 /// Replaces a region in a file delimited by two lines matching regexes.
391 ///
392 /// `path` is the relative path to the file on which you want to perform the replacement.
393 ///
394 /// See `replace_region_in_text` for documentation of the other options.
395 ///
396 /// # Panics
397 ///
398 /// Panics if the path could not read or then written
399 fn replace_region_in_file<F>(
400     path: &Path,
401     start: &str,
402     end: &str,
403     replace_start: bool,
404     write_back: bool,
405     replacements: F,
406 ) -> FileChange
407 where
408     F: FnOnce() -> Vec<String>,
409 {
410     let contents = fs::read_to_string(path).unwrap_or_else(|e| panic!("Cannot read from {}: {}", path.display(), e));
411     let file_change = replace_region_in_text(&contents, start, end, replace_start, replacements);
412
413     if write_back {
414         if let Err(e) = fs::write(path, file_change.new_lines.as_bytes()) {
415             panic!("Cannot write to {}: {}", path.display(), e);
416         }
417     }
418     file_change
419 }
420
421 /// Replaces a region in a text delimited by two lines matching regexes.
422 ///
423 /// * `text` is the input text on which you want to perform the replacement
424 /// * `start` is a `&str` that describes the delimiter line before the region you want to replace.
425 ///   As the `&str` will be converted to a `Regex`, this can contain regex syntax, too.
426 /// * `end` is a `&str` that describes the delimiter line until where the replacement should happen.
427 ///   As the `&str` will be converted to a `Regex`, this can contain regex syntax, too.
428 /// * If `replace_start` is true, the `start` delimiter line is replaced as well. The `end`
429 ///   delimiter line is never replaced.
430 /// * `replacements` is a closure that has to return a `Vec<String>` which contains the new text.
431 ///
432 /// If you want to perform the replacement on files instead of already parsed text,
433 /// use `replace_region_in_file`.
434 ///
435 /// # Example
436 ///
437 /// ```ignore
438 /// let the_text = "replace_start\nsome text\nthat will be replaced\nreplace_end";
439 /// let result =
440 ///     replace_region_in_text(the_text, "replace_start", "replace_end", false, || {
441 ///         vec!["a different".to_string(), "text".to_string()]
442 ///     })
443 ///     .new_lines;
444 /// assert_eq!("replace_start\na different\ntext\nreplace_end", result);
445 /// ```
446 ///
447 /// # Panics
448 ///
449 /// Panics if start or end is not valid regex
450 fn replace_region_in_text<F>(text: &str, start: &str, end: &str, replace_start: bool, replacements: F) -> FileChange
451 where
452     F: FnOnce() -> Vec<String>,
453 {
454     let replace_it = replacements();
455     let mut in_old_region = false;
456     let mut found = false;
457     let mut new_lines = vec![];
458     let start = Regex::new(start).unwrap();
459     let end = Regex::new(end).unwrap();
460
461     for line in text.lines() {
462         if in_old_region {
463             if end.is_match(line) {
464                 in_old_region = false;
465                 new_lines.extend(replace_it.clone());
466                 new_lines.push(line.to_string());
467             }
468         } else if start.is_match(line) {
469             if !replace_start {
470                 new_lines.push(line.to_string());
471             }
472             in_old_region = true;
473             found = true;
474         } else {
475             new_lines.push(line.to_string());
476         }
477     }
478
479     if !found {
480         // This happens if the provided regex in `clippy_dev/src/main.rs` does not match in the
481         // given text or file. Most likely this is an error on the programmer's side and the Regex
482         // is incorrect.
483         eprintln!("error: regex \n{:?}\ndoesn't match. You may have to update it.", start);
484         std::process::exit(1);
485     }
486
487     let mut new_lines = new_lines.join("\n");
488     if text.ends_with('\n') {
489         new_lines.push('\n');
490     }
491     let changed = new_lines != text;
492     FileChange { changed, new_lines }
493 }
494
495 #[test]
496 fn test_parse_contents() {
497     let result: Vec<Lint> = parse_contents(
498         r#"
499 declare_clippy_lint! {
500     #[clippy::version = "Hello Clippy!"]
501     pub PTR_ARG,
502     style,
503     "really long \
504      text"
505 }
506
507 declare_clippy_lint!{
508     #[clippy::version = "Test version"]
509     pub DOC_MARKDOWN,
510     pedantic,
511     "single line"
512 }
513
514 /// some doc comment
515 declare_deprecated_lint! {
516     #[clippy::version = "I'm a version"]
517     pub SHOULD_ASSERT_EQ,
518     "`assert!()` will be more flexible with RFC 2011"
519 }
520     "#,
521         "module_name",
522     )
523     .collect();
524
525     let expected = vec![
526         Lint::new("ptr_arg", "style", "really long text", None, "module_name"),
527         Lint::new("doc_markdown", "pedantic", "single line", None, "module_name"),
528         Lint::new(
529             "should_assert_eq",
530             "Deprecated",
531             "`assert!()` will be more flexible with RFC 2011",
532             Some("`assert!()` will be more flexible with RFC 2011"),
533             "module_name",
534         ),
535     ];
536     assert_eq!(expected, result);
537 }
538
539 #[cfg(test)]
540 mod tests {
541     use super::*;
542
543     #[test]
544     fn test_replace_region() {
545         let text = "\nabc\n123\n789\ndef\nghi";
546         let expected = FileChange {
547             changed: true,
548             new_lines: "\nabc\nhello world\ndef\nghi".to_string(),
549         };
550         let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, false, || {
551             vec!["hello world".to_string()]
552         });
553         assert_eq!(expected, result);
554     }
555
556     #[test]
557     fn test_replace_region_with_start() {
558         let text = "\nabc\n123\n789\ndef\nghi";
559         let expected = FileChange {
560             changed: true,
561             new_lines: "\nhello world\ndef\nghi".to_string(),
562         };
563         let result = replace_region_in_text(text, r#"^\s*abc$"#, r#"^\s*def"#, true, || {
564             vec!["hello world".to_string()]
565         });
566         assert_eq!(expected, result);
567     }
568
569     #[test]
570     fn test_replace_region_no_changes() {
571         let text = "123\n456\n789";
572         let expected = FileChange {
573             changed: false,
574             new_lines: "123\n456\n789".to_string(),
575         };
576         let result = replace_region_in_text(text, r#"^\s*123$"#, r#"^\s*456"#, false, Vec::new);
577         assert_eq!(expected, result);
578     }
579
580     #[test]
581     fn test_usable_lints() {
582         let lints = vec![
583             Lint::new("should_assert_eq", "Deprecated", "abc", Some("Reason"), "module_name"),
584             Lint::new("should_assert_eq2", "Not Deprecated", "abc", None, "module_name"),
585             Lint::new("should_assert_eq2", "internal", "abc", None, "module_name"),
586             Lint::new("should_assert_eq2", "internal_style", "abc", None, "module_name"),
587         ];
588         let expected = vec![Lint::new(
589             "should_assert_eq2",
590             "Not Deprecated",
591             "abc",
592             None,
593             "module_name",
594         )];
595         assert_eq!(expected, Lint::usable_lints(&lints));
596     }
597
598     #[test]
599     fn test_by_lint_group() {
600         let lints = vec![
601             Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
602             Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
603             Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
604         ];
605         let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
606         expected.insert(
607             "group1".to_string(),
608             vec![
609                 Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
610                 Lint::new("incorrect_match", "group1", "abc", None, "module_name"),
611             ],
612         );
613         expected.insert(
614             "group2".to_string(),
615             vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")],
616         );
617         assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
618     }
619
620     #[test]
621     fn test_gen_changelog_lint_list() {
622         let lints = vec![
623             Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
624             Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
625         ];
626         let expected = vec![
627             format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK),
628             format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK),
629         ];
630         assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
631     }
632
633     #[test]
634     fn test_gen_deprecated() {
635         let lints = vec![
636             Lint::new(
637                 "should_assert_eq",
638                 "group1",
639                 "abc",
640                 Some("has been superseded by should_assert_eq2"),
641                 "module_name",
642             ),
643             Lint::new(
644                 "another_deprecated",
645                 "group2",
646                 "abc",
647                 Some("will be removed"),
648                 "module_name",
649             ),
650         ];
651
652         let expected = GENERATED_FILE_COMMENT.to_string()
653             + &[
654                 "{",
655                 "    store.register_removed(",
656                 "        \"clippy::should_assert_eq\",",
657                 "        \"has been superseded by should_assert_eq2\",",
658                 "    );",
659                 "    store.register_removed(",
660                 "        \"clippy::another_deprecated\",",
661                 "        \"will be removed\",",
662                 "    );",
663                 "}",
664             ]
665             .join("\n")
666             + "\n";
667
668         assert_eq!(expected, gen_deprecated(lints.iter()));
669     }
670
671     #[test]
672     #[should_panic]
673     fn test_gen_deprecated_fail() {
674         let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
675         let _deprecated_lints = gen_deprecated(lints.iter());
676     }
677
678     #[test]
679     fn test_gen_modules_list() {
680         let lints = vec![
681             Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
682             Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
683         ];
684         let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()];
685         assert_eq!(expected, gen_modules_list(lints.iter()));
686     }
687
688     #[test]
689     fn test_gen_lint_group_list() {
690         let lints = vec![
691             Lint::new("abc", "group1", "abc", None, "module_name"),
692             Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
693             Lint::new("internal", "internal_style", "abc", None, "module_name"),
694         ];
695         let expected = GENERATED_FILE_COMMENT.to_string()
696             + &[
697                 "store.register_group(true, \"clippy::group1\", Some(\"clippy_group1\"), vec![",
698                 "    LintId::of(module_name::ABC),",
699                 "    LintId::of(module_name::INTERNAL),",
700                 "    LintId::of(module_name::SHOULD_ASSERT_EQ),",
701                 "])",
702             ]
703             .join("\n")
704             + "\n";
705
706         let result = gen_lint_group_list("group1", lints.iter());
707
708         assert_eq!(expected, result);
709     }
710 }