Class: Danger::DangerIblinter

Inherits:
Plugin
  • Object
show all
Defined in:
lib/iblinter/plugin.rb

Overview

Lint Interface Builder files inside your projects. This is done using the [IBLinter](github.com/IBDecodable/IBLinter) tool.

Examples:

Specifying custom config file and path.


iblinter.config_file = ".iblinter.yml"
iblinter.lint

See Also:

  • IBDecodable/IBLinter

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#binary_pathvoid

This method returns an undefined value.

The path to IBLinter“s execution



20
21
22
# File 'lib/iblinter/plugin.rb', line 20

def binary_path
  @binary_path
end

Instance Method Details

#iblinterIBLinterRunner

Instantiate iblinter

Returns:



53
54
55
# File 'lib/iblinter/plugin.rb', line 53

def iblinter
  IBLinterRunner.new(@binary_path)
end

#lint(path = Dir.pwd, fail_on_warning: false, inline_mode: true, options: {}) ⇒ void

This method returns an undefined value.

Lints IB files. Will fail if ‘iblinter` cannot be installed correctly.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/iblinter/plugin.rb', line 25

def lint(path = Dir.pwd, fail_on_warning: false, inline_mode: true, options: {})
  raise "iblinter is not installed" unless iblinter_installed?

  issues = iblinter.lint(path, options)
  return if issues.empty?

  errors = issues.select { |v| v["level"] == "error" }
  warnings = issues.select { |v| v["level"] == "warning" }

  if inline_mode
    send_inline_comment(warnings, fail_on_warning ? :fail : :warn)
    send_inline_comment(errors, :fail)
  else
    message = "### IBLinter found issues\n\n"
    message << markdown_issues(errors, "Errors", ":rotating_light:") unless errors.empty?
    message << markdown_issues(warnings, "Warnings", ":warning:") unless warnings.empty?
    markdown message
  end

  if errors.count.positive?
    fail "Failed due to IBLinter errors"
  elsif fail_on_warning && warnings.count.positive?
    fail "Failed due to IBLinter warnings"
  end
end