wrmswindmill opened a new pull request #2731: Add Lint in TravisCI and Update iOS TravisCI URL: https://github.com/apache/incubator-weex/pull/2731 # Brief Description of the PR Add Static Check in Travis CI ## Lint Tool Lists: 1. [oclint](http://oclint.org) : for c,c++,objective-c 2. [android lint]():for android project ## Check FileType ```javascript const getFileType = file => { if (file.match(/.+\.(m|h|mm|cpp|cc)/)) { return type_c; } else if (file.match(/.+\.java/)) { return type_android; }else{ return type_unknown; } } ``` ## OCLint in .travis.yml ```yaml - env: STATIC_CODE_ANALYSIS=true CHECK_C=true language: objective-c osx_image: xcode7.2 before_install: - | # install oclint if [[ ("${STATIC_CODE_ANALYSIS}" = "true") && ("${CHECK_C}" = "true") ]]; then brew cask uninstall oclint brew tap oclint/formulae brew install oclint fi install: elif [[ ("$TEST_SUITE" = "jsfm") || ("$TEST_SUITE" = "danger") || ("${CHECK_C}" = "true") ]]; then npm install ;; script: if [[ ("${STATIC_CODE_ANALYSIS}" = "true") && ("${CHECK_C}" = "true") ]]; then hasCFile=$(npm run danger -- run --dangerfile ./dangerfile-static-check.js) echo "The value of hasCFile is ${hasCFile}" if [[ "$hasCFile" =~ "hasCFile" ]]; then echo "hasCFile" cd ios/sdk && xcodebuild | xcpretty -r json-compilation-database -o compile_commands.json oclint-json-compilation-database oclint_args -- \ -disable-rule=ShortVariableName \ -disable-rule=LongLine \ -disable-rule=LongMethod \ -disable-rule=HighNcssMethod \ -disable-rule=LongVariableName \ -disable-rule=HighCyclomaticComplexity \ -disable-rule=HighNPathComplexity \ -disable-rule=UnusedLocalVariable \ -disable-rule=DoubleNegative \ -disable-rule=MultipleUnaryOperator \ -disable-rule=DeepNestedBlock \ -max-priority-1=15000 \ -max-priority-2=15000 \ -max-priority-3=15000 fi fi ``` ## Android Lint in .travis.yml ```yaml - env: STATIC_CODE_ANALYSIS=true CHECK_ANDROID=true language: android dist: trusty jdk: oraclejdk8 android: components: - android-26 - extra-android-m2repository install: if [[ ("$TEST_SUITE" = "android") || ("${CHECK_ANDROID}" = "true") ]]; then curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash nvm install 7.6 npm install echo y | sdkmanager "cmake;3.6.4111459" if find "${HOME}/android-ndk-r18b" -mindepth 1 | read; then echo "NDK cache hit" else echo "NDK cache missed" rmdir "${HOME}/android-ndk-r18b" fi if [[ ! -d "${HOME}/android-ndk-r18b" ]]; then wget https://dl.google.com/android/repository/android-ndk-r18b-linux-x86_64.zip unzip android-ndk-r18b-linux-x86_64.zip -d $HOME fi export ANDROID_NDK_HOME=$HOME/android-ndk-r18b export PATH=$PATH:$ANDROID_NDK_HOME echo "ndk.dir=$ANDROID_NDK_HOME" > android/local.properties script: if [[ ("${STATIC_CODE_ANALYSIS}" = "true") && ("${CHECK_ANDROID}" = "true") ]]; then hasAndroidFile=$(npm run danger -- run --dangerfile ./dangerfile-static-check.js) echo "The value of hasAndroidFile is ${hasAndroidFile}" if [[ "$hasAndroidFile" =~ "hasAndroidFile" ]]; then echo "hasAndroidFile" cd android ./gradlew lint fi fi ``` ## Code Format code format with [danger-code_style_validation](https://github.com/flix-tech/danger-code_style_validation) based on clang-format clang-format support code format for program language like:java, c++, c, objective. 1. create a new file named Dangerfile and add a new line: ``` code_style_validation.check file_extensions: ['.cc', '.cpp', '.m', 'mm', '.h', '.java'] ``` 2. add a new line in Gemfile ``` gem 'danger-code_style_validation', :git => 'https://github.com/wrmswindmill/danger-code_style_validation.git' ``` 3. update Travis.yml ``` matrix: fast_finish: true include: # format code using clang-format - env: FORMAT_CODE=true language: ruby install: elif [[ ("${FORMAT_CODE}" = "true" )]]; then bundle install fi script: if [[ ("${FORMAT_CODE}" = "true" )]]; then echo "exec danger ruby" bundle exec danger fi ``` ## Update iOS ```yaml install: elif [[ ("$TEST_SUITE" = "ios") ]]; then git submodule update --init --remote cd weex-playground/ios && bash update_podfile_for_travisci.sh cd ../../ && npm install cd weex-playground/ios && pod install --repo-update cd ../../ fi script: "ios" ) hasIosFile=$(npm run danger -- run --dangerfile ./dangerfile-ios.js) echo "The value of hasIosFile is ${hasIosFile}" if [[ "$hasIosFile" =~ "hasIosFile" ]]; then # build WeexSDK and run WeexSDKTests xcodebuild -project ios/sdk/WeexSDK.xcodeproj test -scheme WeexSDKTests CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -destination "platform=iOS Simulator,name=iPhone 6" | grep -A 5 error: # build WeexDemo and run WeexDemo test cd weex-playground/ios && mkdir tmp && mv * tmp;cd tmp xcodebuild -workspace WeexDemo.xcworkspace test -scheme WeexDemo CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO -destination "platform=iOS Simulator,name=iPhone 6" | grep -A 5 error: fi ;; ``` ## Todo - [x] Discuss OCLint Rules - [x] Discuss Android Rules ## Links 1. OCLint Rules:http://docs.oclint.org/en/stable/rules/index.html
---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
