Skip to content

Commit 68e7f36

Browse files
Merge pull request #865 from newrelic/rubocop-3
Begin linting with Rubocop
2 parents d1f00ab + 7b69542 commit 68e7f36

File tree

682 files changed

+9199
-7717
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

682 files changed

+9199
-7717
lines changed

.rubocop.yml

Lines changed: 1936 additions & 0 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ issues](../../issues?q=is%3Aissue+is%3Aclosed).
6666
### Pull Requests
6767

6868
We can only accept PRs for version v6.12.0 or greater due to open source
69-
licensing restrictions.
69+
licensing restrictions. Please set the merge branch to `dev` unless the issue
70+
states otherwise.
7071

7172
### Code of Conduct
7273

@@ -84,18 +85,29 @@ release from this repo, use the appropriate tag. New Relic usually pushes beta
8485
versions of a release to a working branch before tagging them for General
8586
Availability.
8687

88+
The `main` branch houses the code from the latest release. The `dev` branch
89+
includes unreleased work. Please create all new branches off of `dev`.
90+
8791
## Development Environment Setup
8892

8993
1. Fork and clone the repo locally
9094
- Fork the repository inside GitHub
9195
- `git clone [email protected]:<gh username>/newrelic-ruby-agent.git`
9296
1. Pick a Ruby version
93-
- Use rbenv or rvm to install any version of Ruby between 2.2 up to 3.0.1
97+
- Use rbenv or rvm to install any version of Ruby between 2.2 up to 3.1
9498
1. Install development dependencies
9599
- `bundle install`
96100
1. Check that your env is setup correctly
97101
- `bundle exec rake`
98102

103+
**Optional:** Install [lefthook](https://github.com/evilmartians/lefthook) to
104+
integrate our team's git hooks, such as [rubocop](https://github.com/rubocop/rubocop)
105+
linting into your workflow.
106+
107+
**Note:** These setup instructions will not allow you to run the entire test
108+
suite. Some of our suites require services such as MySQL, Postgres, Redis, and
109+
others to run.
110+
99111
## Testing
100112

101113
The agent includes a suite of unit and functional tests which should be used to

Guardfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
require './test/multiverse/lib/multiverse/bundler_patch'
22

3-
test_folders = Dir.glob("test/new_relic/*").select{|f| File.directory?(f)}
4-
test_folders += Dir.glob("test/new_relic/**/*").select{|f| File.directory?(f)}
3+
test_folders = Dir.glob("test/new_relic/*").select { |f| File.directory?(f) }
4+
test_folders += Dir.glob("test/new_relic/**/*").select { |f| File.directory?(f) }
55

6-
rake_lib_path = Bundler.with_unbundled_env{ `bundle exec gem which rake`.chomp.gsub("lib/rake.rb", "lib") }
7-
ruby_options = %{-w -I"#{rake_lib_path}" "#{rake_lib_path}/rake/rake_test_loader.rb"}
6+
rake_lib_path = Bundler.with_unbundled_env { `bundle exec gem which rake`.chomp.gsub("lib/rake.rb", "lib") }
7+
ruby_options = %(-w -I"#{rake_lib_path}" "#{rake_lib_path}/rake/rake_test_loader.rb")
88

99
guard_options = {
1010
spring: "bundle exec ruby #{ruby_options} ",
11-
test_folders: ['test/new_relic'] + test_folders,
11+
test_folders: ['test/new_relic'] + test_folders,
1212
all_after_pass: false,
1313
all_on_start: false
1414
}
1515

1616
guard :minitest, guard_options do
17-
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
17+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
1818
watch(%r{^test/.+_test\.rb$})
19-
watch(%r{^test/rum/.*}) { "test/new_relic/rack/browser_monitoring_test.rb" }
19+
watch(%r{^test/rum/.*}) { "test/new_relic/rack/browser_monitoring_test.rb" }
2020
watch(%r{^test/fixtures/cross_agent_tests/distributed_tracing/(.+).json}) { |m| "test/new_relic/agent/distributed_tracing/#{m[1]}_cross_agent_test.rb" }
21-
watch('test/test_helper.rb') { "test/new_relic" }
21+
watch('test/test_helper.rb') { "test/new_relic" }
2222
watch('test/agent_helper.rb') { "test/new_relic" }
2323
watch('lib/new_relic/agent/configuration/default_source.rb') { "test/new_relic/agent/configuration/orphan_configuration_test.rb" }
2424
watch(%r{^lib/new_relic/agent/transaction/(.+).rb}) { |m| "test/new_relic/agent/distributed_tracing/#{m[1]}_cross_agent_test.rb" }

Rakefile

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ task :test => ['test:newrelic']
1010

1111
namespace :test do
1212
desc "Run all tests"
13-
task :all => %w{newrelic multiverse}
13+
task :all => %w[newrelic multiverse]
1414

1515
begin
1616
require 'test_bisect'
@@ -27,14 +27,14 @@ namespace :test do
2727
require File.expand_path(File.join(File.dirname(__FILE__), 'test', 'performance', 'lib', 'performance'))
2828
options = {}
2929
options[:suite] = args[:suite] if args[:suite]
30-
options[:name] = args[:name] if args[:name]
30+
options[:name] = args[:name] if args[:name]
3131
Performance::Runner.new(options).run_and_report
3232
end
3333

3434
desc "Run agent within existing mini environments"
3535
task :env, [:env1, :env2, :env3, :env4, :env5, :env6] => [] do |t, args|
3636
require File.expand_path(File.join(File.dirname(__FILE__), 'test', 'environments', 'lib', 'environments', 'runner'))
37-
Environments::Runner.new(args.map{|_,v| v}).run_and_report
37+
Environments::Runner.new(args.map { |_, v| v }).run_and_report
3838
end
3939

4040
Rake::TestTask.new(:intentional_fail) do |t|
@@ -51,11 +51,10 @@ namespace :test do
5151

5252
# Note unit testing task is defined in lib/tasks/tests.rake to facilitate
5353
# running them in a rails application environment.
54-
5554
end
5655

5756
desc 'Record build number and stage'
58-
task :record_build, [ :build_number, :stage ] do |t, args|
57+
task :record_build, [:build_number, :stage] do |t, args|
5958
build_string = args.build_number
6059
build_string << ".#{args.stage}" unless args.stage.nil? || args.stage.empty?
6160

@@ -111,7 +110,7 @@ end
111110

112111
namespace :cross_agent_tests do
113112
cross_agent_tests_upstream_path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'cross_agent_tests'))
114-
cross_agent_tests_local_path = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'fixtures', 'cross_agent_tests'))
113+
cross_agent_tests_local_path = File.expand_path(File.join(File.dirname(__FILE__), 'test', 'fixtures', 'cross_agent_tests'))
115114

