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