Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
f611a18
Add rubocop with a todo list
samsonjs Jun 28, 2025
2967344
Run rubocop as part of the CI workflow
samsonjs Jun 28, 2025
69f5e39
Autofix for RuboCop: Layout/ElseAlignment
pieterocp Jun 30, 2025
672a086
Regen autogen, removing all claude-scratchpad/*
pieterocp Jun 30, 2025
b4daa9b
Autofix RuboCop Layout/EmptyLine
pieterocp Jun 30, 2025
86f2485
AutoFix RuboCop Style/ZeroLengthPredicate
pieterocp Jun 30, 2025
223c84c
AutoFix RuboCop Layout/EmptyLinesAroundAccessModifier
pieterocp Jun 30, 2025
fc2add8
AutoFix RuboCop Layout/EmptyLinesAroundMethodBody
pieterocp Jun 30, 2025
aa596b8
AutoFix RuboCop Layout/EmptyLinesAroundBlockBody
pieterocp Jun 30, 2025
cf62a24
AutoFix RuboCop Layout/EmptyLinesAroundClassBody
pieterocp Jun 30, 2025
4cdf5f3
AutoFix RuboCop Layout/EndAlignment
pieterocp Jun 30, 2025
b683365
AutoFix RuboCop Layout/ExtraSpacing
pieterocp Jun 30, 2025
c9dfc20
AutoFix RuboCop Layout/FirstHashElementIndentation
pieterocp Jun 30, 2025
ea6126d
AutoFix RuboCop Layout/HashAlignment
pieterocp Jun 30, 2025
fc7ae90
AutoFix RuboCop Layout/IndentationWidth
pieterocp Jun 30, 2025
1b9aedf
Regenerate todo
pieterocp Jun 30, 2025
f5a1cdb
AutoFix RuboCop Layout/SpaceBeforeBlockBraces
pieterocp Jun 30, 2025
0ac8504
AutoFix RuboCop Layout/SpaceBeforeComma
pieterocp Jun 30, 2025
8b1f794
AutoFix RuboCop Layout/SpaceInsideBlockBraces
pieterocp Jun 30, 2025
433ace3
AutoFix RuboCop Layout/SpaceInsideHashLiteralBraces
pieterocp Jun 30, 2025
abcef47
AutoFix RuboCop Layout/TrailingEmptyLines
pieterocp Jun 30, 2025
d4bce13
Update ci.yml
samsonjs Jun 30, 2025
df63cfe
WIP: Remove claude-scratchpad cruft from rubocop todo
samsonjs Jun 30, 2025
d51a1db
Specify files explicity in rubocop rake task
samsonjs Jun 30, 2025
8dfd1e8
Pin rubocop version to 1.77.0
samsonjs Jun 30, 2025
78f7ba0
AutoFix RuboCop Style/TrailingCommaInHashLiteral
pieterocp Jul 8, 2025
9e33e1f
AutoFix RuboCop Style/StringLiteralsInInterpolation
pieterocp Jul 8, 2025
5eea5ab
AutoFix RuboCop Style/StringLiterals
pieterocp Jul 8, 2025
5e78a32
AutoFix RuboCop Style/RescueStandardError
pieterocp Jul 8, 2025
e6af1da
AutoFix RuboCop Style/RedundantPercentQ
pieterocp Jul 8, 2025
3a71be7
AutoFix RuboCop Style/RedundantConstantBase
pieterocp Jul 8, 2025
6f0ffc2
AutoFix RuboCop Style/QuotedSymbols
pieterocp Jul 8, 2025
481a6f6
AutoFix RuboCop Style/PercentLiteralDelimiters
pieterocp Jul 8, 2025
c1fa224
AutoFix RuboCop Style/ParallelAssignment
pieterocp Jul 8, 2025
a95640b
AutoFix RuboCop Style/MultilineIfModifier
pieterocp Jul 8, 2025
65aa464
AutoFix RuboCop Style/Lambda
pieterocp Jul 8, 2025
4ca251f
AutoFix RuboCop Style/IfUnlessModifier
pieterocp Jul 8, 2025
f6ae186
AutoFix RuboCop Style/HashSyntax
pieterocp Jul 8, 2025
b8d0831
AutoFix RuboCop Style/GuardClause
pieterocp Jul 8, 2025
086281a
AutoFix RuboCop Style/ExpandPathArguments
pieterocp Jul 8, 2025
f3552bc
AutoFix RuboCop Style/BlockDelimiters
pieterocp Jul 8, 2025
93b41a6
AutoFix RuboCop Style/BlockComments
pieterocp Jul 8, 2025
e5b6b00
AutoFix RuboCop Lint/UnusedMethodArgument
pieterocp Jul 8, 2025
f3ce256
AutoFix RuboCop Lint/SymbolConversion
pieterocp Jul 8, 2025
c9865f3
Merge branch 'master' into add-rubocop
samsonjs Jul 10, 2025
ba45a7d
Merge branch 'add-rubocop' into add-all-todos
pieterocp Jul 10, 2025
b338298
Fix auto-gen formatting + RuboCop AutoFix Style/ModuleFunction
pieterocp Jul 10, 2025
68fbe40
Merge pull request #1 from pieterocp/add-all-todos
samsonjs Jul 14, 2025
e113998
Code style
samsonjs Jul 14, 2025
0b857fb
Merge branch 'master' into add-rubocop
samsonjs Jul 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,17 @@ jobs:
- name: Install dependencies
run: bundle install
- name: Run tests
run: bundle exec rspec spec/
run: bundle exec rake spec
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- uses: ruby/setup-ruby@v1
with:
ruby-version: "3.4"
bundler-cache: true
- name: Install dependencies
run: bundle install
- name: Run RuboCop
run: bundle exec rake rubocop
14 changes: 14 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
inherit_from: .rubocop_todo.yml

AllCops:
NewCops: enable

Metrics/BlockLength:
CountAsOne: [array, hash, heredoc, method_call]

Metrics/ClassLength:
CountAsOne: [array, hash, heredoc, method_call]

Metrics/MethodLength:
CountAsOne: [array, hash, heredoc, method_call]
Max: 20
160 changes: 160 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2025-07-10 10:25:51 UTC using RuboCop version 1.77.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
# SupportedStyles: Gemfile, gems.rb, gemspec
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
Gemspec/DevelopmentDependencies:
Exclude:
- "grape_logging.gemspec"

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequireMFA:
Exclude:
- "grape_logging.gemspec"

# Offense count: 1
# Configuration parameters: Severity, Include.
# Include: **/*.gemspec
Gemspec/RequiredRubyVersion:
Exclude:
- "grape_logging.gemspec"

