Pour le développement iOS, nous avons utilisé un tel outil d'analyse statique dans notre développement quotidien, c'est-à-dire qu'il s'agit d'un outil de compilation frontal qui prend en charge , et . Clang
en bitcode Clang
LLVM C
, C++
et enfin compilé en code machine par LLVM. Cet outil prend en charge notre développement et notre débogage quotidiens.Objective-C
Swift
OC
Swift
OCLint
C'est un Clang
outil construit sur , qui peut trouver des problèmes potentiels dans le code. Pour les fonctions spécifiques, veuillez vous référer à la documentation officielle Ici, nous introduisons principalement son installation et son utilisation.
Installer le logiciel
OClint
brew tap oclint/formulae
brew install oclint
test
Saisissez le répertoire du projet (par SuperLogger
exemple),
Basculez vers l'emplacement problématique () du projet téléchargé, et changez dans SuperLoggerDemo
le répertoire :
git clone https://github.com/yourtion/SuperLogger.git
cd SuperLogger
git checkout 0e64637459996ed91e0dd15718efb5d7200a9971
cd SuperLoggerDemo
Exécution des tests :
# Cleanup before building
rm -f compile_commands.json
xctool -project SuperLoggerDemo.xcodeproj -scheme SuperLoggerDemo clean
# Build Project
xctool build \
-project SuperLoggerDemo.xcodeproj -scheme SuperLoggerDemo \
-reporter json-compilation-database:compile_commands.json
# Analyze Project
oclint-json-compilation-database -e Pods -- \
-max-priority-1=100000 \
-max-priority-2=100000 -max-priority-3=100000 \
-disable-rule=InvertedLogic \
-disable-rule=CollapsibleIfStatements \
-disable-rule=UnusedMethodParameter \
-disable-rule=LongLine \
-disable-rule=LongVariableName \
-disable-rule=ShortVariableName \
-disable-rule=UselessParentheses \
-disable-rule=IvarAssignmentOutsideAccessorsOrInit | sed 's/\(.*\.\m\{
1,2\}:[0-9]*:[0-9]*:\)/\1 warning:/'
# Final cleanup
rm -f compile_commands.json
sortir
OCLint Report
Summary: TotalFiles=14 FilesWithViolations=4 P1=0 P2=2 P3=6
SuperLoggerPreviewView.m:77:37: warning: replace with container literal [migration|P3]
SuperLogerListView.m:206:37: warning: empty catch statement [empty|P2]
SuperLogerListView.m:25:15: warning: empty if statement [empty|P2]
SuperLogerListView.m:119:1: warning: long method [size|P3] Method with 92 lines exceeds limit of 50
SuperLogerListView.m:171:41: warning: replace with container literal [migration|P3]
SuperLogerListView.m:110:21: warning: replace with object subscripting [migration|P3]
SuperLogger.m:60:30: warning: replace with object subscripting [migration|P3]
SuperLogger.m:108:31: warning: replace with object subscripting [migration|P3]
[OCLint (http://oclint.org) v0.10.2]
Pour des questions spécifiques, veuillez vous référer à : http://docs.oclint.org/en/stable/rules/index.html
après réparation
OCLint Report
Summary: TotalFiles=14 FilesWithViolations=0 P1=0 P2=0 P3=0
[OCLint (http://oclint.org) v0.10.2]
La fonction générale est la suivante. Si vous avez des questions pendant le processus d'utilisation, veuillez communiquer avec nous.
Lien d'origine : https://blog.yourtion.com/static-code-analysis-ios-using-oclint.html