1 /* Trailing whitespace test. Almost embarrassing, but trivial. */
2 #include <tools/ccanlint/ccanlint.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/str/str.h>
6 /* FIXME: only print full analysis if verbose >= 2. */
7 static char *report_on_trailing_whitespace(const char *line)
9 const char *e = strchr(line, 0);
10 while (e>line && (e[-1]==' ' || e[-1]=='\t'))
13 return NULL; //there were no trailing spaces
15 return NULL; //the line only consists of spaces
17 if (strlen(line) > 20)
18 return talloc_asprintf(line, "...'%s'",
19 line + strlen(line) - 20);
20 return talloc_asprintf(line, "'%s'", line);
23 static void *check_trailing_whitespace(struct manifest *m,
25 unsigned int *timeleft)
29 report = report_on_lines(&m->c_files, report_on_trailing_whitespace,
31 report = report_on_lines(&m->h_files, report_on_trailing_whitespace,
37 static const char *describe_trailing_whitespace(struct manifest *m,
42 return talloc_asprintf(check_result,
43 "Some source files have trailing whitespace:\n"
44 "%s", (char *)check_result);
47 struct ccanlint trailing_whitespace = {
48 .key = "trailing-whitespace",
49 .name = "Module's source code has no trailing whitespace",
51 .check = check_trailing_whitespace,
52 .describe = describe_trailing_whitespace,
56 REGISTER_TEST(trailing_whitespace, NULL);