Skip to content

Instantly share code, notes, and snippets.

@guilhermearaujo
Last active July 27, 2022 09:36
Show Gist options
  • Select an option

  • Save guilhermearaujo/a6e4dbb982fea40a0513 to your computer and use it in GitHub Desktop.

Select an option

Save guilhermearaujo/a6e4dbb982fea40a0513 to your computer and use it in GitHub Desktop.

Revisions

  1. guilhermearaujo revised this gist Apr 11, 2015. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions oclint.sh
    Original file line number Diff line number Diff line change
    @@ -1,17 +1,17 @@
    source ~/.bash_profile
    export PATH=$PATH:/usr/local/bin/

    if [ -z ${SCHEME+x} ]
    if [ -z "${SCHEME+x}" ]
    then
    export SCHEME=${PROJECT_NAME}
    export SCHEME="${PROJECT_NAME}"
    fi

    if [ -z ${WORKSPACE+x} ]
    if [ -z "${WORKSPACE+x}" ]
    then
    export WORKSPACE=${PROJECT_NAME}.xcworkspace
    export WORKSPACE="${PROJECT_NAME}.xcworkspace"
    fi

    cd ${SOURCE_ROOT}
    cd "${SOURCE_ROOT}"

    # Check if xctool and oclint are installed
    if ! which -s xctool
    @@ -28,11 +28,11 @@ fi

    # Cleanup before building
    rm -f compile_commands.json
    xctool -workspace ${WORKSPACE} -scheme ${SCHEME} clean > /dev/null
    xctool -workspace "${WORKSPACE}" -scheme "${SCHEME}" clean > /dev/null

    # Build and analyze
    # OCLint Rule Index: http://docs.oclint.org/en/dev/rules/index.html
    xctool -workspace ${WORKSPACE} -scheme ${SCHEME} -reporter json-compilation-database:compile_commands.json build
    xctool -workspace "${WORKSPACE}" -scheme "${SCHEME}" -reporter json-compilation-database:compile_commands.json build
    oclint-json-compilation-database -e Pods -- -max-priority-1=100000 -max-priority-2=100000 -max-priority-3=100000 \
    -disable-rule=InvertedLogic \
    -disable-rule=UnusedMethodParameter \
  2. guilhermearaujo created this gist Mar 12, 2015.
    16 changes: 16 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    # OCLint integration with Xcode

    ## 1. Integration
    * Add a new ***Target*** of kind ***Aggregate***, name it ***OCLint***
    * Under *Builde Phases*, add a new ***Run Script Phase***
    * Paste the script

    ## 2. Usage
    * Select target ***OCLint***
    * Build the target (press <kbd>⌘</kbd>+<kbd>B</kbd>)
    * Wait for the script to run
    * Warnings will appear in the *Issue Navigator* (press <kbd>⌘</kbd>+<kbd>4</kbd>)

    ## 3. Customization
    * Rules can be ignored by adding the parameter `-disable-rule=<RuleName>` to the `oclint-json-compilation-database` command
    * A comprehensive list of rules can be found at [OCLint documentation](http://docs.oclint.org/en/dev/rules/index.html)
    46 changes: 46 additions & 0 deletions oclint.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    source ~/.bash_profile
    export PATH=$PATH:/usr/local/bin/

    if [ -z ${SCHEME+x} ]
    then
    export SCHEME=${PROJECT_NAME}
    fi

    if [ -z ${WORKSPACE+x} ]
    then
    export WORKSPACE=${PROJECT_NAME}.xcworkspace
    fi

    cd ${SOURCE_ROOT}

    # Check if xctool and oclint are installed
    if ! which -s xctool
    then
    echo 'error: xctool not found, install e.g. with homebrew'
    exit 1
    fi

    if ! which -s oclint-json-compilation-database
    then
    echo 'error: OCLint not installed, install e.g. with homebrew cask'
    exit 2
    fi

    # Cleanup before building
    rm -f compile_commands.json
    xctool -workspace ${WORKSPACE} -scheme ${SCHEME} clean > /dev/null

    # Build and analyze
    # OCLint Rule Index: http://docs.oclint.org/en/dev/rules/index.html
    xctool -workspace ${WORKSPACE} -scheme ${SCHEME} -reporter json-compilation-database:compile_commands.json build
    oclint-json-compilation-database -e Pods -- -max-priority-1=100000 -max-priority-2=100000 -max-priority-3=100000 \
    -disable-rule=InvertedLogic \
    -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