lib/paraxial/cli.rb in paraxial-0.5.0 vs lib/paraxial/cli.rb in paraxial-0.6.0
- old
+ new
@@ -16,11 +16,20 @@
option :repo_name, type: :string, desc: 'Repository name'
option :pr_number, type: :numeric, desc: 'Pull request number'
def scan
puts '[Paraxial] Scan starting...'
+ if check_rubocop_configuration
+ puts '[Paraxial] .rubocop.yml is valid.'
+ else
+ puts '[Paraxial] .rubocop.yml is missing rubocop-erb. To scan embedded Ruby files for security problems, add:'
+ puts '.rubocop.yml'
+ puts 'require:'
+ puts '- rubocop-erb'
+ end
+
if Paraxial::Helpers.get_api_key.nil?
puts '[Paraxial] Environment variable PARAXIAL_API_KEY not found'
else
github_app = options[:github_app]
install_id = options[:install_id]
@@ -38,11 +47,11 @@
body = { rubocop: rubocop, lockfile: lockfile, api_key: api_key, timestamp: Paraxial.get_timestamp }
response = Net::HTTP.post(uri, body.to_json, headers)
m = JSON.parse(response.body)
findings = m['ok']['findings']
puts
- puts "[Paraxial] Scan count #{findings.length}"
+ puts "[Paraxial] Scan count: #{findings.length}"
puts
findings.each do |finding|
puts finding
puts
end
@@ -87,7 +96,23 @@
:ok
end
end
end
+ private
+
+ def check_rubocop_configuration
+ rubocop_file = File.join(Dir.pwd, '.rubocop.yml')
+
+ return false unless File.exist?(rubocop_file)
+
+ config = YAML.load_file(rubocop_file)
+ required_key = 'require'
+
+ if config.is_a?(Hash) && config[required_key].is_a?(Array)
+ config[required_key].include?('rubocop-erb')
+ else
+ false
+ end
+ end
end
end