Install oclint

  1. Download resources
  2. Configuring environment Variables
  3. validation

For details about the installation, see the official documentation. 4

source ~/.zshrc cd ${SRCROOT} xcodebuild clean xcodebuild -workspace testPrivatePod.xcworkspace -scheme testPrivatePod |  xcpretty -r json-compilation-database oclint-json-compilation-database -- -report-type xcodeCopy the code

Error compiling using CMD +b

Error: compile_commands.json not found at xxxx
Copy the code

The script to modify

xcodebuild -workspace testPrivatePod.xcworkspace -scheme testPrivatePod | xcpretty -r json-compilation-database
Copy the code

Continue to report errors

accessing build database "/Users/xxx/Library/Developer/Xcode/DerivedData/testPrivatePod-dkrzybvaowacztfjutpjkzqosbrf/Build/Intermediates.noindex/ XCBuildData/build.db": database is locked Possibly there are two concurrent builds running in the same filesystem location.Copy the code

Add the condition

-UseModernBuildSystem=NO
Copy the code

If removed, the error is still reported

Continue to report errors

Could not delete `/build` because it was not created by the build system
Copy the code

The build folder is generated under the project directory, which can be removed manually

Recompilation still reports an error

Error: compile_commands.json not found at xxxx
Copy the code

Manually create such a file in the root directory, or configure it as follows to output a file

xcodebuild -workspace testPrivatePod.xcworkspace -scheme testPrivatePod -UseModernBuildSystem=NO | xcpretty -r json-compilation-database  --output compile_commands.json
Copy the code

cmd+b

Is still an error

LLVM ERROR: CommonOptionsParser: failed to parse command-line arguments. [CommonOptionsParser]: oclint: Not enough positional command line arguments specified! Must specify at least 1 positional argument: See: /Users/ XXX /oclint-21.03/bin/oclint --helpCopy the code

It seems that there is a problem with the parameter, it is said that at least one parameter is needed, but the code is copied from the official website, what is wrong?

Comment the following line and compile without error

oclint-json-compilation-database -exclude Pods -- -report-type xcode
Copy the code

So there must be a problem with this line of command

Replace them with commands that someone else says work

unset LLVM_TARGET_TRIPLE_SUFFIX

# Rules
LINT_LONG_LINE=300
LINT_LONG_VARIABLE_NAME=64
LINT_LONG_METHOD=150

LINT_RULES="-rc LONG_LINE=${LINT_LONG_LINE} \
    -rc LONG_VARIABLE_NAME=${LINT_LONG_VARIABLE_NAME} \
    -rc LONG_METHOD=${LINT_LONG_METHOD}"

# Threshold.
LINT_PRIORITY_1_THRESHOLD=0
LINT_PRIORITY_2_THRESHOLD=20
LINT_PRIORITY_3_THRESHOLD=30
LINT_THRESHOLD = "-max-priority-1=${LINT_PRIORITY_1_THRESHOLD} \
    -max-priority-2=${LINT_PRIORITY_2_THRESHOLD} \
    -max-priority-3=${LINT_PRIORITY_3_THRESHOLD}"

# Excludes
# you can use grep-like regular expressions syntax,
LINT_EXCLUDES="Pods|lib"

oclint-json-compilation-database \
    -exclude ${LINT_EXCLUDES} \
    -- \
    -report-type xcode \
    ${LINT_RULES} \
    ${LINT_THRESHOLD} \
Copy the code

Try the solution: Clear the cache before oclint execution

. rm -rf ~/Library/Developer/Xcode/DerivedData/ oclint-json-compilation-database \ -exclude ${LINT_EXCLUDES} \ -- \ -report-type xcode \ ${LINT_RULES} \ ${LINT_THRESHOLD} \Copy the code

It’s no use. There are more mistakes

Try the solution: Export analysis logs to HTML

oclint-json-compilation-database -e Pods -- --verbose -rc CYCLOMATIC_COMPLEXITY=10 -rc LONG_CLASS=1000 -report-type html  -o oclint.htmlCopy the code

Parameter problems are still reported

Annotate Oclint’s command and report the following error for no apparent reason

invalid byte sequence in US-ASCII 
Copy the code

Solution, set the language before executing the script

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
Copy the code

worked

Error opening oclint command

/ Users/XXXX/Desktop/other/myDemo/tododemoios/oclint: 1-1: compilation the contains multiple jobs:Copy the code

The solution sets all COMPILER_INDEX_STORE_ENABLE properties in buildSetting to NO and the podfile is updated as follows

post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config|  config.build_settings['COMPILER_INDEX_STORE_ENABLE'] = "NO" end end endCopy the code

Pod install, recompile, error

oclint: error: violations exceed threshold
Copy the code

Too many errors exceed the threshold modify command as follows

oclint-json-compilation-database -e Pods -- -report-type xcode -max-priority-1=9999 -max-priority-2=9999 -max-priority-3=9999
Copy the code

You’re done

Xcode is currently reporting a warning

Try exporting to HTML and opening it

oclint-json-compilation-database -e Pods -- -report-type html -o oclint.html -max-priority-1=9999 -max-priority-2=9999 -max-priority-3=9999

open oclint.html
Copy the code

successful