Warning, /sdk/clazy/HOWTO is written in an unsupported language. File is not indexed.

0001 TODO: Use .md
0002 
0003 Help on how to create a new check or a fixit
0004 
0005 --------------------------------------------------------------------------------
0006 Files to create or modify:
0007 
0008 checks/levelX/my-check.cpp
0009 checks/levelX/my-check.h
0010 checks/README-my-check.md
0011 tests/my-check/config.json
0012 tests/my-check/main.cpp
0013 ClazySources.cmake
0014 checks.json
0015 ChangeLog
0016 README.md
0017 
0018 Just add your check to checks.json and run dev-scripts/generate.py --generate
0019 which will generate the files you need to write, and edit others for you.
0020 
0021 --------------------------------------------------------------------------------
0022 Tips
0023 
0024 - Write the unit-test before the check
0025 
0026 - Dump the abstract syntax tree (AST) of your unit-test:
0027 
0028   ./run_tests.py my-test --dump-ast
0029 
0030   This creates a main.cpp.ast file, if you include Qt headers, the AST will be
0031   very big, your stuff will be at the end of the file. Use the AST to check which
0032   nodes you have to visit.
0033 
0034 - You can also dump the AST of a statement in C++:
0035   stmt->dump()
0036 
0037   This dumps the sub-AST to stdout, having stmt as it's root
0038 
0039 - llvm::errs() is useful to print to stderr
0040   llvm::errs() << record->getNameAsString() << "\n";
0041   llvm::errs() << stmt->getLocStart().printToString(m_ci.getSourceManager()) << "\n";
0042 
0043 - Look in Utils.h, StringUtils.h, QtUtils.h, FixitUtils.h, etc for helper functions you might need.
0044 
0045 --------------------------------------------------------------------------------
0046 Using ASTMatchers
0047 
0048 - See the qcolor-from-literal check for how to use ASTMatchers with clazy
0049 --------------------------------------------------------------------------------
0050 Tips for fixits
0051 
0052 - Usually you'll have to poke around and debug print getLocStart and getLocEnd of statements until
0053   you find the locations you want, otherwise you'll have to manipulate the locations with Lexer,
0054   see FixItUtils.cpp.
0055 
0056 - Learn from existing fixits:
0057     qgetenv.cpp
0058     functionargsbyref.cpp
0059     autounexpectedqstringbuilder.cpp
0060     qstringref.cpp
0061     qt4-qstring-from-array.cpp
0062 
0063 --------------------------------------------------------------------------------
0064 Running tests
0065     ./run_tests.py # This runs all tests
0066     ./run_tests.py my-check # This runs one tests
0067     ./run_tests.py my-check --verbose # Prints the compiler invocation command
0068     ./run_tests.py my-check --dump-ast # dumps the AST into a file with .ast extension