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>
15 #include <ccan/tal/grab_file/grab_file.h>
17 static void check_info_documentation_exists(struct manifest *m,
18 unsigned int *timeleft,
21 static struct ccanlint info_documentation_exists = {
22 .key = "info_documentation_exists",
23 .name = "Module has documentation in _info",
24 .check = check_info_documentation_exists,
25 .needs = "info_exists"
28 static void create_info_template_doc(struct manifest *m, struct score *score)
34 if (!ask("Should I prepend description to _info file for you?"))
37 fd = open("_info.new", O_WRONLY|O_CREAT|O_EXCL, 0666);
38 if (fd < 0 || !(new = fdopen(fd, "w")))
39 err(1, "Creating _info.new to insert documentation");
43 " * %s - [[ONE LINE DESCRIPTION HERE]]\n"
45 " * Paragraphs why %s exists and where to use it.\n"
47 " * Followed by an Example: section with a standalone\n"
48 " * (trivial and usually useless) program\n"
49 " */\n", m->modname, m->basename) < 0) {
50 unlink_noerr("_info.new");
51 err(1, "Writing to _info.new to insert documentation");
54 oldcontents = grab_file(m, m->info_file->fullname);
56 unlink_noerr("_info.new");
57 err(1, "Reading %s", m->info_file->fullname);
59 if (fprintf(new, "%s", oldcontents) < 0) {
60 unlink_noerr("_info.new");
61 err(1, "Appending _info to _info.new");
63 if (fclose(new) != 0) {
64 unlink_noerr("_info.new");
65 err(1, "Closing _info.new");
67 if (!move_file("_info.new", m->info_file->fullname)) {
68 unlink_noerr("_info.new");
69 err(1, "Renaming _info.new to %s", m->info_file->fullname);
73 static void check_info_documentation_exists(struct manifest *m,
74 unsigned int *timeleft,
77 struct list_head *infodocs = get_ccan_file_docs(m->info_file);
78 struct doc_section *d;
79 bool summary = false, description = false;
81 /* We don't fail ccanlint for this. */
84 list_for_each(infodocs, d, list) {
85 if (!streq(d->function, m->modname))
87 if (streq(d->type, "summary"))
89 if (streq(d->type, "description"))
93 if (summary && description) {
94 score->score = score->total;
95 } else if (!summary) {
96 score->error = tal_strdup(score,
97 "_info file has no module documentation.\n\n"
98 "CCAN modules use /**-style comments for documentation: the\n"
99 "overall documentation belongs in the _info metafile.\n");
100 info_documentation_exists.handle = create_info_template_doc;
101 } else if (!description) {
102 score->error = tal_strdup(score,
103 "_info file has no module description.\n\n"
104 "The lines after the first summary line in the _info file\n"
105 "documentation should describe the purpose and use of the\n"
106 "overall package\n");
110 REGISTER_TEST(info_documentation_exists);