Class: Danger::DangerPeriphery
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerPeriphery
- Defined in:
- lib/danger/danger_periphery.rb
Overview
Analyze Swift files and detect unused codes in your project. This is done using Periphery.
Constant Summary collapse
- OPTION_OVERRIDES =
{ disable_update_check: true, quiet: true }.freeze
Instance Attribute Summary collapse
-
#binary_path ⇒ String
Path to Periphery executable.
-
#format ⇒ Symbol
writeonly
For internal use only.
-
#scan_all_files ⇒ Boolean
A flag to force Periphery report problems about all files.
-
#warning_as_error ⇒ Boolean
A flag to treat warnings as errors.
Instance Method Summary collapse
-
#initialize(dangerfile) ⇒ DangerPeriphery
constructor
A new instance of DangerPeriphery.
-
#install(version: :latest, path: 'periphery', force: false) ⇒ void
Download and install Periphery executable binary.
-
#scan(options = {}) {|entry| ... } ⇒ void
Scans Swift files.
Constructor Details
#initialize(dangerfile) ⇒ DangerPeriphery
Returns a new instance of DangerPeriphery.
48 49 50 51 52 |
# File 'lib/danger/danger_periphery.rb', line 48 def initialize(dangerfile) super @format = :checkstyle @warning_as_error = false end |
Instance Attribute Details
#binary_path ⇒ String
Path to Periphery executable. By default the value is nil and the executable is searched from $PATH.
24 25 26 |
# File 'lib/danger/danger_periphery.rb', line 24 def binary_path @binary_path end |
#format=(value) ⇒ Symbol (writeonly)
For internal use only.
41 42 43 |
# File 'lib/danger/danger_periphery.rb', line 41 def format=(value) @format = value end |
#scan_all_files ⇒ Boolean
A flag to force Periphery report problems about all files.
30 31 32 |
# File 'lib/danger/danger_periphery.rb', line 30 def scan_all_files @scan_all_files end |
#warning_as_error ⇒ Boolean
A flag to treat warnings as errors.
36 37 38 |
# File 'lib/danger/danger_periphery.rb', line 36 def warning_as_error @warning_as_error end |
Instance Method Details
#install(version: :latest, path: 'periphery', force: false) ⇒ void
This method returns an undefined value.
Download and install Periphery executable binary.
96 97 98 99 100 |
# File 'lib/danger/danger_periphery.rb', line 96 def install(version: :latest, path: 'periphery', force: false) installer = Periphery::Installer.new(version) installer.install(path, force: force) self.binary_path = File.absolute_path(path) end |
#scan(options = {}) {|entry| ... } ⇒ void
This method returns an undefined value.
Scans Swift files. Raises an error when Periphery executable is not found.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/danger/danger_periphery.rb', line 77 def scan( = {}) output = Periphery::Runner.new(binary_path).scan(.merge(OPTION_OVERRIDES).merge(format: @format)) files = files_in_diff unless @scan_all_files parser.parse(output).each do |entry| next unless @scan_all_files || files.include?(entry.path) next if block_given? && !yield(entry) report(entry., file: entry.path, line: entry.line) end end |