Class: Pantograph::Actions::EnsureNoDebugCodeAction
- Inherits:
-
Pantograph::Action
- Object
- Pantograph::Action
- Pantograph::Actions::EnsureNoDebugCodeAction
- Defined in:
- pantograph/lib/pantograph/actions/ensure_no_debug_code.rb
Constant Summary
Constants inherited from Pantograph::Action
Pantograph::Action::AVAILABLE_CATEGORIES, Pantograph::Action::RETURN_TYPES
Documentation collapse
- .authors ⇒ Object
- .available_options ⇒ Object
- .category ⇒ Object
- .description ⇒ Object
- .details ⇒ Object
- .example_code ⇒ Object
- .is_supported?(platform) ⇒ Boolean
- .output ⇒ Object
Class Method Summary collapse
Methods inherited from Pantograph::Action
action_name, author, deprecated_notes, lane_context, method_missing, other_action, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text
Class Method Details
.authors ⇒ Object
118 119 120 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 118 def self. ['KrauseFx'] end |
.available_options ⇒ Object
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 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 64 def self. [ PantographCore::ConfigItem.new( key: :text, env_name: "FL_ENSURE_NO_DEBUG_CODE_TEXT", description: "The text that must not be in the code base" ), PantographCore::ConfigItem.new( key: :path, env_name: "FL_ENSURE_NO_DEBUG_CODE_PATH", description: "The directory containing all the source files", default_value: ".", verify_block: proc do |value| UI.user_error!("Couldn't find the folder at '#{File.absolute_path(value)}'") unless File.directory?(value) end ), PantographCore::ConfigItem.new( key: :extension, env_name: "FL_ENSURE_NO_DEBUG_CODE_EXTENSION", description: "The extension that should be searched for", optional: true, verify_block: proc do |value| value.delete!('.') if value.include?(".") end ), PantographCore::ConfigItem.new( key: :extensions, env_name: "FL_ENSURE_NO_DEBUG_CODE_EXTENSIONS", description: "An array of file extensions that should be searched for", optional: true, is_string: false ), PantographCore::ConfigItem.new( key: :exclude, env_name: "FL_ENSURE_NO_DEBUG_CODE_EXCLUDE", description: "Exclude a certain pattern from the search", optional: true, is_string: true ), PantographCore::ConfigItem.new( key: :exclude_dirs, env_name: "FL_ENSURE_NO_DEBUG_CODE_EXCLUDE_DIRS", description: "An array of dirs that should not be included in the search", optional: true, type: Array, is_string: false ) ] end |
.category ⇒ Object
138 139 140 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 138 def self.category :misc end |
.description ⇒ Object
53 54 55 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 53 def self.description "Ensures the given text is nowhere in the code base" end |
.details ⇒ Object
57 58 59 60 61 62 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 57 def self.details [ "You don't want any debug code to slip into production.", "This can be used to check if there is any debug code still in your codebase or if you have things like `// TO DO` or similar." ].join("\n") end |
.example_code ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 122 def self.example_code [ 'ensure_no_debug_code(text: "// TODO")', 'ensure_no_debug_code(text: "Log.v", extension: "java")', 'ensure_no_debug_code(text: "NSLog", path: "./lib", extension: "m")', 'ensure_no_debug_code(text: "(^#define DEBUG|NSLog)", path: "./lib", extension: "m")', 'ensure_no_debug_code(text: "<<<<<<", extensions: ["m", "swift", "java"])' ] end |
.is_supported?(platform) ⇒ Boolean
142 143 144 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 142 def self.is_supported?(platform) true end |
.output ⇒ Object
114 115 116 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 114 def self.output [] end |
.run(params) ⇒ Object
4 5 6 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 |
# File 'pantograph/lib/pantograph/actions/ensure_no_debug_code.rb', line 4 def self.run(params) command = "grep -RE '#{params[:text]}' '#{File.absolute_path(params[:path])}'" extensions = [] extensions << params[:extension] unless params[:extension].nil? if params[:extensions] params[:extensions].each do |extension| extension.delete!('.') if extension.include?(".") extensions << extension end end if extensions.count > 1 command << " --include=\\*.{#{extensions.join(',')}}" elsif extensions.count > 0 command << " --include=\\*.#{extensions.join(',')}" end command << " --exclude #{params[:exclude]}" if params[:exclude] if params[:exclude_dirs] params[:exclude_dirs].each do |dir| command << " --exclude-dir #{dir.shellescape}" end end return command if Helper.test? UI.important(command) results = `#{command}` # we don't use `sh` as the return code of grep is wrong for some reason # Example Output # ./Pantograph.gemspec: spec.add_development_dependency 'my_word' # ./Gemfile.lock: my_word (0.10.1) found = [] results.split("\n").each do |current_raw| found << current_raw.strip end UI.user_error!("Found debug code '#{params[:text]}': \n\n#{found.join("\n")}") if found.count > 0 UI.("No debug code found in code base 🐛") end |