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,
26 unsigned int *timeleft,
29 struct list_head *list;
33 /* We don't fail ccanlint for this. */
36 foreach_ptr(list, &m->c_files, &m->h_files) {
37 list_for_each(list, f, list) {
38 char **lines = get_ccan_file_lines(f);
39 for (i = 0; i < f->num_lines; i++) {
40 char *err = get_trailing_whitespace(lines[i]);
42 score_file_error(score, f, i+1,
48 score->score = score->total;
52 struct ccanlint no_trailing_whitespace = {
53 .key = "no_trailing_whitespace",
54 .name = "Module's source code has no trailing whitespace",
55 .check = check_trailing_whitespace,
60 REGISTER_TEST(no_trailing_whitespace);