1 #include <tools/ccanlint/ccanlint.h>
2 #include <tools/doc_extract.h>
3 #include <tools/tools.h>
13 #include <ccan/str/str.h>
14 #include <ccan/noerr/noerr.h>
16 static void check_info_documentation_exists(struct manifest *m,
17 unsigned int *timeleft,
20 static struct ccanlint info_documentation_exists = {
21 .key = "info_documentation_exists",
22 .name = "Module has documentation in _info",
23 .check = check_info_documentation_exists,
24 .needs = "info_exists"
27 static void create_info_template_doc(struct manifest *m, struct score *score)
33 if (!ask("Should I prepend description to _info file for you?"))
36 fd = open("_info.new", O_WRONLY|O_CREAT|O_EXCL, 0666);
37 if (fd < 0 || !(new = fdopen(fd, "w")))
38 err(1, "Creating _info.new to insert documentation");
42 " * %s - [[ONE LINE DESCRIPTION HERE]]\n"
44 " * Paragraphs why %s exists and where to use it.\n"
46 " * Followed by an Example: section with a standalone\n"
47 " * (trivial and usually useless) program\n"
48 " */\n", m->modname, m->basename) < 0) {
49 unlink_noerr("_info.new");
50 err(1, "Writing to _info.new to insert documentation");
53 oldcontents = tal_grab_file(m, m->info_file->fullname, NULL);
55 unlink_noerr("_info.new");
56 err(1, "Reading %s", m->info_file->fullname);
58 if (fprintf(new, "%s", oldcontents) < 0) {
59 unlink_noerr("_info.new");
60 err(1, "Appending _info to _info.new");
62 if (fclose(new) != 0) {
63 unlink_noerr("_info.new");
64 err(1, "Closing _info.new");
66 if (!move_file("_info.new", m->info_file->fullname)) {
67 unlink_noerr("_info.new");
68 err(1, "Renaming _info.new to %s", m->info_file->fullname);
72 static void check_info_documentation_exists(struct manifest *m,
73 unsigned int *timeleft,
76 struct list_head *infodocs = get_ccan_file_docs(m->info_file);
77 struct doc_section *d;
78 bool summary = false, description = false;
80 /* We don't fail ccanlint for this. */
83 list_for_each(infodocs, d, list) {
84 if (!streq(d->function, m->modname))
86 if (streq(d->type, "summary"))
88 if (streq(d->type, "description"))
92 if (summary && description) {
93 score->score = score->total;
94 } else if (!summary) {
95 score->error = tal_strdup(score,
96 "_info file has no module documentation.\n\n"
97 "CCAN modules use /**-style comments for documentation: the\n"
98 "overall documentation belongs in the _info metafile.\n");
99 info_documentation_exists.handle = create_info_template_doc;
100 } else if (!description) {
101 score->error = tal_strdup(score,
102 "_info file has no module description.\n\n"
103 "The lines after the first summary line in the _info file\n"
104 "documentation should describe the purpose and use of the\n"
105 "overall package\n");
109 REGISTER_TEST(info_documentation_exists);