]> git.ozlabs.org Git - ccan/blob - tools/ccanlint/trailing_whitespace.c
Broaden use of doc_extract code, put in ccanlint, and fix ccanlint
[ccan] / tools / ccanlint / trailing_whitespace.c
1 /* Trailing whitespace test.  Almost embarrassing, but trivial. */
2 #include "ccanlint.h"
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
5
6 static char *report_on_trailing_whitespace(const char *line)
7 {
8         if (!strends(line, " ") && !strends(line, "\t"))
9                 return NULL;
10
11         if (strlen(line) > 20)
12                 return talloc_asprintf(line, "...'%s'",
13                                        line + strlen(line) - 20);
14         return talloc_asprintf(line, "'%s'", line);
15 }
16
17 static void *check_trailing_whitespace(struct manifest *m)
18 {
19         char *report;
20
21         report = report_on_lines(&m->c_files, report_on_trailing_whitespace,
22                                  NULL);
23         report = report_on_lines(&m->h_files, report_on_trailing_whitespace,
24                                  report);
25
26         return report;
27 }
28
29 static const char *describe_trailing_whitespace(struct manifest *m,
30                                                 void *check_result)
31 {
32         return talloc_asprintf(check_result, 
33                                "Some source files have trailing whitespace:\n"
34                                "%s", (char *)check_result);
35 }
36
37 struct ccanlint trailing_whitespace = {
38         .name = "Lines with unnecessary trailing whitespace",
39         .total_score = 1,
40         .check = check_trailing_whitespace,
41         .describe = describe_trailing_whitespace,
42 };