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 static char *report_on_trailing_whitespace(const char *line)
8 const char *e = strchr(line, 0);
9 while (e>line && (e[-1]==' ' || e[-1]=='\t'))
12 return NULL; //there were no trailing spaces
14 return NULL; //the line only consists of spaces
16 if (strlen(line) > 20)
17 return talloc_asprintf(line, "...'%s'",
18 line + strlen(line) - 20);
19 return talloc_asprintf(line, "'%s'", line);
22 static void *check_trailing_whitespace(struct manifest *m,
23 unsigned int *timeleft)
27 report = report_on_lines(&m->c_files, report_on_trailing_whitespace,
29 report = report_on_lines(&m->h_files, report_on_trailing_whitespace,
35 static const char *describe_trailing_whitespace(struct manifest *m,
38 return talloc_asprintf(check_result,
39 "Some source files have trailing whitespace:\n"
40 "%s", (char *)check_result);
43 struct ccanlint trailing_whitespace = {
44 .key = "trailing-whitespace",
45 .name = "Module's source code has no trailing whitespace",
47 .check = check_trailing_whitespace,
48 .describe = describe_trailing_whitespace,
52 REGISTER_TEST(trailing_whitespace, NULL);