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