From: Chris Webb <chris@arachsys.com>
To: git@vger.kernel.org
Subject: [RFC 1/1] Add new indent-with-tab whitespace check
Date: Sat, 27 Mar 2010 14:08:01 +0000 [thread overview]
Message-ID: <1269698881-26443-2-git-send-email-chris@arachsys.com> (raw)
In-Reply-To: <1269698881-26443-1-git-send-email-chris@arachsys.com>
The indent-with-tab rule warns about any tab characters used in initial
indent, and highlights them in git diff --check.
Signed-off-by: Chris Webb <chris@arachsys.com>
---
cache.h | 1 +
ws.c | 26 ++++++++++++++++++++------
2 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/cache.h b/cache.h
index 2928107..d87bd85 100644
--- a/cache.h
+++ b/cache.h
@@ -1040,6 +1040,7 @@ void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *
#define WS_INDENT_WITH_NON_TAB 04
#define WS_CR_AT_EOL 010
#define WS_BLANK_AT_EOF 020
+#define WS_INDENT_WITH_TAB 040
#define WS_TRAILING_SPACE (WS_BLANK_AT_EOL|WS_BLANK_AT_EOF)
#define WS_DEFAULT_RULE (WS_TRAILING_SPACE|WS_SPACE_BEFORE_TAB)
extern unsigned whitespace_rule_cfg;
diff --git a/ws.c b/ws.c
index c089338..e44a711 100644
--- a/ws.c
+++ b/ws.c
@@ -18,6 +18,7 @@ static struct whitespace_rule {
{ "cr-at-eol", WS_CR_AT_EOL, 1 },
{ "blank-at-eol", WS_BLANK_AT_EOL, 0 },
{ "blank-at-eof", WS_BLANK_AT_EOF, 0 },
+ { "indent-with-tab", WS_INDENT_WITH_TAB, 0 },
};
unsigned parse_whitespace_rule(const char *string)
@@ -125,6 +126,11 @@ char *whitespace_error_string(unsigned ws)
strbuf_addstr(&err, ", ");
strbuf_addstr(&err, "indent with spaces");
}
+ if (ws & WS_INDENT_WITH_TAB) {
+ if (err.len)
+ strbuf_addstr(&err, ", ");
+ strbuf_addstr(&err, "indent with tab");
+ }
return strbuf_detach(&err, NULL);
}
@@ -163,23 +169,31 @@ static unsigned ws_check_emit_1(const char *line, int len, unsigned ws_rule,
}
}
- /* Check for space before tab in initial indent. */
+ /* Check for indent using tab or space before tab in initial indent. */
for (i = 0; i < len; i++) {
if (line[i] == ' ')
continue;
if (line[i] != '\t')
break;
- if ((ws_rule & WS_SPACE_BEFORE_TAB) && written < i) {
+ if (ws_rule & WS_INDENT_WITH_TAB) {
+ result |= WS_INDENT_WITH_TAB;
+ if (stream) {
+ fwrite(line + written, i - written, 1, stream);
+ fputs(ws, stream);
+ fwrite(line + i, 1, 1, stream);
+ fputs(reset, stream);
+ }
+ } else if ((ws_rule & WS_SPACE_BEFORE_TAB) && written < i) {
result |= WS_SPACE_BEFORE_TAB;
if (stream) {
fputs(ws, stream);
fwrite(line + written, i - written, 1, stream);
fputs(reset, stream);
+ fwrite(line + i, 1, 1, stream);
}
- } else if (stream)
- fwrite(line + written, i - written, 1, stream);
- if (stream)
- fwrite(line + i, 1, 1, stream);
+ } else if (stream) {
+ fwrite(line + written, i - written + 1, 1, stream);
+ }
written = i + 1;
}
--
1.7.0.1
next prev parent reply other threads:[~2010-03-27 14:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-27 14:08 [RFC 0/1] diff --check for indent-with-spaces style Chris Webb
2010-03-27 14:08 ` Chris Webb [this message]
2010-03-31 16:23 ` [RFC 1/1] Add new indent-with-tab whitespace check Junio C Hamano
2010-04-01 18:51 ` Re* " Junio C Hamano
2010-04-01 19:02 ` Junio C Hamano
2010-04-02 10:55 ` Chris Webb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1269698881-26443-2-git-send-email-chris@arachsys.com \
--to=chris@arachsys.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).