Class: Danger::DangerPeriphery
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerPeriphery
- Defined in:
- lib/danger_plugin.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.
-
#postprocessor ⇒ Proc
deprecated
Deprecated.
Use #scan with block instead.
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.
-
#process_warnings(&block) ⇒ Proc
deprecated
Deprecated.
Use #scan with block instead.
-
#scan(options = {}, &block) ⇒ void
Scans Swift files.
Constructor Details
#initialize(dangerfile) ⇒ DangerPeriphery
Returns a new instance of DangerPeriphery.
53 54 55 56 57 |
# File 'lib/danger_plugin.rb', line 53 def initialize(dangerfile) super(dangerfile) @postprocessor = ->(_path, _line, _column, ) { true } @format = :checkstyle 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_plugin.rb', line 24 def binary_path @binary_path end |
#format=(value) ⇒ Symbol (writeonly)
For internal use only.
46 47 48 |
# File 'lib/danger_plugin.rb', line 46 def format=(value) @format = value end |
#postprocessor ⇒ Proc
Use #scan with block instead.
Proc object to process each warnings just before showing them. The Proc must receive 4 arguments: path, line, column, message and return one of:
- an array that contains 4 elements [path, line, column, ]
- true
- false
- nil
If Proc returns an array, the warning will be raised based on returned elements. If Proc returns true, the warning will not be modified. If Proc returns false or nil, the warning will be ignored.
By default the Proc returns true.
41 42 43 |
# File 'lib/danger_plugin.rb', line 41 def postprocessor @postprocessor end |
Instance Method Details
#install(version: :latest, path: 'periphery', force: false) ⇒ void
This method returns an undefined value.
Download and install Periphery executable binary.
135 136 137 138 139 |
# File 'lib/danger_plugin.rb', line 135 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 |
#process_warnings(&block) ⇒ Proc
Use #scan with block instead.
Convenience method to set #postprocessor with block.
100 101 102 103 |
# File 'lib/danger_plugin.rb', line 100 def process_warnings(&block) deprecate_in_favor_of_scan @postprocessor = block end |
#scan(options = {}, &block) ⇒ void
This method returns an undefined value.
Scans Swift files. Raises an error when Periphery executable is not found.
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/danger_plugin.rb', line 81 def scan( = {}, &block) output = Periphery::Runner.new(binary_path).scan(.merge(OPTION_OVERRIDES).merge(format: @format)) files = files_in_diff parser.parse(output).each do |entry| next unless files.include?(entry.path) result = postprocess(entry, &block) next unless result path, line, _column, = result warn(, file: path, line: line) end end |