Skip to content

Commit f9faa85

Browse files
Merge pull request #24 from rubyatscale/standardrb
Use standardrb for linting
2 parents 283e1b1 + 1bf1343 commit f9faa85

File tree

16 files changed

+191
-135
lines changed

16 files changed

+191
-135
lines changed

.github/workflows/standardrb.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: StandardRB
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- name: StandardRB Linter
11+
uses: standardrb/[email protected]
12+
env:
13+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.standard.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fix: true
2+
format: progress

Gemfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# frozen_string_literal: true
22

3-
source 'https://rubygems.org'
3+
source "https://rubygems.org"
44

55
# Specify your gem's dependencies in singed.gemspec
66
gemspec
77

8-
gem 'rake', '~> 13.0'
8+
gem "rake", "~> 13.0"
9+
gem "standard"

Gemfile.lock

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
PATH
22
remote: .
33
specs:
4-
singed (0.2.1)
4+
singed (0.2.2)
55
colorize
66
stackprof (>= 0.2.13)
77

88
GEM
99
remote: https://rubygems.org/
1010
specs:
11+
ast (2.4.2)
1112
colorize (0.8.1)
1213
diff-lcs (1.5.0)
14+
json (2.7.2)
15+
language_server-protocol (3.17.0.3)
16+
lint_roller (1.1.0)
17+
parallel (1.24.0)
18+
parser (3.3.1.0)
19+
ast (~> 2.4.1)
20+
racc
21+
racc (1.7.3)
22+
rainbow (3.1.1)
1323
rake (13.0.6)
24+
regexp_parser (2.9.0)
25+
rexml (3.2.6)
1426
rspec (3.12.0)
1527
rspec-core (~> 3.12.0)
1628
rspec-expectations (~> 3.12.0)
@@ -24,7 +36,37 @@ GEM
2436
diff-lcs (>= 1.2.0, < 2.0)
2537
rspec-support (~> 3.12.0)
2638
rspec-support (3.12.0)
39+
rubocop (1.62.1)
40+
json (~> 2.3)
41+
language_server-protocol (>= 3.17.0)
42+
parallel (~> 1.10)
43+
parser (>= 3.3.0.2)
44+
rainbow (>= 2.2.2, < 4.0)
45+
regexp_parser (>= 1.8, < 3.0)
46+
rexml (>= 3.2.5, < 4.0)
47+
rubocop-ast (>= 1.31.1, < 2.0)
48+
ruby-progressbar (~> 1.7)
49+
unicode-display_width (>= 2.4.0, < 3.0)
50+
rubocop-ast (1.31.3)
51+
parser (>= 3.3.1.0)
52+
rubocop-performance (1.20.2)
53+
rubocop (>= 1.48.1, < 2.0)
54+
rubocop-ast (>= 1.30.0, < 2.0)
55+
ruby-progressbar (1.13.0)
2756
stackprof (0.2.17)
57+
standard (1.35.1)
58+
language_server-protocol (~> 3.17.0.2)
59+
lint_roller (~> 1.0)
60+
rubocop (~> 1.62.0)
61+
standard-custom (~> 1.0.0)
62+
standard-performance (~> 1.3)
63+
standard-custom (1.0.2)
64+
lint_roller (~> 1.0)
65+
rubocop (~> 1.50)
66+
standard-performance (1.3.1)
67+
lint_roller (~> 1.1)
68+
rubocop-performance (~> 1.20.2)
69+
unicode-display_width (2.5.0)
2870

2971
PLATFORMS
3072
ruby
@@ -33,6 +75,7 @@ DEPENDENCIES
3375
rake (~> 13.0)
3476
rspec
3577
singed!
78+
standard
3679

3780
BUNDLED WITH
3881
2.4.4

Rakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# frozen_string_literal: true
22

3-
require 'bundler/gem_tasks'
4-
task default: %i()
3+
require "bundler/gem_tasks"
4+
task default: %i[]

exe/singed

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#!/usr/bin/env ruby
22

3-
4-
require 'singed/cli'
3+
require "singed/cli"
54
if Singed::CLI.chdir_rails_root
6-
require './config/environment'
5+
require "./config/environment"
76
end
87

98
Singed::CLI.new(ARGV).run

lib/singed.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# frozen_string_literal: true
22

3-
require 'json'
4-
require 'stackprof'
5-
require 'colorize'
3+
require "json"
4+
require "stackprof"
5+
require "colorize"
66

77
module Singed
88
extend self
@@ -46,11 +46,11 @@ def filter_line(line)
4646
line
4747
end
4848

