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 foreach_ptr(list, &m->c_files, &m->h_files) {
34 list_for_each(list, f, list) {
35 char **lines = get_ccan_file_lines(f);
36 for (i = 0; i < f->num_lines; i++) {
37 char *err = get_trailing_whitespace(lines[i]);
39 score_file_error(score, f, i+1, err);
45 score->score = score->total;
49 struct ccanlint no_trailing_whitespace = {
50 .key = "no_trailing_whitespace",
51 .name = "Module's source code has no trailing whitespace",
52 .check = check_trailing_whitespace,
57 REGISTER_TEST(no_trailing_whitespace);