Coder Social home page Coder Social logo

dougpuob / cppnamelint Goto Github PK

View Code? Open in Web Editor NEW
55.0 2.0 9.0 838 KB

CppNameLint is a naming convention linter of C/C++ source code (Based on LLVM's libtooling), which runs with command line on Windows/Linux/macOS.

License: MIT License

CMake 1.59% C++ 87.54% Python 7.75% Shell 0.56% PowerShell 2.55%
llvm clang libtooling linter naming naming-conventions cppnamelint

cppnamelint's Introduction

CppNameLint

My name is "Upper camel" My name is Upper Camel. (My partner drew this mascot for the project)

Windows Linux macOS

The project is a naming convention checking tool executing on Windows/Linux/MacOS. It is based on LLVM's LibTooling as a compiler frontend to retrieve AST of C/C++ source files, then check your naming convention.

  1. Check for C and C++ programming languages.
  2. Check naming of file, functions, variables, and parameters.
  3. Execute on Windows/Linux/macOS.
  4. Load config file format with TOML.
  5. Output results to console or save an a JSON file.
  6. Support rules with UpperCamelCase, lowerCamelCase, UPPER_SNAKE_CASE, lower_snake_case, and szHungarainNotion.
  7. Integrate with Azure DevOps(CI/CD).

⭐If you like this project or this project gives you some help, please also give me a STAR on GitHub, let me know I am not alone.

————————————————————————————————————————————

● Quick Start

  1. You are an user:

  2. You are a developer

————————————————————————————————————————————

● Usage

Commands

  1. Run Check command

    # Check source file with a specfic config file.  
    $ cppnamelint check YouPlayGround.cpp -config cppnamelint.toml
    
    # Check source file with a specfic config file, and specific header directories (Dir1 and Dir2)
    $ cppnamelint check YouPlayGround.cpp -config cppnamelint.toml -include Dir1 -include Dir2
    
    # Check source file with a specfic config file, and save check result as a JSON file to the specific path.  
    $ cppnamelint check YouPlayGround.cpp -config cppnamelint.toml -jsonout result.json
    
    # Check source file with a specfic config file, and save log to the specific path.  
    $ cppnamelint check YouPlayGround.cpp -config cppnamelint.toml -logfile logout.log
    $ cppnamelint check YouPlayGround.cpp -config cppnamelint.toml -jsonout result.json -logfile logout.log

  2. Run Test command

    # Run Unit Test (Google Test)
    $ cppnamelint test

Helps

# Show usage help to subcommands.
$ cppnamelint -help

# Show usage help to `check` subcommand.
$ cppnamelint check -help

————————————————————————————————————————————

● Tests

Unit Test

Unit Test

————————————————————————————————————————————

● Scripts

cppnamelint.py

This is a Python script, which privodes several features:

  1. Integrate automation with CI/CD (build, packing, and test).
  2. Enhance cppnamelint utility, making it more convenient to integrated into your project.
$ python .\cppnamelint.py -h
usage: cppnamelint.py [-h] [-verbose] [-dbg] [-log LOG]
                      {check,checkdir,format,test,chkenv,bldgtest,bldgpack,bldgcfg} ...

positional arguments:
  {check,checkdir,format,test,chkenv,bldgtest,bldgpack,bldgcfg}
    check               check command
    checkdir            checkdir command
    format              format command
    test                test command
    chkenv              chkenv command for checking build environment
    bldgtest            bldgtest command for building this project
    bldgpack            bldgpack command for packing this project
    bldgcfg             bldgcfg command for doing config via Cmake

optional arguments:
  -h, --help            show this help message and exit
  -verbose              increase output verbosity
  -dbg                  enable debug mode output verbosity
  -log LOG              log file path

Commands

  1. Check whole files in a specfic directory
     $ python .\cppnamelint.py checkdir -h
     usage: cppnamelint.py checkdir [-h] [-cfg CFG] [-json JSON] [-inc INC] srcdir
    
     positional arguments:
       srcdir      Input source code file dir
    
     optional arguments:
       -h, --help  show this help message and exit
       -cfg CFG    Config file path
       -json JSON  Json result output file path
       -inc INC    None or more include directory. (-inc Dir1 -inc Dir2 ...)
     
     
    # Check source file with a specfic config file.  
    $ python .\cppnamelint.py checkdir ../source -cfg ../cppnamelint.toml

————————————————————————————————————————————

● Screenshots

Passed case

C:\>cppnamelint.exe check YouPlayGround.cpp -config cppnamelint.toml
cppnamelint utility v0.3.1
---------------------------------------------------
 File    = YouPlayGround.cpp
 Config  = cppnamelint.toml
 Checked =     6  [File:0 | Func:  5 | Param:  1 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     0  [File:0 | Func:  0 | Param:  0 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------

Passed Case

Failed case

C:\>cppnamelint.exe check YouPlayGround.cpp -config cppnamelint.toml
cppnamelint utility v0.3.1
---------------------------------------------------
 File    = YouPlayGround.cpp
 Config  = cppnamelint.toml
 Checked =     6  [File:0 | Func:  5 | Param:  1 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     1  [File:0 | Func:  0 | Param:  1 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------
  <  16,   25> Parameter : inputValue (int)
------------------------------------------------------------

Failed Case

Others

  • Check command with -verbose option.

  • JSON result (Good case)

  • JSON result (Bad case)

      [{
        "Checked": {
            "Function": 5,
            "Parameter": 1,
            "Variable": 0
        },
        "Error": {
            "Function": 0,
            "Parameter": 1,
            "Variable": 0
        },
        "ErrorDetailList": [
            {
                "Column": 25,
                "Expected": "",
                "Line": 16,
                "TargetName": "inputValue",
                "Type": 4,
                "TypeName": "int"
            }
        ],
        "File": {
            "Config": "cppnamelint.toml",
            "Source": "C:\\petzone\\cpp-namelint\\sample\\YouPlayGround.cpp"
        }
    }]

————————————————————————————————————————————

● License

MIT

————————————————————————————————————————————

● Author

Douglas Chen [email protected]

cppnamelint's People

Contributors

brlin-tw avatar codacy-badger avatar dougpuob avatar hackmd-deploy avatar neville1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

cppnamelint's Issues

Less findings than expected

Note: This is a follow up for the 0.3.4 fix.

I did some checks with the new version and there are far less findings than I would expect.
Again I used https://github.com/changkun/modern-cpp-tutorial for you to reproduce.
I also used the default toml config file from the cppnamelint repo.
I reduced the scope of the tests arbitrarily to §10 in the tutorial.
What I get:

cppnamelint utility v0.3.4
---------------------------------------------------
 File    = 10.1.without.concepts.cpp
 Config  = cppnamelint.toml
 Checked =     2  [File:0 | Func:  1 | Param:  0 | Var:  1 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     1  [File:0 | Func:  0 | Param:  0 | Var:  1 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------
  <  15,    5> Variable  : l (std::list<int>)

cppnamelint utility v0.3.4
---------------------------------------------------
 File    = 10.2.concepts.cpp
 Config  = cppnamelint.toml
 Checked =     0  [File:0 | Func:  0 | Param:  0 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     0  [File:0 | Func:  0 | Param:  0 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------

The first file report looks reasonable, but in the second there are no checks at all. Not evene the "struct Person" is detected.

I cross checked with YouPlayGround.cpp from the repo:

cppnamelint utility v0.3.4
---------------------------------------------------
 File    = YouPlayGround.cpp
 Config  = cppnamelint.toml
 Checked =     6  [File:0 | Func:  5 | Param:  1 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     1  [File:0 | Func:  0 | Param:  1 | Var:  0 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------
  <  16,   25> Parameter : InputC (int)

this looks as expected

Please also note that the "-logfile" option causes cppnamelint to coredump / die with signal 11.

Can you please check? Thanks!

Unexpected report when using ClassName=UpperCamel

I am using release v0.3.4 on Windows 10, following is my cppnamelint.toml:

...
ClassName               = 1 # 0: Default (UpperCamel)
                            # 1: UpperCamel
...

Either I set this value to 0 or 1, it will wrongly report that my class name violates the rule, following is the formatted result.json:

            {
                "Column": 1,
                "Expected": "",
                "Line": 46,
                "TargetName": "XxxxXxxx",
                "Type": 5,
                "TypeName": "class"
            }

Could not find a package configuration file

I've gone through a process of installing LLVM based on instructions from these two webpages:

There was an error due to numeric_limits not being a member of std but I believe I solved that or worked around it

And then attempting to install cppnamelint, but I get an error when trying to run:

cmake .. -DLLVM_INSTALL_DIR="~\llvm\llvm-prebuilt\llvmorg-11.1.0-ninja-gcc-x64-rel"

as follows:

CMake Error at CMakeLists.txt:41 (find_package):
  Could not find a package configuration file provided by "LLVM" with any of
  the following names:

    LLVMConfig.cmake
    llvm-config.cmake

  Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
  "LLVM_DIR" to a directory containing one of the above files.  If "LLVM"
  provides a separate development package or SDK, be sure it has been
  installed.

Unsure what the problem is, as I believe I've set the environment variables but I may have set them wrong, I've set them to all the locations LLVMConfig.cmake exist but rerunning the command still produces the same error, would anyone also know what I need to do to set these correctly please?

I could also be doing something wrong in my build steps, but any help is greatly appreciated, thanks in advance.

Specific rule to check private member variable

We follow this C++ coding style rule, and its 11th rule says that private member variable name should be like length_. But currently all varaibles are in the same group, so I can't make only "private member variable" be checked by its specific rule.

Also, can you please add a rule of "lower_snake_"(lower_snake + underscore), thanks!

[Bug] Build failed with undefined reference to `setupterm' on Ubuntu Linux

  • undefined reference to setupterm
  • undefined reference to tigetnum
  • undefined reference to set_curterm
  • undefined reference to del_curterm

LLVM libraries built with this command

$ cmake -DLLVM_ENABLE_PROJECTS=clang -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_RTTI=ON -G "Unix Makefiles" ../llvm

Full error message

[ 80%] Linking CXX executable Output/cppnamelint
/home/dougpuob/working-folder/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Process.cpp.o): In function `llvm::sys::Process::FileDescriptorHasColors(int)':
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi+0x5c): undefined reference to `setupterm'
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi+0x6c): undefined reference to `tigetnum'
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi+0x78): undefined reference to `set_curterm'
Process.cpp:(.text._ZN4llvm3sys7Process23FileDescriptorHasColorsEi+0x80): undefined reference to `del_curterm'
collect2: error: ld returned 1 exit status
CMakeFiles/cppnamelint.dir/build.make:306: recipe for target 'Output/cppnamelint' failed
make[2]: *** [Output/cppnamelint] Error 1
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/cppnamelint.dir/all' failed
make[1]: *** [CMakeFiles/cppnamelint.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

image

[Bug] Failed to build on Windows (MSVC showed `error C2001: newline in constant` )

12>cppnamelint.git\Module\nlohmannjson.git\test\src\unit-udt.cpp : warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
12>cppnamelint.git\Module\nlohmannjson.git\test\src\unit-udt.cpp(115): error C2001: newline in constant

undefined reference to `llvm::EnableABIBreakingChecks'

Error message when build this project for Release version on Linux/macOS (Windows is OK).

Error Message

CMakeFiles/namelint.dir/Source/ParseAST.cpp.o:(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
CMakeFiles/namelint.dir/Source/Main.cpp.o:(.data.rel+0x0): undefined reference to `llvm::EnableABIBreakingChecks'
collect2: error: ld returned 1 exit status
CMakeFiles/namelint.dir/build.make:228: recipe for target 'Output/namelint' failed
make[2]: *** [Output/namelint] Error 1
make[2]: Leaving directory '/home/dougpuob/working-folder/namelint.git/Build/linux'
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/namelint.dir/all' failed
make[1]: *** [CMakeFiles/namelint.dir/all] Error 2
make[1]: Leaving directory '/home/dougpuob/working-folder/namelint.git/Build/linux'
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

[Request] Detect `struct` and `enum`

#include <stdint.h>

typedef struct _MY_DATA {
    uint8_t u8Value1;
    uint8_t u8Value2;
    uint8_t u8Value3;
    uint8_t u8Value4;    
} MY_DATA;

typedef enum _MY_CHOICE {
    MY_CHOICE_A,
    MY_CHOICE_B,
    MY_CHOICE_C,
    MY_CHOICE_D,
} MY_CHOICE;
|-CXXRecordDecl 0x1938b8f5a30 <C:\working-folder\opensrc\dougpuob\cpp-namelint.git\Source\Test\Sample\Sample_06.cpp:3:9, line:8:1> line:3:16 struct _MY_DATA definition
| |-DefinitionData pass_in_registers aggregate standard_layout trivially_copyable pod trivial literal
| | |-DefaultConstructor exists trivial needs_implicit
| | |-CopyConstructor simple trivial has_const_param needs_implicit implicit_has_const_param
| | |-MoveConstructor exists simple trivial needs_implicit
| | |-CopyAssignment trivial has_const_param needs_implicit implicit_has_const_param
| | |-MoveAssignment exists simple trivial needs_implicit
| | `-Destructor simple irrelevant trivial needs_implicit
| |-CXXRecordDecl 0x1938b8f5b58 <col:9, col:16> col:16 implicit struct _MY_DATA
| |-FieldDecl 0x1938b8f5c20 <line:4:5, col:13> col:13 u8Value1 'uint8_t':'unsigned char'
| |-FieldDecl 0x1938b8f5c80 <line:5:5, col:13> col:13 u8Value2 'uint8_t':'unsigned char'
| |-FieldDecl 0x1938b8f5ce0 <line:6:5, col:13> col:13 u8Value3 'uint8_t':'unsigned char'
| `-FieldDecl 0x1938b8f5d40 <line:7:5, col:13> col:13 u8Value4 'uint8_t':'unsigned char'
|-TypedefDecl 0x1938b8f5e08 <line:3:1, line:8:3> col:3 MY_DATA 'struct _MY_DATA':'_MY_DATA'
| `-ElaboratedType 0x1938b8f5db0 'struct _MY_DATA' sugar
|   `-RecordType 0x1938b8f5ad0 '_MY_DATA'
|     `-CXXRecord 0x1938b8f5a30 '_MY_DATA'
|-EnumDecl 0x1938b8f5e70 <line:10:9, line:15:1> line:10:14 _MY_CHOICE
| |-EnumConstantDecl 0x1938b8f5f30 <line:11:5> col:5 MY_CHOICE_A '_MY_CHOICE'
| |-EnumConstantDecl 0x1938b8f5f80 <line:12:5> col:5 MY_CHOICE_B '_MY_CHOICE'
| |-EnumConstantDecl 0x1938b8f5fd0 <line:13:5> col:5 MY_CHOICE_C '_MY_CHOICE'
| `-EnumConstantDecl 0x1938b8f6020 <line:14:5> col:5 MY_CHOICE_D '_MY_CHOICE'
`-TypedefDecl 0x1938b8f60c8 <line:10:1, line:15:3> col:3 MY_CHOICE 'enum _MY_CHOICE':'_MY_CHOICE'
  `-ElaboratedType 0x1938b8f6070 'enum _MY_CHOICE' sugar
    `-EnumType 0x1938b8f5f10 '_MY_CHOICE'
      `-Enum 0x1938b8f5e70 '_MY_CHOICE'

[Bug] Build failed with undefined reference to 'crc32' on Ubuntu Linux

Even I built with -lz option, but it still showed the following error.

  • Compression.cpp: undefined reference to `compressBound'
  • Compression.cpp: undefined reference to `compress2'
  • undefined reference to `uncompress'
  • undefined reference to `crc32'

Error Message

[ 35%] Linking CXX executable Output/cppnamelint
/usr/bin/cmake -E cmake_link_script CMakeFiles/cppnamelint.dir/link.txt --verbose=1
/usr/bin/g++-8  -frtti -lz -ltinfo -O3 -DNDEBUG   CMakeFiles/cppnamelint.dir/Source/Main.cpp.o CMakeFiles/cppnamelint.dir/Source/Detection.cpp.o CMakeFiles/cppnamelint.dir/Source/Common.cpp.o CMakeFiles/cppnamelint.dir/Source/Config.cpp.o CMakeFiles/cppnamelint.dir/Source/MyFactory.cpp.o CMakeFiles/cppnamelint.dir/Source/MyAstVisitor.cpp.o CMakeFiles/cppnamelint.dir/Source/MyAstConsumer.cpp.o CMakeFiles/cppnamelint.dir/Source/Test/TestConfig.cpp.o CMakeFiles/cppnamelint.dir/Source/Test/TestDetection.cpp.o  -o Output/cppnamelint  -L/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib -Wl,-rpath,/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib Module/docopt.cpp/libdocopt.a lib/libgtest.a lib/libgtest_main.a -lclangAnalysis -lclangARCMigrate -lclangAST -lclangASTMatchers -lclangBasic -lclangCodeGen -lclangCrossTU -lclangDriver -lclangDynamicASTMatchers -lclangEdit -lclangFormat -lclangFrontend -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangIndex -lclangLex -lclangParse -lclangRewrite -lclangRewriteFrontend -lclangSema -lclangSerialization -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor -lLLVMAArch64AsmParser -lLLVMAArch64AsmPrinter -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Disassembler -lLLVMAArch64Info -lLLVMAArch64Utils -lLLVMAggressiveInstCombine -lLLVMAMDGPUAsmParser -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUDisassembler -lLLVMAMDGPUInfo -lLLVMAMDGPUUtils -lLLVMAnalysis -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMDisassembler -lLLVMARMInfo -lLLVMARMUtils -lLLVMAsmParser -lLLVMAsmPrinter -lLLVMBinaryFormat -lLLVMBitReader -lLLVMBitWriter -lLLVMBPFAsmParser -lLLVMBPFAsmPrinter -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFDisassembler -lLLVMBPFInfo -lLLVMCodeGen -lLLVMCore -lLLVMCoroutines -lLLVMCoverage -lLLVMDebugInfoCodeView -lLLVMDebugInfoDWARF -lLLVMDebugInfoMSF -lLLVMDebugInfoPDB -lLLVMDemangle -lLLVMDlltoolDriver -lLLVMExecutionEngine -lLLVMFuzzMutate -lLLVMGlobalISel -lLLVMHexagonAsmParser -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonDisassembler -lLLVMHexagonInfo -lLLVMInstCombine -lLLVMInstrumentation -lLLVMInterpreter -lLLVMipo -lLLVMIRReader -lLLVMLanaiAsmParser -lLLVMLanaiAsmPrinter -lLLVMLanaiCodeGen -lLLVMLanaiDesc -lLLVMLanaiDisassembler -lLLVMLanaiInfo -lLLVMLibDriver -lLLVMLineEditor -lLLVMLinker -lLLVMLTO -lLLVMMC -lLLVMMCDisassembler -lLLVMMCJIT -lLLVMMCParser -lLLVMMipsAsmParser -lLLVMMipsAsmPrinter -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsDisassembler -lLLVMMipsInfo -lLLVMMIRParser -lLLVMMSP430AsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMNVPTXAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMObjCARCOpts -lLLVMObject -lLLVMObjectYAML -lLLVMOption -lLLVMOrcJIT -lLLVMPasses -lLLVMPowerPCAsmParser -lLLVMPowerPCAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCDisassembler -lLLVMPowerPCInfo -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSparcAsmParser -lLLVMSparcAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcDisassembler -lLLVMSparcInfo -lLLVMSupport -lLLVMSymbolize -lLLVMSystemZAsmParser -lLLVMSystemZAsmPrinter -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZDisassembler -lLLVMSystemZInfo -lLLVMTableGen -lLLVMTarget -lLLVMTestingSupport -lLLVMTransformUtils -lLLVMVectorize -lLLVMWindowsManifest -lLLVMX86AsmParser -lLLVMX86AsmPrinter -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Disassembler -lLLVMX86Info -lLLVMX86Utils -lLLVMXCoreAsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreDisassembler -lLLVMXCoreInfo -lLLVMXRay -lLTO -lclangParse -lclangSerialization -lclangDriver -lclangIndex -lclangSema -lclangAnalysis -lclangAST -lclangFrontend -lclangEdit -lclangLex -lclangBasic -lLLVMSupport -lLLVMCore -lLLVMMC lib/libgtest.a -lpthread -lclangARCMigrate -lclangASTMatchers -lclangCodeGen -lclangCrossTU -lclangDynamicASTMatchers -lclangFormat -lclangFrontendTool -lclangHandleCXX -lclangHandleLLVM -lclangRewrite -lclangRewriteFrontend -lclangStaticAnalyzerCheckers -lclangStaticAnalyzerCore -lclangStaticAnalyzerFrontend -lclangTooling -lclangToolingASTDiff -lclangToolingCore -lclangToolingInclusions -lclangToolingRefactor -lLLVMAArch64AsmParser -lLLVMAArch64AsmPrinter -lLLVMAArch64CodeGen -lLLVMAArch64Desc -lLLVMAArch64Disassembler -lLLVMAArch64Info -lLLVMAArch64Utils -lLLVMAggressiveInstCombine -lLLVMAMDGPUAsmParser -lLLVMAMDGPUAsmPrinter -lLLVMAMDGPUCodeGen -lLLVMAMDGPUDesc -lLLVMAMDGPUDisassembler -lLLVMAMDGPUInfo -lLLVMAMDGPUUtils -lLLVMAnalysis -lLLVMARMAsmParser -lLLVMARMAsmPrinter -lLLVMARMCodeGen -lLLVMARMDesc -lLLVMARMDisassembler -lLLVMARMInfo -lLLVMARMUtils -lLLVMAsmParser -lLLVMAsmPrinter -lLLVMBinaryFormat -lLLVMBitReader -lLLVMBitWriter -lLLVMBPFAsmParser -lLLVMBPFAsmPrinter -lLLVMBPFCodeGen -lLLVMBPFDesc -lLLVMBPFDisassembler -lLLVMBPFInfo -lLLVMCodeGen -lLLVMCoroutines -lLLVMCoverage -lLLVMDebugInfoCodeView -lLLVMDebugInfoDWARF -lLLVMDebugInfoMSF -lLLVMDebugInfoPDB -lLLVMDemangle -lLLVMDlltoolDriver -lLLVMExecutionEngine -lLLVMFuzzMutate -lLLVMGlobalISel -lLLVMHexagonAsmParser -lLLVMHexagonCodeGen -lLLVMHexagonDesc -lLLVMHexagonDisassembler -lLLVMHexagonInfo -lLLVMInstCombine -lLLVMInstrumentation -lLLVMInterpreter -lLLVMipo -lLLVMIRReader -lLLVMLanaiAsmParser -lLLVMLanaiAsmPrinter -lLLVMLanaiCodeGen -lLLVMLanaiDesc -lLLVMLanaiDisassembler -lLLVMLanaiInfo -lLLVMLibDriver -lLLVMLineEditor -lLLVMLinker -lLLVMLTO -lLLVMMCDisassembler -lLLVMMCJIT -lLLVMMCParser -lLLVMMipsAsmParser -lLLVMMipsAsmPrinter -lLLVMMipsCodeGen -lLLVMMipsDesc -lLLVMMipsDisassembler -lLLVMMipsInfo -lLLVMMIRParser -lLLVMMSP430AsmPrinter -lLLVMMSP430CodeGen -lLLVMMSP430Desc -lLLVMMSP430Info -lLLVMNVPTXAsmPrinter -lLLVMNVPTXCodeGen -lLLVMNVPTXDesc -lLLVMNVPTXInfo -lLLVMObjCARCOpts -lLLVMObject -lLLVMObjectYAML -lLLVMOption -lLLVMOrcJIT -lLLVMPasses -lLLVMPowerPCAsmParser -lLLVMPowerPCAsmPrinter -lLLVMPowerPCCodeGen -lLLVMPowerPCDesc -lLLVMPowerPCDisassembler -lLLVMPowerPCInfo -lLLVMProfileData -lLLVMRuntimeDyld -lLLVMScalarOpts -lLLVMSelectionDAG -lLLVMSparcAsmParser -lLLVMSparcAsmPrinter -lLLVMSparcCodeGen -lLLVMSparcDesc -lLLVMSparcDisassembler -lLLVMSparcInfo -lLLVMSymbolize -lLLVMSystemZAsmParser -lLLVMSystemZAsmPrinter -lLLVMSystemZCodeGen -lLLVMSystemZDesc -lLLVMSystemZDisassembler -lLLVMSystemZInfo -lLLVMTableGen -lLLVMTarget -lLLVMTestingSupport -lLLVMTransformUtils -lLLVMVectorize -lLLVMWindowsManifest -lLLVMX86AsmParser -lLLVMX86AsmPrinter -lLLVMX86CodeGen -lLLVMX86Desc -lLLVMX86Disassembler -lLLVMX86Info -lLLVMX86Utils -lLLVMXCoreAsmPrinter -lLLVMXCoreCodeGen -lLLVMXCoreDesc -lLLVMXCoreDisassembler -lLLVMXCoreInfo -lLLVMXRay -lLTO 
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::compress(llvm::StringRef, llvm::SmallVectorImpl<char>&, int)':
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x2f): undefined reference to `compressBound'
Compression.cpp:(.text._ZN4llvm4zlib8compressENS_9StringRefERNS_15SmallVectorImplIcEEi+0x52): undefined reference to `compress2'
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::uncompress(llvm::StringRef, char*, unsigned long&)':
Compression.cpp:(.text._ZN4llvm4zlib10uncompressENS_9StringRefEPcRm+0x2a): undefined reference to `uncompress'
/home/dougpuob/my-data/my-repo/llvm-project/8.0.0/build/lib/libLLVMSupport.a(Compression.cpp.o): In function `llvm::zlib::crc32(llvm::StringRef)':
Compression.cpp:(.text._ZN4llvm4zlib5crc32ENS_9StringRefE+0xc): undefined reference to `crc32'
collect2: error: ld returned 1 exit status
CMakeFiles/cppnamelint.dir/build.make:306: recipe for target 'Output/cppnamelint' failed
make[2]: *** [Output/cppnamelint] Error 1
make[2]: Leaving directory '/home/dougpuob/my-data/my-repo/cppnamelint.git/Build/linux'
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/cppnamelint.dir/all' failed
make[1]: *** [CMakeFiles/cppnamelint.dir/all] Error 2
make[1]: Leaving directory '/home/dougpuob/my-data/my-repo/cppnamelint.git/Build/linux'
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2

image

Build fails with latest llvm

ok, not really a bug, as it should work with llvm 8 only ...
LLVM_DIR_CPPNAMELINT_PATH : xxx/llvm-project/build/release/lib
is wrong for me, I have xxx/llvm-project/build/lib only; fixed it with a link
then I get:
/usr/bin/ld: cannot find -lclangToolingRefactor (which is now called libclangToolingRefactoring)
/usr/bin/ld: cannot find -lLLVMX86AsmPrinter (not available in my build)
Just removing these libs from CMakeLists.txt was not successfull (no surprise).

I did some more tests to get that fixed.
By adding all llvm-13 libs to the CMakeLists.txt I was finally able to build cppnamelint, but then I get a runtime error:
: CommandLine Error: Option 'opt-bisect-limit' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
Aborted (core dumped)
which indicates a library load issue which I could not solve in a reasonable time.
But at least it looks as if an update to latest llvm is possible.

Most checks with c++ files fail with "Error while processing" (v0.3.3)

cppnamelint check ...
using default cppnamelint.toml

with -verbose and -logfile=... I get some more infos:

  1. terminated by signal 11

  2. log:
    [123211][Main.cpp!LogConfig@232 ] CheckSubcommand = 1866688367
    [123211][Main.cpp!LogConfig@233 ] TestSubcommand = 1866688367
    [123211][Main.cpp!LogConfig@235 ] bCheckFileName = 1866688367
    [123211][Main.cpp!LogConfig@236 ] bCheckFunctionName = 1866688367
    [123211][Main.cpp!LogConfig@238 ] bCheckEnum = 1866688367
    [123211][Main.cpp!LogConfig@239 ] bCheckStruct = 1866688367
    [123211][Main.cpp!LogConfig@240 ] bCheckVariableName = 1866688367
    [123211][Main.cpp!LogCheckResult@247 ] Assert.nErrorOccurred = 1699900259
    [123211][Main.cpp!LogCheckResult@248 ] Assert.nInvalidDecl = 1699900259
    [123211][Main.cpp!LogCheckResult@249 ] Assert.nNumWarnings = 1699900259
    [123211][Main.cpp!LogCheckResult@251 ] Checked.nClass = 1699900259
    [123211][Main.cpp!LogCheckResult@252 ] Checked.nEnum = 1699900259
    [123211][Main.cpp!LogCheckResult@253 ] Checked.nFile = 1699900259
    [123211][Main.cpp!LogCheckResult@254 ] Checked.nFunction = 1699900259
    [123211][Main.cpp!LogCheckResult@255 ] Checked.nParameter = 1699900259
    [123211][Main.cpp!LogCheckResult@256 ] Checked.nStruct = 1699900259
    [123211][Main.cpp!LogCheckResult@257 ] Checked.nUnion = 1699900259
    [123211][Main.cpp!LogCheckResult@258 ] Checked.nVariable = 1699900259
    [123211][Main.cpp!LogCheckResult@260 ] Error.nClass = 1699900259
    [123211][Main.cpp!LogCheckResult@261 ] Error.nEnum = 1699900259
    [123211][Main.cpp!LogCheckResult@262 ] Error.nFile = 1699900259
    [123211][Main.cpp!LogCheckResult@263 ] Error.nFunction = 1699900259
    [123211][Main.cpp!LogCheckResult@264 ] Error.nParameter = 1699900259
    [123211][Main.cpp!LogCheckResult@265 ] Error.nStruct = 1699900259
    [123211][Main.cpp!LogCheckResult@266 ] Error.nUnion = 1699900259
    [123211][Main.cpp!LogCheckResult@267 ] Error.nVariable = 1699900259
    [123211][Main.cpp!main@334 ] Program is going to close. (iRet=1852399981)
    [123450][Main.cpp!LogConfig@232 ] CheckSubcommand = 1866688367
    [123450][Main.cpp!LogConfig@233 ] TestSubcommand = 1866688367
    [123450][Main.cpp!LogConfig@235 ] bCheckFileName = 1866688367
    [123450][Main.cpp!LogConfig@236 ] bCheckFunctionName = 1866688367
    [123450][Main.cpp!LogConfig@238 ] bCheckEnum = 1866688367
    [123450][Main.cpp!LogConfig@239 ] bCheckStruct = 1866688367
    [123450][Main.cpp!LogConfig@240 ] bCheckVariableName = 1866688367

  3. A success looks like so:
    cppnamelint utility v0.3.3


clang version 8.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/user/bin/cppnamelint
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version 10.0
clang Invocation:
"/home/user/bin/cppnamelint/clang-tool" "-cc1" "-triple" "x86_64-unknown-linux-gnu" "-fsyntax-only" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "measure_cmd_client.h" "-mrelocation-model" "static" "-mthread-model" "posix" "-mdisable-fp-elim" "-fmath-errno" "-masm-verbose" "-mconstructor-aliases" "-munwind-tables" "-fuse-init-array" "-target-cpu" "x86-64" "-dwarf-column-info" "-debugger-tuning=gdb" "-v" "-resource-dir" "/home/user/bin/cppnamelint/../lib/clang/8.0.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0" "-internal-isystem" "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward" "-internal-isystem" "/usr/local/include" "-internal-isystem" "/home/user/bin/cppnamelint/../lib/clang/8.0.0/include" "-internal-externc-isystem" "/usr/include/x86_64-linux-gnu" "-internal-externc-isystem" "/include" "-internal-externc-isystem" "/usr/include" "-fdeprecated-macro" "-fdebug-compilation-dir" "/home/user/projects/embedded-linux/apps/hr-radar/6455/apps/measure_cmd/client" "-ferror-limit" "19" "-fmessage-length" "177" "-fobjc-runtime=gcc" "-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option" "-fcolor-diagnostics" "-x" "c++" "/home/user/projects/embedded-linux/apps/hr-radar/6455/apps/./measure_cmd/client/measure_cmd_client.h" "-faddrsig"

clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/user/bin/cppnamelint/../lib/clang/8.0.0/include"
ignoring nonexistent directory "/include"
ignoring duplicate directory "/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0"
#include "..." search starts here:
#include <...> search starts here:
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/x86_64-linux-gnu/c++/7.5.0
/usr/lib/gcc/x86_64-linux-gnu/7.5.0/../../../../include/c++/7.5.0/backward
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
...

HTH

Assertion `!Init->isValueDependent()' failed. Aborted (core dumped)

OS : Ubuntu 18.04
Build : Debug

dougpuob@dougpuob-Virtual-Machine:~/working-folder/namelint.git/Build/linux/Output$ ./namelint check /home/dougpuob/working-folder/namelint.git/Source/Config.cpp --config=/home/dougpuob/working-folder/namelint.git/Source/Config.toml
--all  		: false
--config  	: "/home/dougpuob/working-folder/namelint.git/Source/Config.toml"
--help  	: false
--log  		: "namelint.log"
--unittest	: false
--version	: false
-a  		: false
-u  		: false
<file>  	: "/home/dougpuob/working-folder/namelint.git/Source/Config.cpp"
check  		: true
config  	: false
test  		: false
namelint: /home/dougpuob/working-folder/llvm.git/tools/clang/lib/AST/Decl.cpp:2342: bool clang::VarDecl::checkInitIsICE() const: Assertion `!Init->isValueDependent()' failed.
Aborted (core dumped)
dougpuob@dougpuob-Virtual-Machine:~/working-folder/namelint.git/Build/linux/Output$ 

image

[Bug] MFC macro function can't be detect correctly

  1. The MFC macro function can't be detected correctly IMPLEMENT_SERIAL.
    2 The following function and its parameter can't be treat correctly.

image

IMPLEMENT_SERIAL(ToolbarLabel, CBCGPToolbarButton, 1)

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

ToolbarLabel::ToolbarLabel(UINT uiId, LPCTSTR StrText)
{
    if (StrText != NULL)
    {
        m_strText = StrText;
    }

    m_bText  = TRUE;
    m_nID    = uiId;
    m_iImage = -1;
}

Fix for using the python file to run on entire directory and produce json out

Python file is using jsonfile when it should should use jsonout.

diff --git a/script/cppnamelint.py b/script/cppnamelint.py
index 6128c7d..fa16c2c 100755
--- a/script/cppnamelint.py
+++ b/script/cppnamelint.py
@@ -340,7 +340,7 @@ def run_util_checkdir_files(exec_file_path, py_args, paired_samples:[], print_ou

         args_list: [] = ['check', paired['src'], '-config='+paired['cfg']]
         if py_args.json:
-            args_list.append('-jsonfile=' + py_args.json)
+            args_list.append('-jsonout=' + py_args.json)

         if py_args.inc:
             for file in py_args.inc:

P.S. Would be nice to check if jq is installed and run it on the json output if it is.

Output for VisitCXXMethodDecl is wrong

OS : Windows
Build : Debug

C:\working-folder\namelint\cpp-namelint.git\Build\win32\Output\Release>namelint.exe check ..\..\..\..\Source\Config.cpp --config=..\..\..\..\Source\Config.toml
--all       : false
--config    : "..\..\..\..\Source\Config.toml"
--help      : false
--log       : "namelint.log"
--unittest  : false
--version   : false
-a          : false
-u          : false
<file>      : "..\..\..\..\Source\Config.cpp"
check       : true
config      : false
test        : false
Config.cpp <Line:11,Col:1>      VisitCXXMethodDecl:  Config()
Config.cpp <Line:29,Col:1>      VisitCXXMethodDecl:  GetData()
Config.cpp <Line:31,Col:1>      VisitCXXMethodDecl:  Load()
Config.cpp <Line:38,Col:5>      Variable:       pr (toml::ParseResult)
Config.cpp <Line:42,Col:9>      Variable:       value (toml::Value)
Config.cpp <Line:53,Col:22>     Variable:       value (toml::Value)
Config.cpp <Line:110,Col:22>    Variable:       value (toml::Value)
Config.cpp <Line:124,Col:22>    Variable:       value (toml::Value)
Config.cpp <Line:140,Col:22>    Variable:       iter (toml::Table::iterator)
Config.cpp <Line:143,Col:21>    Variable:       str1 (class std::basic_string<char,  std::char_traits<char>, class std::allocator<char> >)
Config.cpp <Line:144,Col:21>    Variable:       str2 (class std::basic_string<char,  std::char_traits<char>, class std::allocator<char> >)
Config.cpp <Line:154,Col:1>     VisitCXXMethodDecl:  Print()
Config.cpp <Line:175,Col:10>    Variable:       item (class std::basic_string<char,  std::char_traits<char>, class std::allocator<char> >)
Config.cpp <Line:179,Col:10>    Variable:       item (class std::basic_string<char,  std::char_traits<char>, class std::allocator<char> >)
Config.cpp <Line:188,Col:1>     VisitCXXMethodDecl:  Save()

C:\working-folder\namelint\cpp-namelint.git\Build\win32\Output\Release>

image

Seems like an invalid decl with class

cppnamelint utility v0.3.0
---------------------------------------------------
 File    = DlgFt2GetDevInfo.cpp
 Config  = cppnamelint.toml
 Checked =     6  [File:1 | Func:  2 | Param:  2 | Var:  1 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
 Error   =     3  [File:0 | Func:  0 | Param:  2 | Var:  1 | Enum:  0 | Struct:  0 | Union:  0 | Class:  0]
------------------------------------------------------------
  <  19,   19> Parameter : nDebugLevel (ULONG)
  <  19,   38> Parameter : pszFormat (wchar_t*)
  <  25,    1> Variable  : CWnd (DlgFt2GetDevInfo::DlgFt2GetDevInfo()

image

Failed to build on Ubuntu LInux (error: specialization of ‘std::is_error_code_enum<jsoncons::unicons::conv_errc>’ after instantiation)

error: specialization of ‘std::is_error_code_enumjsoncons::unicons::conv_errc’ after instantiation

Scanning dependencies of target cppnamelint
[ 35%] Building CXX object CMakeFiles/cppnamelint.dir/Source/Main.cpp.o
In file included from /home/dougpuob/working-folder/cpp-namelint.git/Module/jsoncons.git/include/jsoncons/json_exception.hpp:13,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Module/jsoncons.git/include/jsoncons/basic_json.hpp:26,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Module/jsoncons.git/include/jsoncons/json.hpp:10,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Source/Main.cpp:30:
/home/dougpuob/working-folder/cpp-namelint.git/Module/jsoncons.git/include/jsoncons/unicode_traits.hpp:1482:12: error: specialization of ‘std::is_error_code_enum<jsoncons::unicons::conv_errc>’ after instantiation
     struct is_error_code_enum<jsoncons::unicons::conv_errc> : public true_type
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/dougpuob/working-folder/cpp-namelint.git/Module/jsoncons.git/include/jsoncons/unicode_traits.hpp:1482:12: error: redefinition of ‘struct std::is_error_code_enum<jsoncons::unicons::conv_errc>’
In file included from /usr/include/c++/8/bits/ios_base.h:46,
                 from /usr/include/c++/8/ios:42,
                 from /usr/include/c++/8/ostream:38,
                 from /usr/include/c++/8/iostream:39,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Source/Config.h:4,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Source/TraceMemo.h:4,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Source/Common.h:4,
                 from /home/dougpuob/working-folder/cpp-namelint.git/Source/Main.cpp:1:

Unexpected findings

based on 96c8b87

  1. looks like that a constructor is not checked for the class name pattern, but the one of the function (here: lowerCamel), like so:
    File = 2.04.initializer.list.cpp
    Config = cppnamelint.toml
    Checked = 16 [File:0 | Func: 4 | Param: 4 | Var: 8 | Enum: 0 | Struct: 0 | Union: 0 | Class: 2]
    Error = 2 [File:0 | Func: 2 | Param: 0 | Var: 0 | Enum: 0 | Struct: 0 | Union: 0 | Class: 0]

< 18, 5> Function : Foo
< 24, 5> Function : MagicFoo

The same applies to structs:
File = 10.2.concepts.cpp
Config = cppnamelint.toml
Checked = 35 [File:0 | Func: 13 | Param: 7 | Var: 12 | Enum: 0 | Struct: 3 | Union: 0 | Class: 1]
Error = 26 [File:0 | Func: 7 | Param: 7 | Var: 10 | Enum: 0 | Struct: 2 | Union: 0 | Class: 0]

< 30, 5> Function : Person

  1. "Parameters" are reported without configuration that could be set, and disable reporting is also not possible (the TODO?)

  2. Add any namespace around the code in e.g. 10.2.concepts.cpp and the errors will melt down to a few only:

File = 10.2.concepts.cpp
Config = cppnamelint.toml
Checked = 13 [File:0 | Func: 3 | Param: 3 | Var: 4 | Enum: 0 | Struct: 3 | Union: 0 | Class: 0]
Error = 9 [File:0 | Func: 2 | Param: 3 | Var: 2 | Enum: 0 | Struct: 2 | Union: 0 | Class: 0]

< 40, 16> Parameter : a (double)
< 40, 26> Parameter : b (double)
< 41, 9> Function : to_string
< 50, 9> Function : to_string
< 50, 26> Parameter : l (list)
< 52, 13> Variable : s (string)
< 62, 5> Variable : to_string (string)

  1. I have some cases where cppnamelint stops after the first line of code. I cannot say when that happens / what the rule is,
    baut at least "VariableName = 2" (or 3) seems to be required with UpperCamel classe name (other combinations not tested).
    I could create a simple class like
    class BlaBla
    {
    int someVar;
    };
    then the class gets detected as a variable
    Checked = 1 [File:0 | Func: 0 | Param: 0 | Var: 1 | Enum: 0 | Struct: 0 | Union: 0 | Class: 0]
    Error = 1 [File:0 | Func: 0 | Param: 0 | Var: 1 | Enum: 0 | Struct: 0 | Union: 0 | Class: 0]

< 1, 1> Variable : BlaBla (class)
the log then ends with
[2021-04-20 12:49:39.948] [] [info] Program is going to close. (iRet=1)
the real variable someVar does not even get checked

Can you reproduce that issue?

All for now, thanks a lot for your efforts!

Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class

int
main(int iArgc, char** pszArgv)
{
    // ...
    std::map<std::string, docopt::value> Arguments =
      docopt::docopt(USAGE,
                     { pszArgv + 1, pszArgv + iArgc },
                     false, // show help if requested
                     "");   // version string

    // std::cout << "<file>   = " << Arguments["<file>"] << endl;       // Release build failed if this line was remarked.
    // std::cout << "--config = " << Arguments["--config"] << endl;

Passed with release build if std::cout << "<file> = " << Arguments["<file>"] << endl; is there

3>   Creating library C:/working-folder/opensrc/dougpuob/cpp-namelint/cpp-namelint.git/Build/win32/Output/Release/cppnamelint.lib and object C:/working-folder/opensrc/dougpuob/cpp-namelint/cpp-namelint.git/Build/win32/Output/Release/cppnamelint.exp
3>Main.obj : warning LNK4217: locally defined symbol ?docopt@0@YA?AV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uvalue@docopt@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uvalue@docopt@@@std@@@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@ABV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@2@_N02@Z (class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct docopt::value,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,struct docopt::value> > > __cdecl docopt::docopt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &,bool,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)) imported in function _main
3>cppnamelint.vcxproj -> C:\working-folder\opensrc\dougpuob\cpp-namelint\cpp-namelint.git\Build\win32\Output\Release\cppnamelint.exe
3>Done building project "cppnamelint.vcxproj".
7>------ Skipped Build: Project: INSTALL, Configuration: Release Win32 ------
7>Project not selected to build for this solution configuration 
8>------ Skipped Build: Project: PACKAGE, Configuration: Release Win32 ------
8>Project not selected to build for this solution configuration 
========== Build: 1 succeeded, 0 failed, 8 up-to-date, 7 skipped ==========

Failed with release build if std::cout << "<file> = " << Arguments["<file>"] << endl; was remarked

3>Main.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct docopt::value,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,struct docopt::value> > > __cdecl docopt::docopt(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > const &,bool,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,bool)" (__imp_?docopt@0@YA?AV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uvalue@docopt@@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@Uvalue@docopt@@@std@@@2@@std@@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@ABV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@2@_N02@Z) referenced in function _main
3>C:\working-folder\opensrc\dougpuob\cpp-namelint\cpp-namelint.git\Build\win32\Output\Release\cppnamelint.exe : fatal error LNK1120: 1 unresolved externals
3>Done building project "cppnamelint.vcxproj" -- FAILED.
7>------ Skipped Build: Project: INSTALL, Configuration: Release Win32 ------
7>Project not selected to build for this solution configuration 
8>------ Skipped Build: Project: PACKAGE, Configuration: Release Win32 ------
8>Project not selected to build for this solution configuration 
========== Build: 0 succeeded, 1 failed, 8 up-to-date, 7 skipped ==========

Random failed on macOS version on Azure DevOps.

Random failed on macOS version on Azure DevOps.

https://dev.azure.com/CppNameLint/cpp-namelint/_build/results?buildId=201&view=logs&j=a5e52b91-c83f-5429-4a68-c246fc63a4f7&t=4f7f0e14-4767-5646-3512-f2409f98e2bf

/Users/runner/runners/2.165.2/work/1/s/source/test/TestDetection.cpp:257: Failure
Expected equality of these values:
  true
  Detect.CheckFunction(RuleType, "lower_separated_funcname_" )
    Which is: false
[  FAILED  ] Config_Detect_CheckFunction.LowerSeperatedCase_Good (1 ms)

image

[Help] How to get error info from libtooling?

clang file.c -x c++ -Xclang -ast-dump -fsyntax-only

#define MAX_VALUE (10)  
int iVal1 =             
int iVal2 = MAX_VALUE;  

image

file.c:3:1: error: expected expression
int iVal2 = MAX_VALUE;
^
TranslationUnitDecl 0x21bb4965f08 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x21bb49667a0 <<invalid sloc>> <invalid sloc> implicit __int128_t '__int128'
| `-BuiltinType 0x21bb49664a0 '__int128'
|-TypedefDecl 0x21bb4966810 <<invalid sloc>> <invalid sloc> implicit __uint128_t 'unsigned __int128'
| `-BuiltinType 0x21bb49664c0 'unsigned __int128'
|-TypedefDecl 0x21bb4966b18 <<invalid sloc>> <invalid sloc> implicit __NSConstantString 'struct __NSConstantString_tag'
| `-RecordType 0x21bb49668f0 'struct __NSConstantString_tag'
|   `-Record 0x21bb4966868 '__NSConstantString_tag'
|-TypedefDecl 0x21bb4966b88 <<invalid sloc>> <invalid sloc> implicit size_t 'unsigned long long'
| `-BuiltinType 0x21bb49660e0 'unsigned long long'
|-TypedefDecl 0x21bb4966c20 <<invalid sloc>> <invalid sloc> implicit __builtin_ms_va_list 'char *'
| `-PointerType 0x21bb4966be0 'char *'
|   `-BuiltinType 0x21bb4965fa0 'char'
|-TypedefDecl 0x21bb4966c90 <<invalid sloc>> <invalid sloc> implicit __builtin_va_list 'char *'
| `-PointerType 0x21bb4966be0 'char *'
|   `-BuiltinType 0x21bb4965fa0 'char'
`-VarDecl 0x21bb4966d00 <file.c:2:1, col:5> col:5 iVal1 'int'
1 error generated.
PS D:\>           

Added several config options for debugging log

The are several config options in cppnamelint.toml file only, they all not be implemented in the source code.

[Debug.Log]
Main                     = true
DumpDecl                 = true
AstVisitor               = true
Detection                = true
Config                   = true

unknown file: error: SEH exception with code 0xc0000005 thrown in the test body

Failed to pass Unit Test.

image

[----------] 8 tests from Config_Detect_CheckFunction
[ RUN      ] Config_Detect_CheckFunction.InputParms_Good
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] Config_Detect_CheckFunction.InputParms_Good (1 ms)
[ RUN      ] Config_Detect_CheckFunction.InputParms_Bad
unknown file: error: SEH exception with code 0xc0000005 thrown in the test body.
[  FAILED  ] Config_Detect_CheckFunction.InputParms_Bad (1 ms)

variable in Struct

it can't check some variable if it has included struct.
exsample:

typedef struct _Test
{
int ABC; << can't check this type;
} Test;

Build description typo

for Linux it should be

Linux
$ cd cpp-namelint.git/script
$ build-bin-linux.sh
$ cd cpp-namelint.git/build/linux
$ make

Cannot be built on Linux

image

In file included from /usr/include/c++/8/backward/strstream:50,
                 from /home/dougpuob/working-folder/namelint.git/Source/Config.cpp:4:
/usr/include/c++/8/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionality instead. For a listing of replacement headers and interfaces, consult the file backward_warning.h. To disable this warning use -Wno-deprecated. [-Wcpp]
 #warning \
  ^~~~~~~
/home/dougpuob/working-folder/namelint.git/Source/Config.cpp: In member function ‘bool namelint::Config::LoadStream(std::__cxx11::string)’:
/home/dougpuob/working-folder/namelint.git/Source/Config.cpp:48:40: error: cannot bind non-const lvalue reference of type ‘std::istream&’ {aka ‘std::basic_istream<char>&’} to an rvalue of type ‘std::basic_istream<char>’
     toml::ParseResult pr = toml::parse(istringstream(ConfigContent));
                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/dougpuob/working-folder/namelint.git/Source/Config.cpp:9:
/home/dougpuob/working-folder/namelint.git/Source/../Module/tinytoml.git/include/toml/toml.h:378:20: note:   initializing argument 1 of ‘toml::ParseResult toml::parse(std::istream&)’
 inline ParseResult parse(std::istream& is)
                    ^~~~~
CMakeFiles/namelint.dir/build.make:134: recipe for target 'CMakeFiles/namelint.dir/Source/Config.cpp.o' failed
make[2]: *** [CMakeFiles/namelint.dir/Source/Config.cpp.o] Error 1
CMakeFiles/Makefile2:69: recipe for target 'CMakeFiles/namelint.dir/all' failed
make[1]: *** [CMakeFiles/namelint.dir/all] Error 2
Makefile:151: recipe for target 'all' failed
make: *** [all] Error 2
dougpuob@dougpuob-Virtual-Machine:~/working-folder/namelint.git/Build/linux$ 

[Bug] Failed to detect source code with declaring multiple variables

---------------------------------------------------
 File    = D:\working-folder\xxx\buspdo.c
 Config  = D:\working-folder\xxx\CppNameLint\cppnamelint.toml
 Inc[ 1] = -ID:\working-folder\xxx\CppNameLint
 Checked =  1095  [Func:224 | Param:332 | Var:539]
 Error   =   743  [Func: 48 | Param:695 | Var:  0]
---------------------------------------------------
<347, 5> Variable :    nNext (int nCur,)
int nCur, nNext = QS_ERROR;  // Line: 272

Failed to detect variable in structu

cppnamelint utility v0.3.0
---------------------------------------------------
 File    = Global.h
 Config  = cppnamelint.toml
 Checked =    92  [File:1 | Func:  9 | Param:  5 | Var:  2 | Enum: 11 | Struct: 64 | Union:  0 | Class:  0]
 Error   =    63  [File:0 | Func:  2 | Param:  0 | Var:  0 | Enum: 11 | Struct: 50 | Union:  0 | Class:  0]
------------------------------------------------------------
  <  13,    9> Enum Tag  : _SCANF_STYLE
  <  15,    5> Enum Val  : DEC (_SCANF_STYLE)
  <  16,    5> Enum Val  : HEX (_SCANF_STYLE)
  <  19,    9> Enum Tag  : _READER_INDEX
  <  21,    5> Enum Val  : CF_INDEX (_READER_INDEX)
  <  22,    5> Enum Val  : XD_INDEX (_READER_INDEX)
  <  23,    5> Enum Val  : SD1_INDEX (_READER_INDEX)
  <  24,    5> Enum Val  : SD2_INDEX (_READER_INDEX)
  <  25,    5> Enum Val  : MS1_INDEX (_READER_INDEX)
  <  26,    5> Enum Val  : MS2_INDEX (_READER_INDEX)
  <  27,    5> Enum Val  : GPIO_INDEX (_READER_INDEX)
  <  37,    9> Struct Tag: _CONST_DEF ()
  <  43,    9> Struct Tag: _EXEC_OPTION ()
  <  51,    9> Struct Tag: _THREAD_CONTEXT ()
  <  60,    5> Function  : dwThread
  <  61,    5> Function  : dwThreadIdx

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.