49-
autoload :Flamegraph, 'singed/flamegraph'
50-
autoload :Report, 'singed/report'
51-
autoload :RackMiddleware, 'singed/rack_middleware'
49+
autoload :Flamegraph, "singed/flamegraph"
50+
autoload :Report, "singed/report"
51+
autoload :RackMiddleware, "singed/rack_middleware"
5252
end
5353

54-
require 'singed/kernel_ext'
55-
require 'singed/railtie' if defined?(Rails::Railtie)
56-
require 'singed/rspec' if defined?(RSpec) && RSpec.respond_to?(:configure)
54+
require "singed/kernel_ext"
55+
require "singed/railtie" if defined?(Rails::Railtie)
56+
require "singed/rspec" if defined?(RSpec) && RSpec.respond_to?(:configure)

lib/singed/cli.rb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
require 'shellwords'
2-
require 'tmpdir'
3-
require 'optionparser'
4-
require 'pathname'
1+
require "shellwords"
2+
require "tmpdir"
3+
require "optionparser"
4+
require "pathname"
55

66
# NOTE: we defer requiring singed until we run. that lets Rails load it if its in the gemfile, so the railtie has had a chance to run
77

@@ -17,24 +17,24 @@ def initialize(argv)
1717
end
1818

1919
def parse_argv!
20-
opts.banner = 'Usage: singed [options] <command>'
20+
opts.banner = "Usage: singed [options] <command>"
2121

22-
opts.on('-h', '--help', 'Show this message') do
22+
opts.on("-h", "--help", "Show this message") do
2323
@show_help = true
2424
end
2525

26-
opts.on('-o', '--output-directory DIRECTORY', 'Directory to write flamegraph to') do |directory|
26+
opts.on("-o", "--output-directory DIRECTORY", "Directory to write flamegraph to") do |directory|
2727
@output_directory = directory
2828
end
2929

3030
opts.order(@argv) do |arg|
31-
opts.terminate if arg == '--'
31+
opts.terminate if arg == "--"
3232
break
3333
end
3434

3535
if @argv.empty?
3636
@show_help = true
37-
@error_message = 'missing command to profile'
37+
@error_message = "missing command to profile"
3838
return
3939
end
4040

@@ -49,7 +49,7 @@ def parse_argv!
4949
end
5050

5151
def run
52-
require 'singed'
52+
require "singed"
5353

5454
if @error_message
5555
puts @error_message
@@ -66,31 +66,31 @@ def run
6666
Singed.output_directory = @output_directory if @output_directory
6767
Singed.output_directory ||= Dir.tmpdir
6868
FileUtils.mkdir_p Singed.output_directory
69-
@filename = Singed::Flamegraph.generate_filename(label: 'cli')
69+
@filename = Singed::Flamegraph.generate_filename(label: "cli")
7070

7171
options = {
72-
format: 'speedscope',
72+
format: "speedscope",
7373
file: filename.to_s,
74-
silent: nil,
74+
silent: nil
7575
}
7676

7777
rbspy_args = [
78-
'record',
78+
"record",
7979
*options.map { |k, v| ["--#{k}", v].compact }.flatten,
80-
'--',
81-
*argv,
80+
"--",
81+
*argv
8282
]
8383

8484
loop do
8585
break unless password_needed?
8686

87-
puts '🔥📈 Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now...'
87+
puts "🔥📈 Singed needs to run as root, but will drop permissions back to your user. Prompting with sudo now..."
8888
prompt_password
8989
end
9090

9191
rbspy = lambda do
9292
# don't run things with spring, because it forks and rbspy won't see it
93-
sudo ['rbspy', *rbspy_args], reason: 'Singed needs to run as root, but will drop permissions back to your user.', env: { 'DISABLE_SPRING' => '1' }
93+
sudo ["rbspy", *rbspy_args], reason: "Singed needs to run as root, but will drop permissions back to your user.", env: {"DISABLE_SPRING" => "1"}
9494
end
9595

9696
if defined?(Bundler)
@@ -113,8 +113,8 @@ def run
113113

114114
# clean the report, similar to how Singed::Report does
115115
json = JSON.parse(filename.read)
116-
json['shared']['frames'].each do |frame|
117-
frame['file'] = Singed.filter_line(frame['file'])
116+
json["shared"]["frames"].each do |frame|
117+
frame["file"] = Singed.filter_line(frame["file"])
118118
end
119119
filename.write(JSON.dump(json))
120120

@@ -123,15 +123,15 @@ def run
123123
end
124124

