This repository has been archived by the owner on Sep 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathlint.rake
55 lines (44 loc) · 1.58 KB
/
lint.rake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
50
51
52
53
54
55
# Used constants:
# - WORKSPACE
namespace :lint do
SWIFTLINT_VERSION = '0.19.0'
desc 'Install swiftlint'
task :install do |task|
next if check_version()
if not system('tty >/dev/null')
puts "warning: Unable to install SwiftLint #{SWIFTLINT_VERSION} without a terminal. Please run 'bundle exec rake lint:install' from a terminal."
next
end
url = "https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/SwiftLint.pkg"
tmppath = '/tmp/SwiftLint.pkg'
Utils.run([
"curl -Lo #{tmppath} #{url}",
"sudo installer -pkg #{tmppath} -target /"
], task)
end
if File.directory?('Sources')
desc 'Lint the code'
task :code => :install do |task|
Utils.print_header 'Linting the code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Sources), task)
end
end
desc 'Lint the tests'
task :tests => :install do |task|
Utils.print_header 'Linting the unit test code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path "Tests/#{WORKSPACE}Tests"), task)
end
if File.directory?('Tests/Expected')
desc 'Lint the output'
task :output => :install do |task|
Utils.print_header 'Linting the template output code'
Utils.run(%Q(swiftlint lint --no-cache --strict --path Tests/Expected), task)
end
end
def check_version
return false if not system('which swiftlint > /dev/null')
current = `swiftlint version`.chomp.split('.').map { |e| e.to_i }
required = SWIFTLINT_VERSION.chomp.split('.').map { |e| e.to_i }
return (current <=> required) >= 0
end
end