Giter VIP home page Giter VIP logo

danger-periphery's Introduction

danger-periphery

Test Maintainability Test Coverage Gem Version

A Danger plugin to detect unused codes.

image

Installation

You need to install Periphery beforehand.

Write the following code in your Gemfile.

gem "danger-periphery"

Usage

If you already have .periphery.yml, the easiest way to use is just add this to your Dangerfile.

periphery.scan

You can specify the path to executable in this way.

periphery.binary_path = "bin/periphery"

You can pass command line options to periphery.scan like the following. See periphery scan -h for available options.

periphery.scan(
  project: "Foo.xcodeproj",
  schemes: ["foo", "bar"],
  targets: "foo",
  clean_build: true
)

By default, danger-periphery scans all files in the specified targets and reports problems only in added, modified and renamed files. You can make danger-periphery report problems in all files by setting scan_all_files to true.

periphery.scan_all_files = true
periphery.scan

You can force danger-periphery treat all warnings as errors by changing warning_as_error flag.

periphery.warning_as_error = true
periphery.scan

Advanced Usage

Skip building for faster analysis

Let's say that your project already have workflow to run test like the following GitHub Actions workflow.

# .github/workflows/test.yml

steps:
  - name: Run Danger
    run: bundle exec danger
  - name: Run test
    run: xcodebuild test -project Foo.xcodeproj -scheme foo -sdk iphonesimulator -arch arm64

In this case, Periphery can reuse the index store generated by the previous build.

To enable this feature, you need to give index_store_path to the generated index store, and set skip_build to true.

# Dangerfile

periphery.scan(
  project: "Foo.xcodeproj",
  schemes: "foo",
  targets: "foo",
  skip_build: true,
  index_store_path: 'DerivedData/Index.noindex/DataStore' # 'DerivedData/Index/DataStore' in Xcode 13 or earlier.
)

Then do not forget to pass -derivedDataPath option to xcodebuild, and reorder steps.

# .github/workflows/test.yml

steps:
  - name: Run test
    run: xcodebuild test -project Foo.xcodeproj -scheme foo -sdk iphonesimulator -arch arm64 -derivedDataPath DerivedData
  - name: Run Danger
    run: bundle exec danger

Postprocess warnings by passing block to #scan

You can modify warnings as you like by passing a block to scan. scan takes a block that receives ScanResult instance as arguments. Each ScanResult instance corresponds with each entry of Danger warnings. If that block returns falsy value, danger-periphery suppresses the corresponding warning.

For example, if you want your team members to be careful with warnings, the following code may work.

periphery.scan do |violation|
  violation.message = "Pay attention please! #{violation.message}"
end

For another example, if you want to suppress warnings complaining about unused parameter of many of didChangeValue(_ sender: Any) methods, you can suppress this kind of warnings in the following way.

periphery.scan do |violation|
  !violation.message.match(/Parameter 'sender' is unused/)
end

Install Periphery in Dangerfile

Although I recommend you to install Periphery binary on your own, danger-periphery provides a method to install Periphery in Dangerfile.

periphery.install
periphery.scan

Note that periphery.install also changes periphery.binary_path so that you don't need to specify the installed file path.

If you want to install the specific version of Periphery to the specific path with overwriting an existing file, add options like this.

periphery.install version: '2.10.0', path: 'bin/periphery', force: true

Development

  1. Clone this repo
  2. Run bundle install to setup dependencies.
  3. Run bundle exec rake periphery:install to install Periphery.
  4. Run bundle exec rake spec to run the tests.
  5. Use bundle exec guard to automatically have tests run as you make changes.
  6. Make your changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.