# Offense count: 1
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
Lint/DuplicateBranch:
Exclude:
- "lib/grape_logging/util/parameter_filter.rb"

# Offense count: 1
# Configuration parameters: AllowedParentClasses.
Lint/MissingSuper:
Exclude:
- "lib/grape_logging/loggers/filter_parameters.rb"

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 38

# Offense count: 8
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
# AllowedMethods: refine
Metrics/BlockLength:
Max: 90

# Offense count: 3
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 18

# Offense count: 2
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/PerceivedComplexity:
Max: 19

# Offense count: 2
# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns.
# SupportedStyles: snake_case, normalcase, non_integer
# AllowedIdentifiers: TLS1_1, TLS1_2, capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64
Naming/VariableNumber:
Exclude:
- "spec/lib/grape_logging/formatters/rails_spec.rb"

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: MinBranchesCount.
Style/CaseLikeIf:
Exclude:
- "lib/grape_logging/formatters/default.rb"
- "lib/grape_logging/formatters/logstash.rb"
- "lib/grape_logging/formatters/rails.rb"

# Offense count: 17
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false

# Offense count: 29
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Enabled: false

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/GlobalStdStream:
Exclude:
- "lib/grape_logging/reporters/logger_reporter.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: literals, strict
Style/MutableConstant:
Exclude:
- "lib/grape_logging/version.rb"

# Offense count: 10
Style/OpenStructUse:
Exclude:
- "spec/lib/grape_logging/loggers/client_env_spec.rb"
- "spec/lib/grape_logging/loggers/filter_parameters_spec.rb"
- "spec/lib/grape_logging/loggers/request_headers_spec.rb"
- "spec/lib/grape_logging/loggers/response_spec.rb"

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
# AllowedMethods: present?, blank?, presence, try, try!
Style/SafeNavigation:
Exclude:
- "lib/grape_logging/formatters/rails.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
Style/SlicingWithRange:
Exclude:
- "lib/grape_logging/loggers/request_headers.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: RequireEnglish, EnforcedStyle.
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
Style/SpecialGlobalVars:
Exclude:
- "spec/spec_helper.rb"

# Offense count: 3
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- "lib/grape_logging/formatters/json.rb"
- "lib/grape_logging/formatters/lograge.rb"
- "lib/grape_logging/formatters/logstash.rb"

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowMethodsWithArguments, AllowedMethods, AllowedPatterns, AllowComments.
# AllowedMethods: define_method
Style/SymbolProc:
Exclude:
- "lib/grape_logging/util/parameter_filter.rb"

# Offense count: 11
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, IgnoreCopDirectives, AllowedPatterns, SplitStrings.
# URISchemes: http, https
Layout/LineLength:
Max: 203
22 changes: 15 additions & 7 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'

RSpec::Core::RakeTask.new(:spec)
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.rspec_opts = ['-fd -c']
spec.pattern = FileList['spec/**/*_spec.rb']
end

RuboCop::RakeTask.new(:rubocop) do |t|
t.patterns = ['lib/**/*.rb', 'spec/**/*.rb', 'Rakefile', 'Gemfile', 'grape_logging.gemspec']
end

task default: :spec
task default: %i[spec rubocop]

desc 'Release gem and create GitHub release'
task github_release: :release do
Expand All @@ -14,9 +22,9 @@ task github_release: :release do
# Check if gh CLI is available
unless system('which gh > /dev/null 2>&1')
puts "\n⚠️ GitHub CLI (gh) not found"
puts "To create a GitHub release with auto-generated changelog, install gh:"
puts " brew install gh # macOS with Homebrew"
puts " # or visit: https://github.com/cli/cli#installation"
puts 'To create a GitHub release with auto-generated changelog, install gh:'
puts ' brew install gh # macOS with Homebrew'
puts ' # or visit: https://github.com/cli/cli#installation'
puts "\nYou can manually create the release with:"
puts " gh release create v#{GrapeLogging::VERSION} --generate-notes"
next
Expand All @@ -28,8 +36,8 @@ task github_release: :release do
if system('gh', 'release', 'create', version, '--generate-notes', '--verify-tag')
puts "✅ GitHub release #{version} created successfully"
else
puts "❌ Failed to create GitHub release"
puts "You can manually create it with:"
puts '❌ Failed to create GitHub release'
puts 'You can manually create it with:'
puts " gh release create '#{version}' --generate-notes --verify-tag"
end
end
8 changes: 6 additions & 2 deletions grape_logging.gemspec
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'grape_logging/version'

Expand All @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'

spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

Expand All @@ -25,4 +25,8 @@ Gem::Specification.new do |spec|

spec.add_development_dependency 'rake', '~> 13.3'
spec.add_development_dependency 'rspec', '~> 3.5'

# This is pinned to an exact version otherwise we can't know which rules
# are in play at any given time in different environments.
spec.add_development_dependency 'rubocop', '1.77.0'
end
1 change: 1 addition & 0 deletions lib/grape_logging/formatters/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def format(data)
end

private

def format_hash(hash)
hash.keys.sort.map { |key| "#{key}=#{hash[key]}" }.join(' ')
end
Expand Down
6 changes: 3 additions & 3 deletions lib/grape_logging/formatters/logstash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Formatters
class Logstash
def call(severity, datetime, _, data)
{
:'@timestamp' => datetime.iso8601,
:'@version' => '1',
:severity => severity
'@timestamp': datetime.iso8601,
'@version': '1',
severity: severity
}.merge!(format(data)).to_json + "\n"
end

Expand Down
8 changes: 3 additions & 5 deletions lib/grape_logging/formatters/rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module GrapeLogging
module Formatters
class Rails

