Class: Fastlane::Actions::OclintAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/oclint.rb

Documentation collapse

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, details, sh, step_text

Class Method Details

.authorObject


108
109
110
# File 'lib/fastlane/actions/oclint.rb', line 108

def self.author
  'HeEAaD'
end

.available_optionsObject


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/fastlane/actions/oclint.rb', line 59

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :compile_commands,
                                 env_name: 'FL_OCLINT_COMPILE_COMMANDS',
                                 description: 'The json compilation database, use xctool reporter \'json-compilation-database\'',
                                 default_value: 'compile_commands.json',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :select_reqex,
                                 env_name: 'FL_OCLINT_SELECT_REQEX',
                                 description: 'Select all files matching this reqex',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :report_type,
                                 env_name: 'FL_OCLINT_REPORT_TYPE',
                                 description: 'The type of the report (default: html)',
                                 default_value: 'html',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :report_path,
                                 env_name: 'FL_OCLINT_REPORT_PATH',
                                 description: 'The reports file path',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :rc,
                                 env_name: 'FL_OCLINT_RC',
                                 description: 'Override the default behavior of rules',
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :max_priority_1,
                                 env_name: 'FL_OCLINT_MAX_PRIOTITY_1',
                                 description: 'The max allowed number of priority 1 violations',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :max_priority_2,
                                 env_name: 'FL_OCLINT_MAX_PRIOTITY_2',
                                 description: 'The max allowed number of priority 2 violations',
                                 is_string: false,
                                 optional: true),
    FastlaneCore::ConfigItem.new(key: :max_priority_3,
                                 env_name: 'FL_OCLINT_MAX_PRIOTITY_3',
                                 description: 'The max allowed number of priority 3 violations',
                                 is_string: false,
                                 optional: true)
  ]
end

.descriptionObject


55
56
57
# File 'lib/fastlane/actions/oclint.rb', line 55

def self.description
  "Lints implementation files with OCLint"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)

112
113
114
# File 'lib/fastlane/actions/oclint.rb', line 112

def self.is_supported?(platform)
  true
end

.outputObject


102
103
104
105
106
# File 'lib/fastlane/actions/oclint.rb', line 102

def self.output
  [
    ['FL_OCLINT_REPORT_PATH', 'The reports file path']
  ]
end

.run(params) ⇒ Object


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
# File 'lib/fastlane/actions/oclint.rb', line 8

def self.run(params)

  select_reqex = params[:select_reqex]
  
  compile_commands = params[:compile_commands]
  raise "Could not find json compilation database at path '#{compile_commands}'".red unless File.exists?(compile_commands)
  
  files = JSON.parse(File.read(compile_commands)).map { |compile_command| compile_command['file'] }
  files.uniq!
  files.select! do |file|
    file_ruby = file.gsub('\ ', ' ')
    File.exists?(file_ruby) and (!select_reqex or file_ruby =~ select_reqex)
  end

  command_prefix = [
    'cd',
    File.expand_path('.').shellescape,
    '&&'
  ].join(' ')
  
  report_type = params[:report_type]
  report_path = params[:report_path] ? params[:report_path] : 'oclint_report.' + report_type
  
  oclint_args = ["-report-type=#{report_type}", "-o=#{report_path}"]
  oclint_args << "-rc=#{params[:rc]}" if params[:rc]
  oclint_args << "-max-priority-1=#{params[:max_priority_1]}" if params[:max_priority_1]
  oclint_args << "-max-priority-2=#{params[:max_priority_2]}" if params[:max_priority_2]
  oclint_args << "-max-priority-3=#{params[:max_priority_3]}" if params[:max_priority_3]
          
  command = [
    command_prefix,
    'oclint',
    oclint_args,
    '"' + files.join('" "') + '"'
  ].join(' ')
  
  Action.sh command

  Actions.lane_context[SharedValues::FL_OCLINT_REPORT_PATH] = File.expand_path(report_path)
end