Class: Fastlane::Actions::LizardAction
- Inherits:
-
Action
- Object
- Action
- Fastlane::Actions::LizardAction
- Defined in:
- lib/fastlane/plugin/lizard/actions/lizard_action.rb
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .is_supported?(platform) ⇒ Boolean
Class Method Summary collapse
- .forming_command(params) ⇒ Object
- .handle_lizard_error(ignore_exit_status, exit_status) ⇒ Object
- .run(params) ⇒ Object
Class Method Details
.authors ⇒ Object
68 69 70 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 68 def self. ["liaogz82"] end |
.available_options ⇒ Object
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 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 76 def self. [ FastlaneCore::ConfigItem.new(key: :source_folder, env_name: "FL_LIZARD_SOURCE_FOLDER", description: "The folders that contains the source code for lizard to scan", optional: true), FastlaneCore::ConfigItem.new(key: :language, env_name: "FL_LIZARD_LANGUAGE", description: "List the programming languages you want to analyze", default_value: "swift", optional: true), FastlaneCore::ConfigItem.new(key: :export_type, env_name: "FL_LIZARD_EXPORT_TYPE", description: "The file extension of your export. E.g. xml, csv", optional: true), FastlaneCore::ConfigItem.new(key: :ccn, env_name: "FL_LIZARD_CCN", description: "Threshold of cyclomatic complexity number warning", is_string: false, optional: true), FastlaneCore::ConfigItem.new(key: :length, env_name: "FL_LIZARD_LENGTH", description: "Threshold for maximum function length warning", is_string: false, optional: true), FastlaneCore::ConfigItem.new(key: :arguments, env_name: "FL_LIZARD_ARGUMENTS", description: "Limit for number of parameters", optional: true), FastlaneCore::ConfigItem.new(key: :number, env_name: "FL_LIZARD_NUMBER", 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", is_string: false, optional: true), FastlaneCore::ConfigItem.new(key: :exclude, env_name: "FL_LIZARD_EXCLUDE", description: "Exclude files that match this pattern. * matches everything, ? matches any single character, \"./folder/*\" exclude everything in the folder recursively. Multiple patterns can be specified. Don't forget to add \"\" around the pattern", optional: true), FastlaneCore::ConfigItem.new(key: :working_threads, env_name: "FL_LIZARD_WORKING_THREADS", description: "Number of working threads. A bigger number can fully utilize the CPU and faster", optional: true, is_string: false), FastlaneCore::ConfigItem.new(key: :extensions, env_name: "FL_LIZARD_EXTENSIONS", 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", is_string: true, optional: true), FastlaneCore::ConfigItem.new(key: :sorting, env_name: "FL_LIZARD_SORTING", description: "Sort the warning with field. The field can be nloc, cyclomatic_complexity, token_count, parameter_count, etc. Or an customized file", optional: true), FastlaneCore::ConfigItem.new(key: :whitelist, env_name: "FL_LIZARD_WHITELIST", description: "The path and file name to the whitelist file", optional: true), FastlaneCore::ConfigItem.new(key: :report_file, env_name: "FL_LIZARD_REPORT_FILE", description: "The folder/file which lizard output to", optional: true), FastlaneCore::ConfigItem.new(key: :ignore_exit_status, description: "Ignore the exit status of the lizard command, so that serious violations don't fail the build (true/false)", default_value: false, is_string: false, optional: true), FastlaneCore::ConfigItem.new(key: :show_warnings, env_name: "FL_LIZARD_SHOW_WARNINGS", description: "Show lizard warnings on console, on code that is too complex", is_string: false, default_value: false), FastlaneCore::ConfigItem.new(key: :executable, description: "Path to the `lizard.py` executable on your machine", is_string: true, optional: true) ] end |
.description ⇒ Object
64 65 66 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 64 def self.description "Run lizard code cyclomatic complexity analysis." end |
.details ⇒ Object
72 73 74 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 72 def self.details "It counts 1)the nloc (lines of code without comments), 2)CCN (cyclomatic complexity number), 3)token count of functions. 4)parameter count of functions." end |
.forming_command(params) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 23 def self.forming_command(params) command = [] command << 'lizard' unless params[:executable] command << "python #{params[:executable]}" if params[:executable] command << params[:source_folder].to_s if params[:source_folder] command << "-l #{params[:language]}" if params[:language] command << "--#{params[:export_type]}" if params[:export_type] command << "-C #{params[:ccn]}" if params[:ccn] # stands for cyclomatic complexity number command << "-L #{params[:length]}" if params[:length] command << "-a #{params[:arguments]}" if params[:arguments] command << "-i #{params[:number]}" if params[:number] command << "-x #{params[:exclude]}" if params[:exclude] command << "-t #{params[:working_threads]}" if params[:working_threads] command << "-E #{params[:extensions]}" if params[:extensions] command << "-s #{params[:sorting]}" if params[:sorting] command << "-W #{params[:whitelist]}" if params[:whitelist] command << "> #{params[:report_file].shellescape}" if params[:report_file] return command end |
.handle_lizard_error(ignore_exit_status, exit_status) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 44 def self.handle_lizard_error(ignore_exit_status, exit_status) if ignore_exit_status failure_suffix = 'which would normally fail the build.' = 'fastlane will continue because the `ignore_exit_status` option was used! 🙈' else failure_suffix = 'which represents a failure.' = 'If you want fastlane to continue anyway, use the `ignore_exit_status` option. 🙈' end UI.important("") UI.important("Lizard finished with exit code #{exit_status}, #{failure_suffix}") UI.important() UI.important("") UI.user_error!("Lizard finished with errors (exit code: #{exit_status})") unless ignore_exit_status end |
.is_supported?(platform) ⇒ Boolean
153 154 155 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 153 def self.is_supported?(platform) [:ios, :android, :mac].include?(platform) end |
.run(params) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fastlane/plugin/lizard/actions/lizard_action.rb', line 4 def self.run(params) if `which lizard`.to_s.empty? UI.user_error!("You have to install lizard using `[sudo] pip install lizard` or specify the executable path with the `:executable` option.") end command = forming_command(params) if params[:show_warnings] Fastlane::Actions.sh_control_output("lizard #{params[:source_folder]} | sed -n -e '/^$/,$p'", print_command: true, print_command_output: true) end begin Actions.sh(command.join(" "), log: false) rescue StandardError => e puts e handle_lizard_error(params[:ignore_exit_status], $CHILD_STATUS.exitstatus) end end |