116115
# Note: before you pull, make sure your local repo is on the correct, synced branch!
117116
desc 'Pull latest changes from cross_agent_tests repo'
@@ -137,4 +136,3 @@ task :console do
137136
ARGV.clear
138137
Pry.start
139138
end
140-

bin/mongrel_rpm

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ require 'rack/handler/mongrel'
55
require 'optparse'
66

77
port = 3000
8-
options = { }
8+
options = {}
99
appname = nil
1010
OptionParser.new do |opts|
1111
opts.banner = "Usage: #{File.basename($0)} [options] [app_name]"
12-
opts.on("-p", "--port=port", Integer, "default: #{port}") { | port | }
13-
opts.on("--[no-]logging", "turn off request logging" ) { | l | options[:logging] = l }
14-
opts.on("--license=license_key", "override license key" ) { | l | options[:license_key] = l }
15-
opts.on("--install", "install a newrelic.yml template" ) { | l | options[:install] = true }
12+
opts.on("-p", "--port=port", Integer, "default: #{port}") { |port| }
13+
opts.on("--[no-]logging", "turn off request logging") { |l| options[:logging] = l }
14+
opts.on("--license=license_key", "override license key") { |l| options[:license_key] = l }
15+
opts.on("--install", "install a newrelic.yml template") { |l| options[:install] = true }
1616
opts.separator ""
1717
opts.separator "app_name is the name of the application where the metrics will be stored"
1818
opts.separator ""
@@ -26,8 +26,7 @@ ru_file = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "new_r
2626
rackup_code = File.read ru_file
2727
builder = Rack::Builder.new { eval rackup_code, binding, ru_file }
2828

29-
options = { :Host => '127.0.0.1', :Port => port }
30-
Rack::Handler::Mongrel.run(builder.to_app, options) do | server |
31-
NewRelic::Agent.logger.info "Started Mongrel listening for '#{NewRelic::Control.instance.app_names.join(" and ")}' data at #{server.host}:#{server.port}"
29+
options = {:Host => '127.0.0.1', :Port => port}
30+
Rack::Handler::Mongrel.run(builder.to_app, options) do |server|
31+
NewRelic::Agent.logger.info "Started Mongrel listening for '#{NewRelic::Control.instance.app_names.join(" and ")}' data at #{server.host}:#{server.port}"
3232
end
33-

