From: schwarze Date: Sun, 11 Jun 2017 17:16:36 +0000 (+0000) Subject: style message about missing .Fn markup; inspired by mdoclint X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=48497dd55d11cdab4c05d3b652aff494ea77b23d;p=openbsd style message about missing .Fn markup; inspired by mdoclint --- diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index ce487f7df8e..7eae59f2374 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.121 2017/06/10 01:48:31 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.122 2017/06/11 17:16:36 schwarze Exp $ .\" .\" Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons .\" Copyright (c) 2012, 2014-2017 Ingo Schwarze @@ -15,7 +15,7 @@ .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: June 10 2017 $ +.Dd $Mdocdate: June 11 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -799,10 +799,19 @@ Do not use punctuation at the end of an .Ic \&Nd block. .It Sy "no blank before trailing delimiter" +.Pq mdoc The last argument of a macro that supports trailing delimiter arguments is longer than one byte and ends with a trailing delimiter. Consider inserting a blank such that the delimiter becomes a separate argument, thus moving it out of the scope of the macro. +.It Sy "function name without markup" +.Pq mdoc +A word followed by an empty pair of parentheses occurs on a text line. +Consider using an +.Ic \&Fn +or +.Ic \&Xr +macro. .El .Ss Warnings related to the document prologue .Bl -ohang diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index b839b212061..d659d20d873 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.169 2017/06/10 01:48:31 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.170 2017/06/11 17:16:36 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -52,6 +52,7 @@ enum mandocerr { MANDOCERR_ER_REP, /* duplicate errno: Er ... */ MANDOCERR_ND_DOT, /* description line ends with a full stop */ MANDOCERR_DELIM, /* no blank before trailing delimiter: macro ... */ + MANDOCERR_FUNC, /* function name without markup: name() */ MANDOCERR_WARNING, /* ===== start of warnings ===== */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 57ab101c1d5..b78256c501c 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.250 2017/06/11 14:10:24 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.251 2017/06/11 17:16:36 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -51,10 +51,10 @@ typedef void (*v_post)(POST_ARGS); static int build_list(struct roff_man *, int); static void check_text(struct roff_man *, int, int, char *); -static void check_bsd(struct roff_man *, int, int, char *); static void check_argv(struct roff_man *, struct roff_node *, struct mdoc_argv *); static void check_args(struct roff_man *, struct roff_node *); +static void check_toptext(struct roff_man *, int, int, const char *); static int child_an(const struct roff_node *); static size_t macro2len(enum roff_tok); static void rewrite_macro2len(struct roff_man *, char **); @@ -302,10 +302,11 @@ mdoc_node_validate(struct roff_man *mdoc) if (n->sec != SEC_SYNOPSIS || (n->parent->tok != MDOC_Cd && n->parent->tok != MDOC_Fd)) check_text(mdoc, n->line, n->pos, n->string); - if (n->parent->tok == MDOC_Sh || - n->parent->tok == MDOC_Ss || - n->parent->tok == MDOC_It) - check_bsd(mdoc, n->line, n->pos, n->string); + if (n->parent->tok == MDOC_It || + (n->parent->type == ROFFT_BODY && + (n->parent->tok == MDOC_Sh || + n->parent->tok == MDOC_Ss))) + check_toptext(mdoc, n->line, n->pos, n->string); break; case ROFFT_EQN: case ROFFT_TBL: @@ -388,9 +389,12 @@ check_text(struct roff_man *mdoc, int ln, int pos, char *p) } static void -check_bsd(struct roff_man *mdoc, int ln, int pos, char *p) +check_toptext(struct roff_man *mdoc, int ln, int pos, const char *p) { - const char *cp; + const char *cp, *cpr; + + if (*p == '\0') + return; if ((cp = strstr(p, "OpenBSD")) != NULL) mandoc_msg(MANDOCERR_BX, mdoc->parse, @@ -404,6 +408,19 @@ check_bsd(struct roff_man *mdoc, int ln, int pos, char *p) if ((cp = strstr(p, "DragonFly")) != NULL) mandoc_msg(MANDOCERR_BX, mdoc->parse, ln, pos + (cp - p), "Dx"); + + cp = p; + while ((cp = strstr(cp + 1, "()")) != NULL) { + for (cpr = cp - 1; cpr >= p; cpr--) + if (*cpr != '_' && !isalnum((unsigned char)*cpr)) + break; + if ((cpr < p || *cpr == ' ') && cpr + 1 < cp) { + cpr++; + mandoc_vmsg(MANDOCERR_FUNC, mdoc->parse, + ln, pos + (cpr - p), + "%.*s()", (int)(cp - cpr), cpr); + } + } } static void diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 6bd7ec794f4..4de20b114ac 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.146 2017/06/10 01:48:31 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.147 2017/06/11 17:16:36 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -90,6 +90,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "duplicate errno", "description line ends with a full stop", "no blank before trailing delimiter", + "function name without markup", "generic warning",