Class: Swiftlint
- Inherits:
-
Object
- Object
- Swiftlint
- Defined in:
- ext/swiftlint/swiftlint.rb
Overview
A wrapper to use SwiftLint via a Ruby API.
Instance Method Summary collapse
-
#initialize(swiftlint_path = nil) ⇒ Swiftlint
constructor
A new instance of Swiftlint.
-
#installed? ⇒ Boolean
Return true if swiftlint is installed or false otherwise.
-
#lint(options, additional_swiftlint_args, env = nil) ⇒ Object
Shortcut for running the lint command.
-
#run(cmd = 'lint', additional_swiftlint_args = '', options = {}, env = nil) ⇒ Object
Runs swiftlint.
-
#swiftlint_path ⇒ Object
Return swiftlint execution path.
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
38 39 40 |
# File 'ext/swiftlint/swiftlint.rb', line 38 def installed? File.exist?(swiftlint_path) end |
#lint(options, additional_swiftlint_args, env = nil) ⇒ Object
Shortcut for running the lint command
33 34 35 |
# File 'ext/swiftlint/swiftlint.rb', line 33 def lint(, additional_swiftlint_args, env = nil) run('lint', additional_swiftlint_args, , 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 24 25 26 27 28 29 30 |
# File 'ext/swiftlint/swiftlint.rb', line 10 def run(cmd = 'lint', additional_swiftlint_args = '', = {}, env = nil) # allow for temporary change to pwd before running swiftlint pwd = .delete(:pwd) command = "#{swiftlint_path} #{cmd} #{swiftlint_arguments(, additional_swiftlint_args)}" # Add `env` to environment update_env(env) begin # run swiftlint with provided options if pwd Dir.chdir(pwd) do `#{command}` end else `#{command}` end ensure # Remove any ENV variables we might have added restore_env() end end |
#swiftlint_path ⇒ Object
Return swiftlint execution path
43 44 45 |
# File 'ext/swiftlint/swiftlint.rb', line 43 def swiftlint_path @swiftlint_path || default_swiftlint_path end |