The returned string should be freed by the caller. */
| 112 | |
| 113 | /* The returned string should be freed by the caller. */ |
| 114 | char *whitespace_error_string(unsigned ws) |
| 115 | { |
| 116 | struct strbuf err = STRBUF_INIT; |
| 117 | if ((ws & WS_TRAILING_SPACE) == WS_TRAILING_SPACE) |
| 118 | strbuf_addstr(&err, "trailing whitespace"); |
| 119 | else { |
| 120 | if (ws & WS_BLANK_AT_EOL) |
| 121 | strbuf_addstr(&err, "trailing whitespace"); |
| 122 | if (ws & WS_BLANK_AT_EOF) { |
| 123 | if (err.len) |
| 124 | strbuf_addstr(&err, ", "); |
| 125 | strbuf_addstr(&err, "new blank line at EOF"); |
| 126 | } |
| 127 | } |
| 128 | if (ws & WS_SPACE_BEFORE_TAB) { |
| 129 | if (err.len) |
| 130 | strbuf_addstr(&err, ", "); |
| 131 | strbuf_addstr(&err, "space before tab in indent"); |
| 132 | } |
| 133 | if (ws & WS_INDENT_WITH_NON_TAB) { |
| 134 | if (err.len) |
| 135 | strbuf_addstr(&err, ", "); |
| 136 | strbuf_addstr(&err, "indent with spaces"); |
| 137 | } |
| 138 | if (ws & WS_TAB_IN_INDENT) { |
| 139 | if (err.len) |
| 140 | strbuf_addstr(&err, ", "); |
| 141 | strbuf_addstr(&err, "tab in indent"); |
| 142 | } |
| 143 | if (ws & WS_INCOMPLETE_LINE) { |
| 144 | if (err.len) |
| 145 | strbuf_addstr(&err, ", "); |
| 146 | strbuf_addstr(&err, "no newline at the end of file"); |
| 147 | } |
| 148 | return strbuf_detach(&err, NULL); |
| 149 | } |
| 150 | |
| 151 | /* If stream is non-NULL, emits the line after checking. */ |
| 152 | static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule, |
no test coverage detected