A Danger plugin to detect unused codes.
You need to install Periphery beforehand.
Write the following code in your Gemfile.
gem "danger-periphery"
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.
Note that build_args
option is a special option that does not exist in Periphery but the arguments are passed down to periphery
after an argument terminator (--
).
periphery.scan(
project: "Foo.xcodeproj",
schemes: ["foo", "bar"],
targets: "foo",
clean_build: true,
build_args: "-sdk iphonesimulator"
)
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
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
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
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
- Clone this repo
- Run
bundle install
to setup dependencies. - Run
bundle exec rake periphery:install
to install Periphery. - Run
bundle exec rake spec
to run the tests. - Use
bundle exec guard
to automatically have tests run as you make changes. - Make your changes.