tools/nxstyle.c;: Add check for blank lines before and after single line comments.

This commit is contained in:
Bob Feretich 2018-04-11 15:45:39 -06:00 committed by Gregory Nutt
parent be61157246
commit 7ae14be1de
2 changed files with 59 additions and 0 deletions

View File

@ -926,6 +926,21 @@ uncrustify.cfg
it leaves it alone, but if the block comment is deemed to need a fix it leaves it alone, but if the block comment is deemed to need a fix
it starts erroneously indenting the continuation lines of the comment. it starts erroneously indenting the continuation lines of the comment.
- uncrustify.cfg messed up the indent of most block comments.
cmt_sp_before_star_cont is applied inconsistently. I added
cmt_indent_multi = false # disable all multi-line comment changes
to the .cfg file to limit its damage to block comments.
- It is very strict at wrapping lines at column 78. Even when column 79
just contained the '/' of a closing "*/". That created many
bad continuation lines.
- It moved '{' that opened a struct to the line defining the struct.
nl_struct_brace = add (or force) seemed to be ignored.
- It also aligned variable names in declarations and '=' signs in
assignment statements in a seemingly arbitrary manner. Making changes
that were not necessary.
NOTE: uncrustify.cfg should *ONLY* be used with new files that have an NOTE: uncrustify.cfg should *ONLY* be used with new files that have an
inconsistent coding style. uncrustify.cfg should get you in the ballpark, inconsistent coding style. uncrustify.cfg should get you in the ballpark,
but you should expect to review and hand-edit the files to assume 100% but you should expect to review and hand-edit the files to assume 100%

View File

@ -56,6 +56,7 @@ int main(int argc, char **argv, char **envp)
{ {
FILE *instream; FILE *instream;
char line[LINE_SIZE]; char line[LINE_SIZE];
char *lptr;
bool btabs; bool btabs;
bool bfunctions; bool bfunctions;
bool bstatm; bool bstatm;
@ -73,6 +74,9 @@ int main(int argc, char **argv, char **envp)
int prevncomment; int prevncomment;
int n; int n;
int i; int i;
int last_oneline_comment;
int last_blank_line;
int linelen;
instream = fopen(argv[1], "r"); instream = fopen(argv[1], "r");
if (!instream) if (!instream)
@ -91,6 +95,9 @@ int main(int argc, char **argv, char **envp)
declnest = 0; declnest = 0;
prevdeclnest = 0; prevdeclnest = 0;
prevncomment = 0; prevncomment = 0;
last_oneline_comment = -1; /* Line on which the last one line comment was
* closed */
last_blank_line = -1; /* lineno of last blank line */
while (fgets(line, LINE_SIZE, instream)) while (fgets(line, LINE_SIZE, instream))
{ {
@ -102,6 +109,22 @@ int main(int argc, char **argv, char **envp)
bstatm = false; bstatm = false;
bfor = false; /* REVISIT: Implies for() is all on one line */ bfor = false; /* REVISIT: Implies for() is all on one line */
/* Check for a blank line */
if (line[0] == '\n')
{
last_blank_line = lineno;
}
else /* this line is non-blank */
{
if (lineno == last_oneline_comment + 1)
{
fprintf(stderr,
"Missing blank line after comment line. Found at line %d\n",
last_oneline_comment);
}
}
/* STEP 1: Find the indentation level and the start of real stuff on /* STEP 1: Find the indentation level and the start of real stuff on
* the line. * the line.
*/ */
@ -144,6 +167,27 @@ int main(int argc, char **argv, char **envp)
continue; continue;
} }
/* Check for a single line comment */
linelen = strlen(line);
if (linelen >= 5) /* Minimum is slash, star, star, slash, newline */
{
lptr = strstr(line, "*/");
if (line[indent] == '/' && line[indent +1] == '*' &&
lptr - line == linelen - 3)
{
if (last_oneline_comment != lineno - 1 &&
last_blank_line != lineno - 1)
{
fprintf(stderr,
"Missing blank line before comment found at line %d\n",
lineno);
}
last_oneline_comment = lineno;
}
}
/* Check for the comment block indicating the beginning of functions. */ /* Check for the comment block indicating the beginning of functions. */
if (!bfunctions && ncomment > 0 && if (!bfunctions && ncomment > 0 &&