bin/newrelic

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# executes one of the commands in the new_relic/commands directory
33
# pass the name of the command as an argument
44

5-
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..','lib'))
5+
$LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
66
require 'new_relic/cli/command'
77
begin
88
NewRelic::Cli::Command.run

bin/nrdebug

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
require 'tempfile'
88
require 'rbconfig'
99

10-
def fail(msg, opts={})
10+
def fail(msg, opts = {})
1111
$stderr.puts(msg)
1212
usage() if opts[:usage]
1313
exit(-1)
@@ -84,7 +84,7 @@ class ProcessDataProvider
8484

8585
def self.for_process(pid)
8686
case RbConfig::CONFIG['target_os']
87-
when /linux/ then LinuxProcessDataProvider.new(pid)
87+
when /linux/ then LinuxProcessDataProvider.new(pid)
8888
when /darwin/ then DarwinProcessDataProvider.new(pid)
8989
end
9090
end
@@ -170,7 +170,7 @@ end
170170
class ProcessReport
171171
attr_reader :target, :path
172172

173-
def initialize(target, path=nil)
173+
def initialize(target, path = nil)
174174
@target = target
175175
@path = path
176176
end
@@ -185,7 +185,7 @@ class ProcessReport
185185
end
186186
end
187187

188-
def section(f, name=nil)
188+
def section(f, name = nil)
189189
content = begin
190190
yield
191191
rescue StandardError => e
@@ -200,27 +200,27 @@ class ProcessReport
200200

201201
def generate
202202
open do |f|
203-
section(f, "Time") { Time.now }
204-
section(f, "PID") { @target.pid }
205-
section(f, "Command") { @target.procline }
206-
section(f, "RSS") { @target.rss }
207-
section(f, "CPU") { @target.cpu }
208-
section(f, "Parent PID") { @target.ppid }
209-
section(f, "OS") { ShellWrapper.execute('uname -a') }
203+
section(f, "Time") { Time.now }
204+
section(f, "PID") { @target.pid }
205+
section(f, "Command") { @target.procline }
206+
section(f, "RSS") { @target.rss }
207+
section(f, "CPU") { @target.cpu }
208+
section(f, "Parent PID") { @target.ppid }
209+
section(f, "OS") { ShellWrapper.execute('uname -a') }
210210
section(f, "Environment") { @target.environment }
211211

212212
section(f) do
213213
c_backtraces, ruby_backtraces = @target.gather_backtraces
214214
if c_backtraces.match(/could not attach/i)
215215
fail("Failed to attach to target process. Please try again with sudo.")
216216
end
217-
section(f, "C Backtraces") { c_backtraces }
217+
section(f, "C Backtraces") { c_backtraces }
218218
section(f, "Ruby Backtrace(s)") { ruby_backtraces }
219219
end
220220

221221
section(f, "Open files") { @target.open_files }
222222
section(f, "Log") do
223-
commands = Logger.messages.map { |(_,msg)| msg }
223+
commands = Logger.messages.map { |(_, msg)| msg }
224224
commands.join("\n")
225225
end
226226
end
@@ -243,7 +243,7 @@ def prompt_for_confirmation(target_pid, target_cmd)
243243
puts ''
244244
puts "To continue, type 'continue':"
245245

246-
until ($stdin.gets.strip == 'continue') do
246+
until $stdin.gets.strip == 'continue'
247247
puts "Please type 'continue' to continue, or ctrl-c to abort."
248248
end
249249
end

infinite_tracing/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ Rake::TestTask.new do |t|
2020
t.libs << "#{ROOT}/test"
2121
t.libs << "#{ROOT}/lib"
2222
t.pattern = Array(file_pattern).join(",")
23-
t.verbose = ENV["VERBOSE"]
23+
t.verbose = ENV["VERBOSE"]
2424
end

infinite_tracing/lib/infinite_tracing.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737

3838
require 'infinite_tracing/agent_integrations'
3939
end
40-
end
40+
end

infinite_tracing/lib/infinite_tracing/agent_integrations.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ module InfiniteTracing
1717
NewRelic::Agent.logger.debug "Skipped Integrating Infinite Tracer with Agent"
1818
end
1919
end
20-
end
20+
end

0 commit comments

Comments
 (0)