1 /* Trailing whitespace test. Almost embarrassing, but trivial. */
2 #include <tools/ccanlint/ccanlint.h>
3 #include <ccan/talloc/talloc.h>
4 #include <ccan/foreach/foreach.h>
5 #include <ccan/str/str.h>
7 /* FIXME: only print full analysis if verbose >= 2. */
8 static char *get_trailing_whitespace(const char *line)
10 const char *e = strchr(line, 0);
11 while (e>line && (e[-1]==' ' || e[-1]=='\t'))
14 return NULL; //there were no trailing spaces
16 return NULL; //the line only consists of spaces
18 if (strlen(line) > 20)
19 return talloc_asprintf(line, "...'%s'",
20 line + strlen(line) - 20);
21 return talloc_asprintf(line, "'%s'", line);
24 static void check_trailing_whitespace(struct manifest *m,
25 unsigned int *timeleft,
28 struct list_head *list;
32 /* We don't fail ccanlint for this. */
35 foreach_ptr(list, &m->c_files, &m->h_files) {
36 list_for_each(list, f, list) {
37 char **lines = get_ccan_file_lines(f);
38 for (i = 0; i < f->num_lines; i++) {
39 char *err = get_trailing_whitespace(lines[i]);
41 score_file_error(score, f, i+1,
47 score->score = score->total;
51 struct ccanlint no_trailing_whitespace = {
52 .key = "no_trailing_whitespace",
53 .name = "Module's source code has no trailing whitespace",
54 .check = check_trailing_whitespace,
55 .needs = "info_exists"
59 REGISTER_TEST(no_trailing_whitespace);