From bc20504396aa0a062fea42bfe58ddeac5bcae063 Mon Sep 17 00:00:00 2001 From: schwarze Date: Tue, 30 May 2017 19:29:31 +0000 Subject: [PATCH] STYLE message about useless macros we don't want (Bt Tn Ud); not a WARNING because they don't endanger portability --- regress/usr.bin/mandoc/Makefile.inc | 6 +++--- regress/usr.bin/mandoc/mdoc/Tn/noarg.out_lint | 1 + regress/usr.bin/mandoc/mdoc/Ud/arg.out_lint | 6 ++++++ usr.bin/mandoc/mandoc.1 | 16 ++++++++++++++-- usr.bin/mandoc/mandoc.h | 4 +++- usr.bin/mandoc/mdoc_validate.c | 16 ++++++++++++++-- usr.bin/mandoc/read.c | 5 ++++- 7 files changed, 45 insertions(+), 9 deletions(-) diff --git a/regress/usr.bin/mandoc/Makefile.inc b/regress/usr.bin/mandoc/Makefile.inc index 0c640a5bf8c..1f7a138cb62 100644 --- a/regress/usr.bin/mandoc/Makefile.inc +++ b/regress/usr.bin/mandoc/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.22 2017/03/08 22:53:35 schwarze Exp $ +# $OpenBSD: Makefile.inc,v 1.23 2017/05/30 19:29:31 schwarze Exp $ .include "Makefile.sub" @@ -108,7 +108,7 @@ htmlval: ${_HTMLVALS} @${MANDOC} -man -Tascii -Omdoc ${.IMPSRC} > ${.TARGET} .in.mandoc_lint: - @-${MANDOC} ${MOPTS} -Tlint ${.IMPSRC} 2>&1 | \ + @-${MANDOC} ${MOPTS} -Tlint -Wall ${.IMPSRC} 2>&1 | \ sed -E 's/^mandoc: \/[^:]+\//mandoc: /' > ${.TARGET} .mandoc_lint.diff_lint: @@ -289,7 +289,7 @@ ${t}.out_markdown: ${t}.in .for t in ${LINT_TARGETS} ${t}.out_lint: ${t}.in - -${MANDOC} ${MOPTS} -Tlint ${.ALLSRC} > ${.TARGET} 2>&1 + -${MANDOC} ${MOPTS} -Tlint -Wall ${.ALLSRC} > ${.TARGET} 2>&1 .endfor # --- phony targets --- diff --git a/regress/usr.bin/mandoc/mdoc/Tn/noarg.out_lint b/regress/usr.bin/mandoc/mdoc/Tn/noarg.out_lint index 74e0b6fc842..340a3502df2 100644 --- a/regress/usr.bin/mandoc/mdoc/Tn/noarg.out_lint +++ b/regress/usr.bin/mandoc/mdoc/Tn/noarg.out_lint @@ -1 +1,2 @@ mandoc: noarg.in:11:2: WARNING: skipping empty macro: Tn +mandoc: noarg.in:9:2: STYLE: useless macro: Tn diff --git a/regress/usr.bin/mandoc/mdoc/Ud/arg.out_lint b/regress/usr.bin/mandoc/mdoc/Ud/arg.out_lint index 854845cdd40..eac1710faf6 100644 --- a/regress/usr.bin/mandoc/mdoc/Ud/arg.out_lint +++ b/regress/usr.bin/mandoc/mdoc/Ud/arg.out_lint @@ -1,4 +1,10 @@ +mandoc: arg.in:9:2: STYLE: useless macro: Ud +mandoc: arg.in:11:2: STYLE: useless macro: Bt +mandoc: arg.in:15:2: STYLE: useless macro: Ud mandoc: arg.in:15:2: ERROR: skipping all arguments: Ud bar +mandoc: arg.in:16:2: STYLE: useless macro: Bt mandoc: arg.in:16:2: ERROR: skipping all arguments: Bt foo +mandoc: arg.in:17:2: STYLE: useless macro: Ud mandoc: arg.in:17:2: ERROR: skipping all arguments: Ud one +mandoc: arg.in:18:2: STYLE: useless macro: Bt mandoc: arg.in:18:2: ERROR: skipping all arguments: Bt one diff --git a/usr.bin/mandoc/mandoc.1 b/usr.bin/mandoc/mandoc.1 index 155102a33f1..9f69aec68e5 100644 --- a/usr.bin/mandoc/mandoc.1 +++ b/usr.bin/mandoc/mandoc.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: mandoc.1,v 1.112 2017/05/17 23:39:15 schwarze Exp $ +.\" $OpenBSD: mandoc.1,v 1.113 2017/05/30 19:29:31 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: May 17 2017 $ +.Dd $Mdocdate: May 30 2017 $ .Dt MANDOC 1 .Os .Sh NAME @@ -742,6 +742,18 @@ are hidden unless their level, or a lower level, is requested using a option or .Fl T Cm lint output mode. +.Ss Style messages +.Bl -ohang +.It Sy "useless macro" +.Pq mdoc +A +.Ic \&Bt , +.Ic \&Tn , +or +.Ic \Ud +macro was found. +Simply delete it, it serves no useful purpose. +.El .Ss Warnings related to the document prologue .Bl -ohang .It Sy "missing manual title, using UNTITLED" diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index f42429cfee0..46b8e1c35ac 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.158 2017/05/16 19:05:36 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.159 2017/05/30 19:29:31 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -46,6 +46,8 @@ enum mandocerr { MANDOCERR_STYLE, /* ===== start of style suggestions ===== */ + MANDOCERR_MACRO_USELESS, /* useless macro: macro */ + MANDOCERR_WARNING, /* ===== start of warnings ===== */ /* related to the prologue */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 94768022d60..5c3a65b23a8 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.243 2017/05/14 13:59:53 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.244 2017/05/30 19:29:31 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -103,6 +103,7 @@ static void post_sh_authors(POST_ARGS); static void post_sm(POST_ARGS); static void post_st(POST_ARGS); static void post_std(POST_ARGS); +static void post_useless(POST_ARGS); static void post_xr(POST_ARGS); static void post_xx(POST_ARGS); @@ -199,7 +200,7 @@ static const v_post __mdoc_valids[MDOC_MAX - MDOC_Dd] = { post_sm, /* Sm */ post_hyph, /* Sx */ NULL, /* Sy */ - NULL, /* Tn */ + post_useless, /* Tn */ post_xx, /* Ux */ NULL, /* Xc */ NULL, /* Xo */ @@ -669,6 +670,7 @@ post_eoln(POST_ARGS) { struct roff_node *n; + post_useless(mdoc); n = mdoc->last; if (n->child != NULL) mandoc_vmsg(MANDOCERR_ARG_SKIP, mdoc->parse, n->line, @@ -854,6 +856,16 @@ post_obsolete(POST_ARGS) n->line, n->pos, roff_name[n->tok]); } +static void +post_useless(POST_ARGS) +{ + struct roff_node *n; + + n = mdoc->last; + mandoc_msg(MANDOCERR_MACRO_USELESS, mdoc->parse, + n->line, n->pos, roff_name[n->tok]); +} + /* * Block macros. */ diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 1ea665b33b8..24df125f5a9 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.137 2017/05/16 19:05:36 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.138 2017/05/30 19:29:31 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010-2017 Ingo Schwarze @@ -83,6 +83,9 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "ok", "generic style suggestion", + + "useless macro", + "generic warning", /* related to the prologue */ -- 2.20.1