-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathlint.rake
50 lines (40 loc) · 1.24 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
# frozen_string_literal: true
# Used constants:
# - BUILD_DIR
namespace :lint do
SWIFTLINT = 'rakelib/lint.sh'
SWIFTLINT_VERSION = '0.48.0'
task :install do |task|
next if check_version
if OS.mac?
url = "https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/portable_swiftlint.zip"
else
url = "https://github.com/realm/SwiftLint/releases/download/#{SWIFTLINT_VERSION}/swiftlint_linux.zip"
end
tmppath = '/tmp/swiftlint.zip'
destination = "#{BUILD_DIR}/swiftlint"
Utils.run([
%(curl -Lo #{tmppath} #{url}),
%(rm -rf #{destination}),
%(mkdir -p #{destination}),
%(unzip #{tmppath} -d #{destination})
], task)
end
desc 'Lint the code'
task :code => :install do |task|
Utils.print_header 'Linting the code'
Utils.run(%(#{SWIFTLINT} sources), task)
end
desc 'Lint the tests'
task :tests => :install do |task|
Utils.print_header 'Linting the unit test code'
Utils.run(%(#{SWIFTLINT} tests), task)
end
def check_version
swiftlint = "#{BUILD_DIR}/swiftlint/swiftlint"
return false unless File.executable?(swiftlint)
current = `#{swiftlint} version`.chomp
required = SWIFTLINT_VERSION.chomp
current == required
end
end