danger-periphery
A Danger plugin to detect unused codes.
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
)
Advanced Usage
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. = "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..match(/Parameter 'sender' is unused/)
end
Postprocess warnings by calling #process_warnings
You can modify warnings as you like by passing a block to process_warnings.
process_warnings takes a block that receives [path, line, column, message] as arguments and returns one of the following types.
Arraythat exactly contains[path, line, column, message]truefalsenil
If an Array is returned, danger-periphery uses the values in an array instead of the raw result produced by Periphery.
true has the same meaning as [path, line, column, message], the argument array as-is.
If it returns false or nil, the processing warning will be suppressed.
For example, if you want your team members to be careful with warnings, the following code may work.
periphery.process_warnings do |path, line, column, |
[path, line, column, "Pay attention please! #{message}"]
end
Or if you want to suppress all unused warnings, to return nil or false in the block works.
periphery.process_warnings do |path, line, column, |
!.match(/unused/i)
end
Development
- Clone this repo
- Run
bundle installto setup dependencies. - Run
bin/download_peripheryto install Periphery. - Run
bundle exec rake specto run the tests. - Use
bundle exec guardto automatically have tests run as you make changes. - Make your changes.