Checking for white-listed prefixes is also simpler now because the check is table driver. New data structure: g_white_prefix[] and new function white_prefix().
Clean up the no and unknown file extension info since only .h and .c
files supported. Just ignore them quietly.
Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
If we are going to use this tool for things like
git pre-commit hook or CI workflow, it's critical to
avoid false alarms.
This reverts commit de764af9aa.
Eliminate warnings. Ignore mixed case identifies beginning with PRIx.
These most likely come from inttypes.h and we nxstyle must tolerate
those definitions even though they do not follow the coding style.
Consider junk.c for example:
/****************************************************************************
* xx
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
struct foo_s
{
int bar;
};
/****************************************************************************
* Public Functions
****************************************************************************/
int dofoo(int barin)
{
barout = barin;
return barout;
}
nxstyle not detects these problems:
$ tools/nxstyle.exe junk.c
junk.c:11:0: error: Blank line before opening left brace
junk.c:21:0: error: Blank line before opening left brace
Commit cf5d17f795 added logic to detect #define pre-processor definitions outside of the "Pre-processor Definitions" file section. That commit was verified against numerous .c source files. But not against any .h header files.
When run against a header file, that change causes a false alarm warning like:
file:line:pos: warning: #define outside of 'Pre-processor Definitions' section
That is caused the idempotence, guard definition that must appear in the header file BEFORE the first file section.
This commit adds logic to nxstyle to ignore pre-processor definitions in header files that occur before the first file section is encountered.
* tools/nxstyle: Added logic to parse section headers (like Included files, Pre-processor Definitions, etc.) and to assure that the section headers are correct for the file type. Also (1) verify that #include appears only in the 'Included Files' section and that (2) #define only occurs in the Pre-processor definition section.
Right now, there are several places where that rule is not followed. I think most of these are acceptable so these failures only generate warnings, not errors. The warning means that we need to go look at the offending #define or #include and decide if it is a acceptable usage or not.
the width of all block comments. Includes a check to assure that all block
comments use the same line width.
Verified against all .c files under /sched. There were a few cosmetic changes to the coding style under /sched to account to new, correctly detected problems in the /sched files.
* tools/nxstyle.c: Donot check unknown file extension files
nxstyle only support c soure file and header file check, donot check
other unknown file extension files.
* tools/checkpatch.sh: Add checkpatch.sh script based on nxstyle tool
Usage:
checkpatch.sh patch-list // default as patch list
checkpatch.sh -p patch-list
checkpatch.sh -c commit-list
checkpatch.sh -f file-list
checkpatch.sh - // read from stdin, which used by git pre-commit hook
And git pre-commit hook could use checkpatch.sh as below:
git diff --cached | ./tools/checkpatch.sh -
Usage: ./nxstyle -r start,count filename
nxstyle with -r option used to parse the range lines rather than the whole file.
Change-Id: I58ec56511fde14d6ec914400a7849e69960a3711
Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
tools/nxstyle.c: Output compiler like error format. Added features
Uses getops to pars command line.
Supports
-s silence all output
-g provide a PASS fail message
* tools/README.txt: Update with new nxstyle options
This change decouples that upper activity-based logic from the lower random walk logic and allows use of other upper state detection logic (such as a custom, application-specific state machine).