fastlane-plugin-swiftlint_codequality 1.0.1 β†’ 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcb5caa1c9cfe3874e7cd77a62ceb1ca8bf9f5ae250968a864fc6826e1d9f090
4
- data.tar.gz: 0cd78729191c9ab5b4f49161b0a701dc1b709752757039b036107c6cdcce0202
3
+ metadata.gz: b89de6a3679654cb2828d0ef86169f4e811c0f1b5f57fe01a05f5de546233893
4
+ data.tar.gz: c4d3fe9240bf1c2e324c86981af465941ff35070b9b1f889b368f0ec26b367d1
5
5
  SHA512:
6
- metadata.gz: '029d5fa7366cc9a7c12faf0fcfd21c334ada9f0412d86482ab3b14ff5963796cc5b28e623d4dafda84b493947dfaa74a126bec9e993157b007dc2ad374fd9f69'
7
- data.tar.gz: 63d394b304b77fb9d9393c4557ab1064d7907c94a4575532ba2b9c644b45a25173c74a6f341ceb68723db3ef4478d8399e92a9d34fded33d4e601de7cdaed049
6
+ metadata.gz: 8311edcc371f126c6373f4664ade3988939e14dfecb386194a87bcbc784e194f027db45e10d91b9b6741eb5737197dc5812f706563653c6f778447a7df15f3f9
7
+ data.tar.gz: 257b8eb68c5c93132bea3b12719f3ec468fe9bfce587b44f76c76c25600bdd1be4df151bcbb52ec14ce2e9ec9efa123cb4b0b65d08120f804d2421a9b38c167b
@@ -7,50 +7,81 @@ module Fastlane
7
7
  def self.run(params)
8
8
  UI.message("Parsing SwiftLint report at #{params[:path]}")
9
9
 
10
- pwd = `pwd`.strip
11
-
12
- result = File.open(params[:path])
13
- .each
14
- .select { |l| l.include?("Warning Threshold Violation") == false }
15
- .map { |line|
16
- filename, start, reason = line.match(/(.*\.swift):(\d+):\d+:\s*(.*)/).captures
17
-
18
- # example: error: Type Name Violation: Type name should only contain alphanumeric characters: 'FILE' (type_name)
19
-
20
- issue_type, failure_type, description, rule = reason.match(/(.*?):?\s(.*?):\s(.*)\((.*)\)/).captures
21
-
22
- case issue_type
23
- when 'error'
24
- severity = 'critical'
25
- when 'warning'
26
- severity = 'minor'
27
- else
28
- severity = 'info'
29
- end
30
-
31
- {
32
- :type => "issue",
33
- :check_name => failure_type.strip,
34
- :description => description.strip,
35
- :fingerprint => Digest::MD5.hexdigest(line),
36
- :severity => severity,
37
- :location => {
38
- :path => params[:prefix] + filename.sub(pwd, ''),
39
- :lines => {
40
- :begin => start.to_i,
41
- :end => start.to_i
42
- }
43
- }
44
- }
45
- }
46
- .to_a
47
- .to_json
10
+ pwd = Fastlane::Actions.sh("pwd", log: false).strip
11
+
12
+ report = File.open(params[:path])
13
+ result = report
14
+ .each
15
+ .select { |l| l.include?("Warning Threshold Violation") == false }
16
+ .map { |line| self.line_to_code_climate_object(line, params[:prefix], pwd) }
17
+ .to_a
18
+
19
+ IO.write(params[:output], result.to_json)
48
20
 
21
+ UI.success("πŸš€ Generated Code Quality report at #{params[:output]} πŸš€")
49
22
 
23
+ handle_result(result, params[:fail_build_conditions])
24
+ end
50
25
 
