-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rubolint all the things #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
require: | ||
- rubocop-rake | ||
- rubocop-rspec | ||
|
||
AllCops: | ||
NewCops: enable | ||
|
||
Exclude: | ||
- 'lib/hawksi.rb' | ||
|
||
Style/HashSyntax: | ||
Enabled: false | ||
|
||
Layout/HeredocIndentation: | ||
Exclude: | ||
- 'lib/hawksi.rb' | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- 'spec/**/*' | ||
- '*.gemspec' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require_relative '../lib/hawksi' | ||
CLI.start(ARGV) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
# hawksi.gemspec | ||
require_relative 'lib/version' | ||
|
||
|
@@ -8,7 +10,8 @@ Gem::Specification.new do |spec| | |
spec.email = ['[email protected]'] | ||
|
||
spec.summary = 'Hawksi: Rack middleware to the Mocksi API.' | ||
spec.description = 'Hawksi sits between your application and the Mocksi API, allowing our agents to learn from your app to simulate whatever you can imagine.' | ||
spec.description = 'Hawksi sits between your application and the Mocksi API,\n' | ||
spec.description += 'allowing our agents to learn from your app to simulate whatever you can imagine.' | ||
spec.homepage = 'https://github.com/Mocksi/hawksi' | ||
spec.license = 'MIT' | ||
spec.required_ruby_version = Gem::Requirement.new('>= 3.2.0') | ||
|
@@ -20,22 +23,19 @@ Gem::Specification.new do |spec| | |
spec.files = Dir.chdir(File.expand_path(__dir__)) do | ||
`git ls-files -z`.split("\x0").reject do |f| | ||
%w[test spec features .gitignore hawksi.gemspec].include?(f) || | ||
f.match?(/(^\.|\/\.\.|\.\.\/|\.git|\.hg|CVS|\.svn|\.lock|~$)/) || | ||
f.end_with?('.gem') # Exclude gem files | ||
f.match?(%r{(^\.|/\.\.|\.\./|\.git|\.hg|CVS|\.svn|\.lock|~$)}) || | ||
f.end_with?('.gem') # Exclude gem files | ||
end | ||
end | ||
spec.bindir = 'bin' | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.require_paths = ['lib'] | ||
|
||
spec.add_dependency 'rack', '~> 2.2' | ||
spec.add_dependency 'httpx', '~> 1.3' | ||
spec.add_dependency 'json', '~> 2.5' | ||
spec.add_dependency 'puma', '~> 5.0' | ||
spec.add_dependency 'rack', '~> 2.2' | ||
spec.add_dependency 'thor', '~> 1.1' | ||
spec.add_dependency 'json', '~> 2.5' | ||
spec.add_dependency 'httpx', '~> 1.3' | ||
|
||
|
||
spec.add_development_dependency 'bundler', '~> 2.2' | ||
spec.add_development_dependency 'rake', '~> 13.0' | ||
spec.add_development_dependency 'rspec', '~> 3.10' | ||
spec.metadata['rubygems_mfa_required'] = 'true' | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'fileutils' | ||
require 'securerandom' | ||
|
||
# Handles file operations. | ||
class FileHandler | ||
def initialize(base_dir, logger) | ||
@base_dir = base_dir | ||
|
@@ -25,7 +28,7 @@ def generate_client_uuid | |
client_uuid | ||
end | ||
|
||
def create_tar_gz_files(files) | ||
def create_tar_gz_files(files) # rubocop:disable Metrics/MethodLength | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider refactoring instead of disabling RuboCop. While it's sometimes necessary to disable RuboCop cops, it's generally better to refactor the code to comply with the rules. The Consider breaking down the def create_tar_gz_files(files)
files.map { |file| create_tar_gz_file(file) }.compact
end
private
def create_tar_gz_file(file)
tar_gz_file = "#{file}.tar.gz"
return tar_gz_file if File.exist?(tar_gz_file)
create_tarball(file)
compress_tarball(file)
tar_gz_file
end
def create_tarball(file)
tar_file = "#{file}.tar"
system("tar -C #{File.dirname(file)} -cf #{tar_file} #{File.basename(file)}")
end
def compress_tarball(file)
tar_file = "#{file}.tar"
system("gzip #{tar_file}")
end This refactoring breaks down the logic into smaller, more focused methods, which should resolve the |
||
tar_gz_files = [] | ||
files.each do |file| | ||
tar_file = "#{file}.tar" | ||
|
@@ -39,7 +42,6 @@ def create_tar_gz_files(files) | |
system("gzip #{tar_file}") | ||
end | ||
|
||
|
||
tar_gz_files << tar_gz_file | ||
end | ||
tar_gz_files | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip
Codebase Verification
Review Required: RuboCop version not pinned in Gemfile.
Enabling
NewCops
is beneficial for staying updated with the latest style recommendations. However, since RuboCop is not version-pinned in the Gemfile, automatic updates may introduce unexpected changes in your CI pipelines.gem 'rubocop'
Recommendation: Pin the RuboCop version in your Gemfile to ensure consistent behavior across environments. For example:
Analysis chain
LGTM: NewCops enabled, consider version pinning.
Enabling
NewCops
is a good practice as it keeps the project up-to-date with the latest style recommendations. However, it's worth noting that this may introduce unexpected changes in CI pipelines when RuboCop is updated.To ensure consistent behavior across different environments, consider pinning the RuboCop version in your Gemfile. You can verify the current RuboCop version with:
If the version isn't pinned, you might want to update your Gemfile to include a specific version of RuboCop.
Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 260
Script:
Length of output: 67