125125
def password_needed?
126-
!system('sudo --non-interactive true >/dev/null 2>&1')
126+
!system("sudo --non-interactive true >/dev/null 2>&1")
127127
end
128128

129129
def prompt_password
130-
system('sudo true')
130+
system("sudo true")
131131
end
132132

133133
def adjust_ownership!
134-
sudo ['chown', ENV['USER'], filename], reason: "Adjusting ownership of #{filename}, but need root."
134+
sudo ["chown", ENV["USER"], filename], reason: "Adjusting ownership of #{filename}, but need root."
135135
end
136136

137137
def show_help?
@@ -147,9 +147,9 @@ def sudo(system_args, reason:, env: {})
147147
end
148148

149149
sudo_args = [
150-
'sudo',
151-
'--preserve-env',
152-
*system_args.map(&:to_s),
150+
"sudo",
151+
"--preserve-env",
152+
*system_args.map(&:to_s)
153153
]
154154

155155
puts "$ #{Shellwords.join(sudo_args)}"
@@ -161,7 +161,7 @@ def self.chdir_rails_root
161161
original_cwd = Dir.pwd
162162

163163
loop do
164-
if File.file?('config/environment.rb')
164+
if File.file?("config/environment.rb")
165165
return Dir.pwd
166166
end
167167

@@ -171,7 +171,7 @@ def self.chdir_rails_root
171171
end
172172

173173
# Otherwise keep moving upwards in search of an executable.
174-
Dir.chdir('..')
174+
Dir.chdir("..")
175175
end
176176
end
177177
end

lib/singed/flamegraph.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def initialize(label: nil, ignore_gc: false, interval: 1000, filename: nil)
66
# it's been created elsewhere, ie rbspy
77
if filename
88
if ignore_gc
9-
raise ArgumentError, 'ignore_gc not supported when given an existing file'
9+
raise ArgumentError, "ignore_gc not supported when given an existing file"
1010
end
1111

1212
if label
13-
raise ArgumentError, 'label not supported when given an existing file'
13+
raise ArgumentError, "label not supported when given an existing file"
1414
end
1515

1616
@filename = filename
@@ -41,7 +41,7 @@ def save
4141
report = Singed::Report.new(@profile)
4242
report.filter!
4343
filename.dirname.mkpath
44-
filename.open('w') { |f| report.print_json(f) }
44+
filename.open("w") { |f| report.print_json(f) }
4545
end
4646

4747
def open
@@ -53,10 +53,10 @@ def open_command
5353
end
5454

5555
def self.generate_filename(label: nil, time: Time.now) # rubocop:disable Rails/TimeZone
56-
formatted_time = time.strftime('%Y%m%d%H%M%S-%6N')
57-
basename_parts = ['speedscope', label, formatted_time].compact
56+
formatted_time = time.strftime("%Y%m%d%H%M%S-%6N")
57+
basename_parts = ["speedscope", label, formatted_time].compact
5858

59-
file = Singed.output_directory.join("#{basename_parts.join('-')}.json")
59+
file = Singed.output_directory.join("#{basename_parts.join("-")}.json")
6060
# convert to relative directory if it's an absolute path and within the current
6161
pwd = Pathname.pwd
6262
file = file.relative_path_from(pwd) if file.absolute? && file.to_s.start_with?(pwd.to_s)

lib/singed/kernel_ext.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
module Kernel
2-
def flamegraph(label = nil, open: true, ignore_gc: false, interval: 1000, io: $stdout, &block)
2+
def flamegraph(label = nil, open: true, ignore_gc: false, interval: 1000, io: $stdout, &)
33
fg = Singed::Flamegraph.new(label: label, ignore_gc: ignore_gc, interval: interval)
4-
result = fg.record(&block)
4+
result = fg.record(&)
55
fg.save
66

77
if open
88
# use npx, so we don't have to add it as a dependency
9-
io.puts "🔥📈 #{'Captured flamegraph, opening with'.colorize(:bold).colorize(:red)}: #{fg.open_command}"
9+
io.puts "🔥📈 #{"Captured flamegraph, opening with".colorize(:bold).colorize(:red)}: #{fg.open_command}"
1010
fg.open
1111
else
12-
io.puts "🔥📈 #{'Captured flamegraph to file'.colorize(:bold).colorize(:red)}: #{fg.filename}"
12+
io.puts "🔥📈 #{"Captured flamegraph to file".colorize(:bold).colorize(:red)}: #{fg.filename}"
1313
end
1414

1515
result

0 commit comments

Comments
 (0)