51
- IO.write(params[:output], result)
26
+ def self.line_to_code_climate_object(line, prefix, pwd)
27
+ filename, start, reason = line.match(/(.*\.swift):(\d+):\d+:\s*(.*)/).captures
28
+
29
+ # example: error: Type Name Violation: Type name should only contain alphanumeric characters: 'FILE' (type_name)
30
+
31
+ issue_type, failure_type, description, _rule = reason.match(/(.*?):?\s(.*?):\s(.*)\((.*)\)/).captures
32
+
33
+ case issue_type
34
+ when 'error'
35
+ severity = Severity::CRITICAL
36
+ when 'warning'
37
+ severity = Severity::MINOR
38
+ else
39
+ severity = Severity::INFO
40
+ end
41
+
42
+ {
43
+ type: "issue",
44
+ check_name: failure_type.strip,
45
+ description: description.strip,
46
+ fingerprint: Digest::MD5.hexdigest(line),
47
+ severity: severity,
48
+ location: {
49
+ path: prefix + filename.sub(pwd, ''),
50
+ lines: {
51
+ begin: start.to_i,
52
+ end: start.to_i
53
+ }
54
+ }
55
+ }
56
+ end
52
57
 
53
- UI.success "πŸš€ Generated Code Quality report at #{params[:output]} πŸš€"
58
+ def self.handle_result(result, fail_build_conditions)
59
+ critical_limit = fail_build_conditions.fetch(Severity::CRITICAL.to_sym, 0)
60
+ minor_limit = fail_build_conditions.fetch(Severity::MINOR.to_sym, 0)
61
+ info_limit = fail_build_conditions.fetch(Severity::INFO.to_sym, 0)
62
+
63
+ critical_count = result.select { |issue| issue[:severity] == Severity::CRITICAL }.length
64
+ minor_count = result.select { |issue| issue[:severity] == Severity::MINOR }.length
65
+ info_count = result.select { |issue| issue[:severity] == Severity::INFO }.length
66
+
67
+ UI.important("")
68
+ violations = false
69
+ if critical_count > critical_limit
70
+ UI.important("Critical issue limit (#{critical_limit}) exceeded: #{critical_count}")
71
+ violations = true
72
+ end
73
+ if minor_count > minor_limit
74
+ UI.important("Minor issue limit (#{minor_limit}) exceeded: #{minor_count}")
75
+ violations = true
76
+ end
77
+ if info_count > info_limit
78
+ UI.important("Info issue limit (#{info_limit}) exceeded: #{info_count}")
79
+ violations = true
80
+ end
81
+
82
+ UI.important("")
83
+
84
+ UI.user_error!("Severity limits where exceeded.") if violations
54
85
  end
55
86
 
56
87
  def self.description
@@ -61,10 +92,6 @@ module Fastlane
61
92
  ["madsbogeskov"]
62
93
  end
63
94
 
64
- def self.return_value
65
-
66
- end
67
-
68
95
  def self.details
69
96
  "Converts SwiftLint reports into GitLab support CodeQuality reports"
70
97
  end
@@ -86,13 +113,25 @@ module Fastlane
86
113
  description: "Used to prefix the path of a file. Usefull in e.g. React Native projects where the iOS project is in a subfolder",
87
114
  optional: true,
88
115
  default_value: '',
89
- type: String)
116
+ type: String),
117
+ FastlaneCore::ConfigItem.new(key: :fail_build_conditions,
118
+ env_name: "SWIFTLINT_CODEQUALITY_FAIL_BUILD_CONDITIONS",
119
+ description: "A hash with severities and their limits, that if exceeded should result in an exception. Supported severities: critical, minor and info.",
120
+ is_string: false,
121
+ default_value: {},
122
+ optional: true)
90
123
  ]
91
124
  end
92
125
 
93
126
  def self.is_supported?(platform)
94
127
  true
95
128
  end
129
+
130
+ class Severity
131
+ CRITICAL = "critical".freeze
132
+ MINOR = "minor".freeze
133
+ INFO = "info".freeze
134
+ end
96
135
  end
97
136
  end
98
137
  end
@@ -5,7 +5,6 @@ module Fastlane
5
5
 
6
6
  module Helper
7
7
  class SwiftlintCodequalityHelper
8
-
9
8
  end
10
9
  end
11
10
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module SwiftlintCodequality
3
- VERSION = "1.0.1"
3
+ VERSION = "2.0.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-swiftlint_codequality
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mads BΓΈgeskov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry