fastlane-plugin-lizard 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9360c19ec778d87634bb6a89daf38b7e482de826
4
- data.tar.gz: 41fae722e87952ecc8f9502c503b9f0e6b368d48
3
+ metadata.gz: 9de970de855b2210fbf9fb92295f5702084531ae
4
+ data.tar.gz: 0bce82b9a9c562a7c1b8d2abb09bdcbe5bbcc594
5
5
  SHA512:
6
- metadata.gz: 20ee83f0a870a8f4fa7d1e7524f4d2b42d7dcb3a8cde4c4fa370acfd9c48ecf791bf97aa9fec5cf962f5544f562a5364430449ea9caabfb82ee5fdd309f95965
7
- data.tar.gz: 552030bb5dd3d18bb7febcf9d57cae2955455089733afec592f646196b80666fac25865fc585ac20560ff1339d9700060a8663d71eaf19a3d666de25c3fa3e8c
6
+ metadata.gz: bba85d449d509527f062e79bf433754eed0a803207ece49c12b64c404d557eb54ad4afce9aa9c331f8ea9e7acae1a61c4478c30c3bb4611ab8e2ce955ffc5a44
7
+ data.tar.gz: 8cca9c3904dc1f04e520cc83eb9113416d1e0d307460f2af75aed854c37327e8c99029c84135aa2531176a37b2705a3d0614236c2a11af6f8167bde9e6fc27ca
@@ -2,7 +2,29 @@ module Fastlane
2
2
  module Actions
3
3
  class LizardAction < Action
4
4
  def self.run(params)
5
- command = ["lizard #{params[:source_folder]}"]
5
+ if `which lizard`.to_s.empty?
6
+ UI.user_error!("You have to install lizard using `[sudo] pip install lizard` or specify the executable path with the `:executable` option.")
7
+ end
8
+
9
+ command = forming_command(params)
10
+
11
+ if params[:show_warnings]
12
+ Fastlane::Actions.sh_control_output("lizard #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
13
+ end
14
+
15
+ begin
16
+ Actions.sh(command.join(" "), log: false)
17
+ rescue StandardError => e
18
+ puts e
19
+ handle_lizard_error(params[:ignore_exit_status], $CHILD_STATUS.exitstatus)
20
+ end
21
+ end
22
+
23
+ def self.forming_command(params)
24
+ command = []
25
+ command << 'lizard' unless params[:executable]
26
+ command << "python #{params[:executable]}" if params[:executable]
27
+ command << params[:source_folder].to_s if params[:source_folder]
6
28
  command << "-l #{params[:language]}" if params[:language]
7
29
  command << "--#{params[:export_type]}" if params[:export_type]
8
30
  command << "-C #{params[:ccn]}" if params[:ccn] # stands for cyclomatic complexity number
@@ -14,21 +36,33 @@ module Fastlane
14
36
  command << "-E #{params[:extensions]}" if params[:extensions]
15
37
  command << "-s #{params[:sorting]}" if params[:sorting]
16
38
  command << "-W #{params[:whitelist]}" if params[:whitelist]
17
- command << "> ./#{params[:report_file]}"
39
+ command << "> #{params[:report_file].shellescape}" if params[:report_file]
18
40
 
19
- if params[:show_warnings]
20
- Fastlane::Actions.sh_control_output("lizard #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true)
21
- end
22
- if File.directory?(params[:report_file])
23
- Fastlane::Actions.sh_control_output(command.join(" "), print_command: false, print_command_output: false)
41
+ return command
42
+ end
43
+
44
+ def self.handle_lizard_error(ignore_exit_status, exit_status)
45
+ if ignore_exit_status
46
+ failure_suffix = 'which would normally fail the build.'
47
+ secondary_message = 'fastlane will continue because the `ignore_exit_status` option was used! 🙈'
24
48
  else
25
- # throws user_error
26
- UI.user_error!("Please ensure #{params[:report_file]} is writable")
49
+ failure_suffix = 'which represents a failure.'
50
+ secondary_message = 'If you want fastlane to continue anyway, use the `ignore_exit_status` option. 🙈'
27
51
  end
52
+
53
+ UI.important("")
54
+ UI.important("Lizard finished with exit code #{exit_status}, #{failure_suffix}")
55
+ UI.important(secondary_message)
56
+ UI.important("")
57
+ UI.user_error!("Lizard finished with errors (exit code: #{exit_status})") unless ignore_exit_status
28
58
  end
29
59
 
60
+ #####################################################
61
+ # @!group Documentation
62
+ #####################################################
63
+
30
64
  def self.description
31
- "Lizard is an extensible Cyclomatic Complexity Analyzer for many imperative programming languages including C/C++"
65
+ "Run lizard code cyclomatic complexity analysis."
32
66
  end
33
67
 
34
68
  def self.authors
@@ -44,31 +78,34 @@ module Fastlane
44
78
  FastlaneCore::ConfigItem.new(key: :source_folder,
45
79
  env_name: "FL_LIZARD_SOURCE_FOLDER",
46
80
  description: "The folders that contains the source code for lizard to scan",
47
- verify_block: proc do |value|
48
- UI.user_error!("No source folder specified") unless value and !value.empty?
49
- end),
81
+ optional: true),
50
82
  FastlaneCore::ConfigItem.new(key: :language,
51
83
  env_name: "FL_LIZARD_LANGUAGE",
52
84
  description: "List the programming languages you want to analyze",
53
- default_value: "swift"),
85
+ default_value: "swift",
86
+ optional: true),
54
87
  FastlaneCore::ConfigItem.new(key: :export_type,
55
- env_name: "FL_LIZARD_EXPORT_TYPE",
56
- description: "The file extension of your export. E.g. xml, csv"),
88
+ env_name: "FL_LIZARD_EXPORT_TYPE",
89
+ description: "The file extension of your export. E.g. xml, csv",
90
+ optional: true),
57
91
  FastlaneCore::ConfigItem.new(key: :ccn,
58
92
  env_name: "FL_LIZARD_CCN",
59
93
  description: "Threshold of cyclomatic complexity number warning",
94
+ is_string: false,
60
95
  optional: true),
61
96
  FastlaneCore::ConfigItem.new(key: :length,
62
- env_name: "FL_LIZARD_LENGTH",
63
- description: "Threshold for maximum function length warning",
64
- optional: true),
97
+ env_name: "FL_LIZARD_LENGTH",
98
+ description: "Threshold for maximum function length warning",
99
+ is_string: false,
100
+ optional: true),
65
101
  FastlaneCore::ConfigItem.new(key: :arguments,
66
- env_name: "FL_LIZARD_ARGUMENTS",
67
- description: "Limit for number of parameters",
68
- optional: true),
102
+ env_name: "FL_LIZARD_ARGUMENTS",
103
+ description: "Limit for number of parameters",
104
+ optional: true),
69
105
  FastlaneCore::ConfigItem.new(key: :number,
70
106
  env_name: "FL_LIZARD_NUMBER",
71
107
  description: "If the number of warnings is equal or less than the number, the tool will exit normally, otherwise it will generate error. Useful in makefile for legacy code",
108
+ is_string: false,
72
109
  optional: true),
73
110
  FastlaneCore::ConfigItem.new(key: :exclude,
74
111
  env_name: "FL_LIZARD_EXCLUDE",
@@ -82,6 +119,7 @@ module Fastlane
82
119
  FastlaneCore::ConfigItem.new(key: :extensions,
83
120
  env_name: "FL_LIZARD_EXTENSIONS",
84
121
  description: "User the extensions. The available extensions are: -Ecpre: it will ignore code in the #else branch. -Ewordcount: count word frequencies and generate tag cloud. -Eoutside: include the global code as one function",
122
+ is_string: true,
85
123
  optional: true),
86
124
  FastlaneCore::ConfigItem.new(key: :sorting,
87
125
  env_name: "FL_LIZARD_SORTING",
@@ -93,17 +131,27 @@ module Fastlane
93
131
  optional: true),
94
132
  FastlaneCore::ConfigItem.new(key: :report_file,
95
133
  env_name: "FL_LIZARD_REPORT_FILE",
96
- description: "The folder/file which lizard output to"),
134
+ description: "The folder/file which lizard output to",
135
+ optional: true),
136
+ FastlaneCore::ConfigItem.new(key: :ignore_exit_status,
137
+ description: "Ignore the exit status of the lizard command, so that serious violations don't fail the build (true/false)",
138
+ default_value: false,
139
+ is_string: false,
140
+ optional: true),
97
141
  FastlaneCore::ConfigItem.new(key: :show_warnings,
98
142
  env_name: "FL_LIZARD_SHOW_WARNINGS",
99
143
  description: "Show lizard warnings on console, on code that is too complex",
100
144
  is_string: false,
101
- default_value: false)
145
+ default_value: false),
146
+ FastlaneCore::ConfigItem.new(key: :executable,
147
+ description: "Path to the `lizard.py` executable on your machine",
148
+ is_string: true,
149
+ optional: true)
102
150
  ]
103
151
  end
104
152
 
105
153
  def self.is_supported?(platform)
106
- true
154
+ [:ios, :android, :mac].include?(platform)
107
155
  end
108
156
  end
109
157
  end
@@ -0,0 +1,166 @@
1
+ module Fastlane
2
+ module Actions
3
+ class SwiftlintAction < Action
4
+ def self.run(params)
5
+ if `which swiftlint`.to_s.length == 0 && params[:executable].nil? && !Helper.test?
6
+ UI.user_error!("You have to install swiftlint using `brew install swiftlint` or specify the executable path with the `:executable` option.")
7
+ end
8
+
9
+ version = swiftlint_version(executable: params[:executable])
10
+ if params[:mode] == :autocorrect and version < Gem::Version.new('0.5.0') and !Helper.test?
11
+ UI.user_error!("Your version of swiftlint (#{version}) does not support autocorrect mode.\nUpdate swiftlint using `brew update && brew upgrade swiftlint`")
12
+ end
13
+
14
+ command = (params[:executable] || "swiftlint").dup
15
+ command << " #{params[:mode]}"
16
+ command << supported_option_switch(params, :strict, "0.9.2", true)
17
+ command << " --config #{params[:config_file].shellescape}" if params[:config_file]
18
+ command << " --reporter #{params[:reporter]}" if params[:reporter]
19
+ command << supported_option_switch(params, :quiet, "0.9.0", true)
20
+
21
+ if params[:files]
22
+ if version < Gem::Version.new('0.5.1')
23
+ UI.user_error!("Your version of swiftlint (#{version}) does not support list of files as input.\nUpdate swiftlint using `brew update && brew upgrade swiftlint`")
24
+ end
25
+
26
+ files = params[:files].map.with_index(0) { |f, i| "SCRIPT_INPUT_FILE_#{i}=#{f.shellescape}" }.join(" ")
27
+ command = command.prepend("SCRIPT_INPUT_FILE_COUNT=#{params[:files].count} #{files} ")
28
+ command << " --use-script-input-files"
29
+ end
30
+
31
+ command << " > #{params[:output_file].shellescape}" if params[:output_file]
32
+
33
+ begin
34
+ Actions.sh(command)
35
+ rescue
36
+ handle_swiftlint_error(params[:ignore_exit_status], $?.exitstatus)
37
+ end
38
+ end
39
+
40
+ # Get current SwiftLint version
41
+ def self.swiftlint_version(executable: nil)
42
+ binary = executable || 'swiftlint'
43
+ Gem::Version.new(`#{binary} version`.chomp)
44
+ end
45
+
46
+ # Return "--option" switch if option is on and current SwiftLint version is greater or equal than min version.
47
+ # Return "" otherwise.
48
+ def self.supported_option_switch(params, option, min_version, can_ignore = false)
49
+ return "" unless params[option]
50
+ version = swiftlint_version(executable: params[:executable])
51
+ if version < Gem::Version.new(min_version)
52
+ message = "Your version of swiftlint (#{version}) does not support '--#{option}' option.\nUpdate swiftlint to #{min_version} or above using `brew update && brew upgrade swiftlint`"
53
+ message += "\nThe option will be ignored." if can_ignore
54
+ can_ignore ? UI.important(message) : UI.user_error!(message)
55
+ ""
56
+ else
57
+ " --#{option}"
58
+ end
59
+ end
60
+
61
+ #####################################################
62
+ # @!group Documentation
63
+ #####################################################
64
+
65
+ def self.description
66
+ "Run swift code validation using Lizard"
67
+ end
68
+
69
+ def self.details
70
+ end
71
+
72
+ def self.available_options
73
+ [
74
+ FastlaneCore::ConfigItem.new(key: :mode,
75
+ description: "SwiftLint mode: :lint or :autocorrect",
76
+ is_string: false,
77
+ default_value: :lint,
78
+ optional: true),
79
+ FastlaneCore::ConfigItem.new(key: :output_file,
80
+ description: 'Path to output SwiftLint result',
81
+ optional: true),
82
+ FastlaneCore::ConfigItem.new(key: :config_file,
83
+ description: 'Custom configuration file of SwiftLint',
84
+ optional: true),
85
+ FastlaneCore::ConfigItem.new(key: :strict,
86
+ description: 'Fail on warnings? (true/false)',
87
+ default_value: false,
88
+ is_string: false,
89
+ optional: true),
90
+ FastlaneCore::ConfigItem.new(key: :files,
91
+ description: 'List of files to process',
92
+ is_string: false,
93
+ optional: true),
94
+ FastlaneCore::ConfigItem.new(key: :ignore_exit_status,
95
+ description: "Ignore the exit status of the SwiftLint command, so that serious violations \
96
+ don't fail the build (true/false)",
97
+ default_value: false,
98
+ is_string: false,
99
+ optional: true),
100
+ FastlaneCore::ConfigItem.new(key: :reporter,
101
+ description: 'Choose output reporter',
102
+ is_string: true,
103
+ optional: true),
104
+ FastlaneCore::ConfigItem.new(key: :quiet,
105
+ description: "Don't print status logs like 'Linting <file>' & 'Done linting'",
106
+ default_value: false,
107
+ is_string: false,
108
+ optional: true),
109
+ FastlaneCore::ConfigItem.new(key: :executable,
110
+ description: "Path to the `swiftlint` executable on your machine",
111
+ is_string: true,
112
+ optional: true)
113
+ ]
114
+ end
115
+
116
+ def self.output
117
+ end
118
+
119
+ def self.return_value
120
+ end
121
+
122
+ def self.authors
123
+ ["KrauseFx"]
124
+ end
125
+
126
+ def self.is_supported?(platform)
127
+ [:ios, :mac].include?(platform)
128
+ end
129
+
130
+ def self.example_code
131
+ [
132
+ 'swiftlint(
133
+ mode: :lint, # SwiftLint mode: :lint (default) or :autocorrect
134
+ output_file: "swiftlint.result.json", # The path of the output file (optional)
135
+ config_file: ".swiftlint-ci.yml", # The path of the configuration file (optional)
136
+ files: [ # List of files to process (optional)
137
+ "AppDelegate.swift",
138
+ "path/to/project/Model.swift"
139
+ ],
140
+ ignore_exit_status: true # Allow fastlane to continue even if SwiftLint returns a non-zero exit status
141
+ )'
142
+ ]
143
+ end
144
+
145
+ def self.category
146
+ :testing
147
+ end
148
+
149
+ def self.handle_swiftlint_error(ignore_exit_status, exit_status)
150
+ if ignore_exit_status
151
+ failure_suffix = 'which would normally fail the build.'
152
+ secondary_message = 'fastlane will continue because the `ignore_exit_status` option was used! 🙈'
153
+ else
154
+ failure_suffix = 'which represents a failure.'
155
+ secondary_message = 'If you want fastlane to continue anyway, use the `ignore_exit_status` option. 🙈'
156
+ end
157
+
158
+ UI.important("")
159
+ UI.important("SwiftLint finished with exit code #{exit_status}, #{failure_suffix}")
160
+ UI.important(secondary_message)
161
+ UI.important("")
162
+ UI.user_error!("SwiftLint finished with errors (exit code: #{exit_status})") unless ignore_exit_status
163
+ end
164
+ end
165
+ end
166
+ end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Lizard
3
- VERSION = "0.1.2"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-lizard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Moses Liao
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-21 00:00:00.000000000 Z
11
+ date: 2018-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -45,7 +45,7 @@ dependencies:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -59,7 +59,7 @@ dependencies:
59
59
  - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
- type: :development
62
+ type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
@@ -73,7 +73,7 @@ dependencies:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
- type: :development
76
+ type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
@@ -87,7 +87,7 @@ dependencies:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
- type: :development
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
@@ -101,7 +101,7 @@ dependencies:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
- type: :development
104
+ type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
@@ -115,7 +115,7 @@ dependencies:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
- type: :development
118
+ type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
@@ -132,6 +132,7 @@ files:
132
132
  - README.md
133
133
  - lib/fastlane/plugin/lizard.rb
134
134
  - lib/fastlane/plugin/lizard/actions/lizard_action.rb
135
+ - lib/fastlane/plugin/lizard/actions/swiftlint_example.rb
135
136
  - lib/fastlane/plugin/lizard/helper/lizard_helper.rb
136
137
  - lib/fastlane/plugin/lizard/version.rb
137
138
  homepage: https://github.com/liaogz82/fastlane-plugin-lizard
@@ -157,5 +158,5 @@ rubyforge_project:
157
158
  rubygems_version: 2.6.13
158
159
  signing_key:
159
160
  specification_version: 4
160
- summary: it uses lizard to calculate code complexity
161
+ summary: Run swift code complexity analytics using Lizard
161
162
  test_files: []