Class: Swiftlint

Inherits:
Object
  • Object
show all
Defined in:
ext/swiftlint/swiftlint.rb

Overview

A wrapper to use SwiftLint via a Ruby API.

Instance Method Summary collapse

Constructor Details

#initialize(swiftlint_path = nil) ⇒ Swiftlint

Returns a new instance of Swiftlint.



5
6
7
# File 'ext/swiftlint/swiftlint.rb', line 5

def initialize(swiftlint_path = nil)
  @swiftlint_path = swiftlint_path
end

Instance Method Details

#installed?Boolean

Return true if swiftlint is installed or false otherwise

Returns:

  • (Boolean)


31
32
33
# File 'ext/swiftlint/swiftlint.rb', line 31

def installed?
  File.exist?(swiftlint_path)
end

#lint(options, additional_swiftlint_args, env = nil) ⇒ Object

Shortcut for running the lint command



26
27
28
# File 'ext/swiftlint/swiftlint.rb', line 26

def lint(options, additional_swiftlint_args, env = nil)
  run('lint', additional_swiftlint_args, options, env)
end

#run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil) ⇒ Object

Runs swiftlint



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'ext/swiftlint/swiftlint.rb', line 10

def run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil)
  # change pwd before run swiftlint
  Dir.chdir options.delete(:pwd) if options.key? :pwd

  # Add `env` to environment
  update_env(env)
  begin
    # run swiftlint with provided options
    `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options, additional_swiftlint_args)}`
  ensure
    # Remove any ENV variables we might have added
    restore_env()
  end
end

#swiftlint_pathObject

Return swiftlint execution path



36
37
38
# File 'ext/swiftlint/swiftlint.rb', line 36

def swiftlint_path
  @swiftlint_path || default_swiftlint_path
end