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)
26 report = report_on_lines(&m->c_files, report_on_trailing_whitespace,
28 report = report_on_lines(&m->h_files, report_on_trailing_whitespace,
34 static const char *describe_trailing_whitespace(struct manifest *m,
37 return talloc_asprintf(check_result,
38 "Some source files have trailing whitespace:\n"
39 "%s", (char *)check_result);
42 struct ccanlint trailing_whitespace = {
43 .name = "No lines with unnecessary trailing whitespace",
45 .check = check_trailing_whitespace,
46 .describe = describe_trailing_whitespace,
50 REGISTER_TEST(trailing_whitespace, NULL);