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.

danger-periphery's People

Contributors

github-actions[bot] avatar manicmaniac avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

danger-periphery's Issues

Possibility to set error instead of warning

First of all, awesome plugin, one of the most important one, should be a builtin in a danger iOS setup, thank you for that.

I didnt see any option (hidden ?) to set danger as error instead warning in PR message. It would be nice something such as:

periphery.warning_as_error = true (default = false)
WDYT ?

Deprecate Danger::DangerPeriphery#process_warnings and #postprocessor= in favor of #scan with block

danger-periphery supports 3 similar functionality to modify PR comment.

1. Danger::DangerPeriphery#process_warnings

# deprecated
periphery.process_warnings do |path, line, column, message|
  !message.include?('unused')
end

2. Danger::DangerPeriphery#postprocessor=

# deprecated
periphery.postprocessor = proc do |path, line, column, message|
  !message.include?('unused')
end

3. Danger::DangerPeriphery#scan

# recommended
periphery.scan do |violation|
  !violation.message.include?('unused')
end

These 3 ways do the same thing - suppress warnings that contains the word unused - but actually the first and the second ones have the minor problem. That is, imagine you need to run periphery.scan more than once, those cannot replace the logic per each execution but only the third syntax can achieve the goal.

Maintaining those 3 methods is not so hard currently but in future, it could become a burden to keep the code clean.

So danger-periphery deprecates the first and second syntaxes in favor of the third one.
Note that those syntaxes are exclusive each other. Once you use the third syntax in your Dangerfile, the blocks given to first and second ones are ignored.

Warn of unused code not in diff

Hello,

Thanks for making this plugin! It’s pretty great. One feature request:

A lot of times code that was previously used can become unused later, such as after a large refactor. This code might not be part of the git diff. Periphery can identify this type of unused code, but this plugin explicitly filters those results out:

Screenshot 2024-02-12 at 3 26 34 PM

Would it be possible to have an option for not filtering out code that’s not in the diff, and instead logging all Periphery warnings?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

This repository currently has no open or pending branches.

Detected dependencies

bundler
Gemfile
  • bundler '~> 2.0'
  • danger '~> 9.0'
  • danger-danger_plugin_lint '~> 0.2'
  • danger-rubocop '~> 0.12'
  • guard '~> 2.18'
  • guard-rspec '~> 4.7'
  • guard-rubocop '~> 1.5'
  • listen '~> 3.9'
  • pry '~> 0.14'
  • rake '~> 13.1'
  • rspec '~> 3.13'
  • rubocop '~> 1.60'
  • rubocop-rake '~> 0.6'
  • rubocop-rspec '~> 2.26'
  • simplecov '~> 0.22'
  • yard '~> 0.9'
github-actions
.github/workflows/lint.yml
  • actions/checkout v4
  • ruby/setup-ruby v1
.github/workflows/test.yml
  • actions/checkout v4
  • ruby/setup-ruby v1
  • actions/upload-artifact v4
  • actions/download-artifact v4
  • ubuntu 22.04
regex
Rakefile
  • peripheryapp/periphery 2.18.0

  • Check this box to trigger a request for Renovate to run again on this repository

Pass down error log

When the scan step fails due to an error, The error logs of periphery should spill through in the danger log so it's easy to review. Currently it just returns the exit code and the log exits out

[2022-11-29T04:29:20.581Z] [20:29:20]: --- Step: danger ---

[2022-11-29T04:29:20.581Z] [20:29:20]: --------------------

[2022-11-29T04:29:20.581Z] [20:29:20]: $ bundle exec danger --danger_id=periphery_result --dangerfile=PeripheryDangerfile

[2022-11-29T04:30:20.640Z] [20:30:20]: ▸ bundler: failed to load command: danger (/Users/test/vendor/bundle/ruby/2.7.0/bin/danger)

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ /Users/test/vendor/bundle/ruby/2.7.0/gems/danger-periphery-0.2.2/lib/periphery/runner.rb:16:in `scan': \e[31m (Danger::DSLError)

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ [!] Invalid `PeripheryDangerfile` file: error: ["/Users/test/.swift_tools/tools/periphery/2.10.0/periphery", "scan", "--config", ".periphery.yml", "--skip-build", "--index-store-path", "output/derived_data/Index.noindex/DataStore", "--verbose", "--disable-update-check", "--quiet", "--format", "checkstyle"] exited with status code 1. error: Shell command '/usr/bin/env xcodebuild -project /Users/test/Some.xcodeproj -list -json' returned exit status '74':

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ . Updating the Danger gem might fix the issue. Your Danger version: 9.0.0, latest Danger version: 9.1.0

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ \e[0m

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ #  from PeripheryDangerfile:5

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ #  -------------------------------------------

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ #

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ >  periphery.scan(

[2022-11-29T04:30:20.751Z] [20:30:20]: ▸ #      config: ".periphery.yml",

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.