Class: Fastlane::Actions::SwiftlintCodequalityAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb

Class Method Summary collapse

Class Method Details

.authorsObject



60
61
62
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 60

def self.authors
  ["madsbogeskov"]
end

.available_optionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 72

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                            env_name: "SWIFTLINT_CODEQUALITY_PATH",
                         description: "The path to the SwiftLint results file",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :output,
                            env_name: "SWIFTLINT_CODEQUALITY_OUTPUT",
                         description: "The path to the generated output report",
                            optional: false,
                                type: String),
    FastlaneCore::ConfigItem.new(key: :prefix,
                            env_name: "SWIFTLINT_CODEQUALITY_PREFIX_PATH",
                         description: "Used to prefix the path of a file. Usefull in e.g. React Native projects where the iOS project is in a subfolder",
                            optional: true,
                       default_value: '',
                                type: String)
  ]
end

.descriptionObject



56
57
58
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 56

def self.description
  "Converts SwiftLint reports into GitLab support CodeQuality reports"
end

.detailsObject



68
69
70
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 68

def self.details
  "Converts SwiftLint reports into GitLab support CodeQuality reports"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 93

def self.is_supported?(platform)
  true
end

.return_valueObject



64
65
66
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 64

def self.return_value
  
end

.run(params) ⇒ Object



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
# File 'lib/fastlane/plugin/swiftlint_codequality/actions/swiftlint_codequality_action.rb', line 7

def self.run(params)
  UI.message("Parsing SwiftLint report at #{params[:path]}")

  pwd = `pwd`.strip

  result = File.open(params[:path])
      .each
      .select { |l| l.include?("Warning Threshold Violation") == false }
      .map { |line|
        filename, start, reason = line.match(/(.*\.swift):(\d+):\d+:\s*(.*)/).captures
  
        # example: error: Type Name Violation: Type name should only contain alphanumeric characters: 'FILE' (type_name)

        issue_type, failure_type, description, rule = reason.match(/(.*?):?\s(.*?):\s(.*)\((.*)\)/).captures

        case issue_type
        when 'error'
          severity = 'critical'
        when 'warning'
          severity = 'minor'
        else
          severity = 'info'
        end

         {
          :type => "issue",
          :check_name => failure_type.strip,
          :description => description.strip, 
          :fingerprint => Digest::MD5.hexdigest(line),
          :severity => severity,
          :location => {
            :path => params[:prefix] + filename.sub(pwd, ''),
            :lines => {
              :begin => start.to_i,
              :end => start.to_i
            }
          }
        }
      }
      .to_a
      .to_json



  IO.write(params[:output], result)

  UI.success "🚀 Generated Code Quality report at #{params[:output]} 🚀"
end