Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 30 May 2018 20:00:45 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Alan Somers <asomers@freebsd.org>
Cc:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   Re: svn commit: r334355 - in user/asomers: . style9
Message-ID:  <20180530193603.S2597@besplex.bde.org>
In-Reply-To: <201805292137.w4TLb2PF080170@repo.freebsd.org>
References:  <201805292137.w4TLb2PF080170@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 29 May 2018, Alan Somers wrote:

> Log:
>  user/asomers/style9: automatic style verifier
>
>  This python script can automatically detect many common style(9) violations.
>
>  Sponsored by:	Spectra Logic Corp
>
> Added:
>  user/asomers/
>  user/asomers/style9/
>  user/asomers/style9/badstyle.c   (contents, props changed)
>  user/asomers/style9/style9.py   (contents, props changed)
>
> Added: user/asomers/style9/badstyle.c
> ==============================================================================
> --- /dev/null	00:00:00 1970	(empty, because file is newly added)
> +++ user/asomers/style9/badstyle.c	Tue May 29 21:37:02 2018	(r334355)
> @@ -0,0 +1,73 @@
> +/*
> + * this is a comment
> + * with text on the last line */
> +
> +/* func on same line as type; OK in a prototype */
> +int foo();

I wonder if the script detects all the style bugs or if so many are
intentional.

I doubt that the following in the above are intentional or can be detected
without full English and C parsers:

- sentences without capitalizaton or punctuation
- indentaation affer type (before function name).  indent(1) will fix this
   and about half of the comment misformatting, but needs a delicate choice
   of options.  I usually tell indent to not reformat comments since comments
   tend to have too many misformattings and rewrapping comments gives enormous
   changes for small bugs.  Declarations are also much less structured than
   statements so I would like to often ignore misformattings in them, but
   indent has no options for that.
- K&R declaration
- comment saying that a K&R declaration is a prototype
- comment saying that something is OK when it is required.

> +
> +

- double vertical spacing.  Extra blank lines are poorly handled by
   indent(1), since some are not extra.  But double blank lines usually
   have at least 1 extra.

> +/* func on same line as type */
> +int foo(){
> +}

- error list incomplete.  This also has the left brace on the same line
   and no space before it.

> +static const struct blargle *myfunc(int x, char *y, struct foo *f){
> +}
> +/* this one is really long */
> +static int zfs_close(vnode_t *vp, int flag, int count, offset_t offset,
> +    cred_t *cr, caller_context_t *ct)

- but better formatted than most long declarations.

> +
> +/* Omit the space after some keywords */

- the rules are not consistenly backwards, so it is not clear which ones
   are parodies

> +int
> +foo(){
> +	if(1) {
> +		while(7){
> +			if (foo){
> +			}
> +		}
> +	}
> +}
> +
> +// A C++ style comment
> +int foo;    //C++ style inline comment

Some rules are not stated as [anti-]rules.

> +
> +
> +/* Solo brace after control block */
> +long
> +bar(){
> +	if (x)
> +	{
> +		1;
> +	}
> +}
> +
> +/* Empty loop with space before the semicolon */
> +float
> +baz()
> +{
> +	for (i=0; i<10; i++) ;
> +}
> +
> +
> +/* bad inline function */
> +inline static int zero(void);
> +
> +/* long control block without braces around single statement body */
> +if (this
> +        && that
> +        && the other)
> +    do_stuff();

- also excessive line splitting
- also gnuish-style formatting of placement of operators after line splitting
   (start new lines with an operator, the opposite to KNF.  Full gnu style
   also requires a different indentation than the above for the operators).

> +
> +
> +/* Return statement without parens around the argument */
> +int
> +foo()
> +{
> +    return 0;
> +}
> +
> +/* Void return statement without parens.  This is ok */
> +void
> +voidfoo()
> +{
> +    return ;
> +}
> +

- also spelling of OK as ok
- also redundant return statement.

Bruce



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20180530193603.S2597>