def call(severity, datetime, _, data)
if data.is_a?(String)
"#{severity[0..0]} [#{datetime}] #{severity} -- : #{data}\n"
Expand All @@ -24,15 +23,15 @@ def format_exception(exception)
[
"#{exception.message} (#{exception.class})",
backtrace_array.join("\n")
].reject{|line| line == ""}.join("\n")
].reject { |line| line == '' }.join("\n")
end

def format_hash(hash)
# Create Rails' single summary line at the end of every request, formatted like:
# Completed 200 OK in 958ms (Views: 951.1ms | ActiveRecord: 3.8ms)
# See: actionpack/lib/action_controller/log_subscriber.rb

message = ""
message = ''
additions = []
status = hash.delete(:status)
params = hash.delete(:params)
Expand All @@ -47,13 +46,12 @@ def format_hash(hash)
message << " Parameters: #{params.inspect}\n" if params

message << "Completed #{status} #{::Rack::Utils::HTTP_STATUS_CODES[status]} in #{total_time}ms"
message << " (#{additions.join(" | ".freeze)})" if additions.size > 0
message << " (#{additions.join(' | '.freeze)})" unless additions.empty?
message << "\n"
message << "\n" if defined?(::Rails.env) && ::Rails.env.development?

message
end

end
end
end
2 changes: 1 addition & 1 deletion lib/grape_logging/loggers/base.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module GrapeLogging
module Loggers
class Base
def parameters(request, response)
def parameters(_request, _response)
{}
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/grape_logging/loggers/client_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module GrapeLogging
module Loggers
class ClientEnv < GrapeLogging::Loggers::Base
def parameters(request, _)
{ ip: request.env["HTTP_X_FORWARDED_FOR"] || request.env["REMOTE_ADDR"], ua: request.env["HTTP_USER_AGENT"] }
{ ip: request.env['HTTP_X_FORWARDED_FOR'] || request.env['REMOTE_ADDR'], ua: request.env['HTTP_USER_AGENT'] }
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/grape_logging/loggers/filter_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module Loggers
class FilterParameters < GrapeLogging::Loggers::Base
AD_PARAMS = 'action_dispatch.request.parameters'.freeze

def initialize(filter_parameters = nil, replacement = nil, exceptions = %w(controller action format))
def initialize(filter_parameters = nil, replacement = nil, exceptions = %w[controller action format])
@filter_parameters = filter_parameters || (defined?(::Rails.application) ? ::Rails.application.config.filter_parameters : [])
@replacement = replacement || '[FILTERED]'
@exceptions = exceptions
Expand All @@ -30,8 +30,8 @@ def safe_parameters(request)

def clean_parameters(parameters)
original_encoding_map = build_encoding_map(parameters)
params = transform_key_encoding(parameters, Hash.new{ |h, _| [Encoding::ASCII_8BIT, h] })
cleaned_params = parameter_filter.filter(params).reject{ |key, _value| @exceptions.include?(key) }
params = transform_key_encoding(parameters, Hash.new { |h, _| [Encoding::ASCII_8BIT, h] })
cleaned_params = parameter_filter.filter(params).reject { |key, _value| @exceptions.include?(key) }
transform_key_encoding(cleaned_params, original_encoding_map)
end

Expand Down
2 changes: 0 additions & 2 deletions lib/grape_logging/loggers/request_headers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module GrapeLogging
module Loggers
class RequestHeaders < GrapeLogging::Loggers::Base

HTTP_PREFIX = 'HTTP_'.freeze

def parameters(request, _)
Expand All @@ -16,7 +15,6 @@ def parameters(request, _)

{ headers: headers }
end

end
end
end
5 changes: 2 additions & 3 deletions lib/grape_logging/loggers/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ def parameters(_, response)
# For example, if you POST on a PUT endpoint, response.body is egal to """".
# It's strange, but it's the Grape behavior...
def serialized_response_body(response)

if response.respond_to?(:body)
# Rack responses
begin
response.body.map{ |body| JSON.parse(body.to_s) }
rescue # No reason to have "=> e" here when we don't use it..
response.body.map { |body| JSON.parse(body.to_s) }
rescue StandardError # No reason to have "=> e" here when we don't use it..
response.body
end
else
Expand Down
Loading